U
    mÇf©  ã                   @   s   d dl mZ G dd„ dƒZdS )é    )Úgdalc                   @   sÎ   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZed$dd „ƒZd!d"„ Zd#S )%ÚSpatialRefSysMixinz~
    The SpatialRefSysMixin is a class used by the database-dependent
    SpatialRefSys objects to reduce redundant code.
    c              
   C   s¦   t | dƒr| j ¡ S zt | j¡| _| jW S  tk
rP } z|}W 5 d}~X Y nX zt | j¡| _| jW S  tk
rŽ } z|}W 5 d}~X Y nX td| j|f ƒ‚dS )z8
        Return a GDAL SpatialReference object.
        Ú_srsNz9Could not get OSR SpatialReference from WKT: %s
Error:
%s)	Úhasattrr   Úcloner   ÚSpatialReferenceÚwktÚsrsÚ	ExceptionZ	proj4text)ÚselfÚeÚmsg© r   úN/tmp/pip-unpacked-wheel-siwebuq3/django/contrib/gis/db/backends/base/models.pyr	   
   s"    

ÿÿzSpatialRefSysMixin.srsc                 C   s   | j jS )z
        Return a tuple of the ellipsoid parameters:
        (semimajor axis, semiminor axis, and inverse flattening).
        )r	   Ú	ellipsoid©r   r   r   r   r   (   s    zSpatialRefSysMixin.ellipsoidc                 C   s   | j jS )zReturn the projection name.)r	   Únamer   r   r   r   r   0   s    zSpatialRefSysMixin.namec                 C   s
   | j d S )z4Return the spheroid name for this spatial reference.Úspheroid©r	   r   r   r   r   r   5   s    zSpatialRefSysMixin.spheroidc                 C   s
   | j d S )z,Return the datum for this spatial reference.Údatumr   r   r   r   r   r   :   s    zSpatialRefSysMixin.datumc                 C   s   | j jS )z$Is this Spatial Reference projected?)r	   Ú	projectedr   r   r   r   r   ?   s    zSpatialRefSysMixin.projectedc                 C   s   | j jS )z Is this Spatial Reference local?)r	   Úlocalr   r   r   r   r   D   s    zSpatialRefSysMixin.localc                 C   s   | j jS )z%Is this Spatial Reference geographic?)r	   Ú
geographicr   r   r   r   r   I   s    zSpatialRefSysMixin.geographicc                 C   s   | j jS )zReturn the linear units name.)r	   Úlinear_namer   r   r   r   r   N   s    zSpatialRefSysMixin.linear_namec                 C   s   | j jS )zReturn the linear units.)r	   Úlinear_unitsr   r   r   r   r   S   s    zSpatialRefSysMixin.linear_unitsc                 C   s   | j jS )z%Return the name of the angular units.)r	   Úangular_namer   r   r   r   r   X   s    zSpatialRefSysMixin.angular_namec                 C   s   | j jS )zReturn the angular units.)r	   Úangular_unitsr   r   r   r   r   ]   s    z SpatialRefSysMixin.angular_unitsc                 C   s2   | j s| jr| j| jfS | jr*| j| jfS dS dS )z)Return a tuple of the units and the name.)NNN)r   r   r   r   r   r   r   r   r   r   r   Úunitsb   s
    zSpatialRefSysMixin.unitsc                 C   s   t  |¡jS )z
        Return a tuple of (unit_value, unit_name) for the given WKT without
        using any of the database fields.
        )r   r   r   )Úclsr   r   r   r   Ú	get_unitsl   s    zSpatialRefSysMixin.get_unitsTc                 C   s^   t  |¡}|j}|d }|s$||fS t|ƒdkrD|d |d  }}n|\}}d|||f S dS )zŒ
        Class method used by GeometryField on initialization to
        retrieve the `SPHEROID[..]` parameters from the given WKT.
        r   é   r   é   zSPHEROID["%s",%s,%s]N)r   r   r   Úlen)r   r   Ústringr	   Zsphere_paramsZsphere_nameZradiusZ
flatteningr   r   r   Úget_spheroidt   s    
zSpatialRefSysMixin.get_spheroidc                 C   s
   t | jƒS )zG
        Return the string representation, a 'pretty' OGC WKT.
        )Ústrr	   r   r   r   r   Ú__str__ˆ   s    zSpatialRefSysMixin.__str__N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr	   r   r   r   r   r   r   r   r   r   r   r   r   Úclassmethodr   r$   r&   r   r   r   r   r      s@   












	
r   N)Zdjango.contrib.gisr   r   r   r   r   r   Ú<module>   s   