
vลฯ^z  ใ               @   s'   d  d l  m Z Gd d   d  Z d S)้    )ฺgdalc               @   s3  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 j   Sy  t j |  j  |  _ |  j SWn+ t k
 ri } z | } WYd d } ~ Xn Xy  t j |  j  |  _ |  j SWn+ t k
 rท } z | } WYd d } ~ Xn Xt 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   ๚L/tmp/pip-build-8lau8j11/django/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	   ฺname)r   r   r   r   r   ,   s    zSpatialRefSysMixin.namec             C   s   |  j  d S)z4Return the spheroid name for this spatial reference.ฺspheroid)r	   )r   r   r   r   r   1   s    zSpatialRefSysMixin.spheroidc             C   s   |  j  d S)z,Return the datum for this spatial reference.ฺdatum)r	   )r   r   r   r   r   6   s    zSpatialRefSysMixin.datumc             C   s
   |  j  j S)z$Is this Spatial Reference projected?)r	   ฺ	projected)r   r   r   r   r   ;   s    zSpatialRefSysMixin.projectedc             C   s
   |  j  j S)z Is this Spatial Reference local?)r	   ฺlocal)r   r   r   r   r   @   s    zSpatialRefSysMixin.localc             C   s
   |  j  j S)z%Is this Spatial Reference geographic?)r	   ฺ
geographic)r   r   r   r   r   E   s    zSpatialRefSysMixin.geographicc             C   s
   |  j  j S)zReturn the linear units name.)r	   ฺlinear_name)r   r   r   r   r   J   s    zSpatialRefSysMixin.linear_namec             C   s
   |  j  j S)zReturn the linear units.)r	   ฺlinear_units)r   r   r   r   r   O   s    zSpatialRefSysMixin.linear_unitsc             C   s
   |  j  j S)z%Return the name of the angular units.)r	   ฺangular_name)r   r   r   r   r   T   s    zSpatialRefSysMixin.angular_namec             C   s
   |  j  j S)zReturn the angular units.)r	   ฺangular_units)r   r   r   r   r   Y   s    z SpatialRefSysMixin.angular_unitsc             C   sC   |  j  s |  j r" |  j |  j f S|  j r; |  j |  j f Sd Sd S)z)Return a tuple of the units and the name.N)NN)r   r   r   r   r   r   r   )r   r   r   r   ฺunits^   s
    	zSpatialRefSysMixin.unitsc             C   s   t  j |  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_unitsh   s    zSpatialRefSysMixin.get_unitsTc             C   s}   t  j |  } | j } | d } | s2 | | f St |  d k r\ | d | d } } n | \ } } d | | | f Sd 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_spheroidp   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)ฺ__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   