ó
®ā0_c           @   sP   d  d l  m Z d  d l m Z d  d l m Z e d e f d     Y Z d S(   i’’’’(   t   gdal(   t   six(   t   python_2_unicode_compatiblet   SpatialRefSysMixinc           B   sū   e  Z d  Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z e d	    Z e d
    Z e d    Z e d    Z e d    Z e d    Z e e d   Z d   Z RS(   s~   
    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
 rW } | } n Xy  t j |  j  |  _ |  j SWn t k
 r } | } n Xt d |  j | f   d S(   s9   
        Returns a GDAL SpatialReference object.
        t   _srss9   Could not get OSR SpatialReference from WKT: %s
Error:
%sN(	   t   hasattrR   t   cloneR    t   SpatialReferencet   wktt   srst	   Exceptiont	   proj4text(   t   selft   et   msg(    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR	      s    

c         C   s
   |  j  j S(   s   
        Returns a tuple of the ellipsoid parameters:
        (semimajor axis, semiminor axis, and inverse flattening).
        (   R	   t	   ellipsoid(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   '   s    c         C   s
   |  j  j S(   s   Returns the projection name.(   R	   t   name(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   /   s    c         C   s   |  j  d S(   s5   Returns the spheroid name for this spatial reference.t   spheroid(   R	   (   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   4   s    c         C   s   |  j  d S(   s-   Returns the datum for this spatial reference.t   datum(   R	   (   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   9   s    c         C   s
   |  j  j S(   s$   Is this Spatial Reference projected?(   R	   t	   projected(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   >   s    c         C   s
   |  j  j S(   s    Is this Spatial Reference local?(   R	   t   local(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   C   s    c         C   s
   |  j  j S(   s%   Is this Spatial Reference geographic?(   R	   t
   geographic(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   H   s    c         C   s
   |  j  j S(   s   Returns the linear units name.(   R	   t   linear_name(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   M   s    c         C   s
   |  j  j S(   s   Returns the linear units.(   R	   t   linear_units(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   R   s    c         C   s
   |  j  j S(   s&   Returns the name of the angular units.(   R	   t   angular_name(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   W   s    c         C   s
   |  j  j S(   s   Returns the angular units.(   R	   t   angular_units(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR   \   s    c         C   sC   |  j  s |  j r" |  j |  j f S|  j r; |  j |  j f Sd Sd S(   s*   Returns a tuple of the units and the name.N(   NN(   R   R   R   R   R   R   R   t   None(   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyt   unitsa   s
    	c         C   s   t  j |  j S(   s   
        Return a tuple of (unit_value, unit_name) for the given WKT without
        using any of the database fields.
        (   R    R   R   (   t   clsR   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyt	   get_unitsk   s    c         C   s}   t  j |  } | j } | d } | s2 | | f St |  d k r\ | d | d } } n | \ } } d | | | f Sd S(   s   
        Class method used by GeometryField on initialization to
        retrieve the `SPHEROID[..]` parameters from the given WKT.
        R   i   i    i   s   SPHEROID["%s",%s,%s]N(   R    R   R   t   len(   R   R   t   stringR	   t   sphere_paramst   sphere_namet   radiust
   flattening(    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyt   get_spheroids   s    	

c         C   s   t  j |  j  S(   sH   
        Returns the string representation, a 'pretty' OGC WKT.
        (   R   t	   text_typeR	   (   R   (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__t   propertyR	   R   R   R   R   R   R   R   R   R   R   R   R   t   classmethodR   t   TrueR$   R&   (    (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyR      s$   
N(   t   django.contrib.gisR    t   django.utilsR   t   django.utils.encodingR   t   objectR   (    (    (    sL   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/db/backends/base/models.pyt   <module>   s   