a
    5Xh                      @   s   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z ddlmZ G dd	 d	ejZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )forms)GDALException)GEOSExceptionGEOSGeometry)ValidationError)gettext_lazy   )OpenLayersWidgetc                       sj   e Zd ZdZeZdZededededdZddd	 fd
d
Z	dd Z
 fddZdd Z  ZS )GeometryFieldz
    This is the basic form field for a Geometry.  Any textual input that is
    accepted by GEOSGeometry is accepted by this form.  By default,
    this includes WKT, HEXEWKB, WKB (in a buffer), and GeoJSON.
    GEOMETRYzNo geometry value provided.zInvalid geometry value.zInvalid geometry type.zXAn error occurred when transforming the geometry to the SRID of the geometry form field.)requiredinvalid_geominvalid_geom_typetransform_errorN)srid	geom_typec                   s8   || _ |d ur|| _t jf i | | j| jjd< d S )Nr   )r   r   super__init__widgetattrs)selfr   r   kwargs	__class__ d/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/django/contrib/gis/forms/fields.pyr      s
    zGeometryField.__init__c              
   C   s   || j v rdS t|tst| jdrNz| j|}W qx tyJ   d}Y qx0 n*zt|}W n ttt	fyv   d}Y n0 |du rt
| jd dd|jsz| jj|_W n  ty   | jr| j|_Y n0 |S )z)Transform the value to a Geometry object.Ndeserializer   code)Zempty_values
isinstancer   hasattrr   r   r   r   
ValueError	TypeErrorr   error_messagesr   Zmap_sridAttributeError)r   valuer   r   r   	to_python%   s.    



zGeometryField.to_pythonc                    s   t  |}|du r|S t|j | jkrH| jdkrHt| jd dd| jr| jdkr| j|jkrz|| j W n$ t	y   t| jd ddY n0 |S )z
        Validate that the input value can be converted to a Geometry object
        and return it. Raise a ValidationError if the value cannot be
        instantiated as a Geometry.
        Nr   r   r   r   )
r   cleanstrr   upperr   r#   r   	transformr   )r   r%   Zgeomr   r   r   r(   C   s$    

zGeometryField.cleanc                 C   sf   z|  |}|  |}W n ty,   Y dS 0 |rR|rR||j |j|dd S t|t|kS dS )z8Compare geographic value of data with its initial value.Tgư>)Z	toleranceN)r&   r   r+   r   Zequals_exactbool)r   initialdatar   r   r   has_changedb   s    
zGeometryField.has_changed)__name__
__module____qualname____doc__r	   r   r   _Zdefault_error_messagesr   r&   r(   r/   __classcell__r   r   r   r   r
   
   s   
r
   c                   @   s   e Zd ZdZdS )GeometryCollectionFieldZGEOMETRYCOLLECTIONNr0   r1   r2   r   r   r   r   r   r6   w   s   r6   c                   @   s   e Zd ZdZdS )
PointFieldZPOINTNr7   r   r   r   r   r8   {   s   r8   c                   @   s   e Zd ZdZdS )MultiPointFieldZ
MULTIPOINTNr7   r   r   r   r   r9      s   r9   c                   @   s   e Zd ZdZdS )LineStringFieldZ
LINESTRINGNr7   r   r   r   r   r:      s   r:   c                   @   s   e Zd ZdZdS )MultiLineStringFieldZMULTILINESTRINGNr7   r   r   r   r   r;      s   r;   c                   @   s   e Zd ZdZdS )PolygonFieldZPOLYGONNr7   r   r   r   r   r<      s   r<   c                   @   s   e Zd ZdZdS )MultiPolygonFieldZMULTIPOLYGONNr7   r   r   r   r   r=      s   r=   N)Zdjangor   Zdjango.contrib.gis.gdalr   Zdjango.contrib.gis.geosr   r   Zdjango.core.exceptionsr   Zdjango.utils.translationr   r4   Zwidgetsr	   ZFieldr
   r6   r8   r9   r:   r;   r<   r=   r   r   r   r   <module>   s   m