ó
i4Vdc           @   s\   d  d l  Z  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ÿÿÿÿN(   t   gdal(   t   six(   t   python_2_unicode_compatiblet   SpatialRefSysMixinc           B   s  e  Z d  Z e j d ƒ Z e j 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.
    sO   .+SPHEROID\[\"(?P<name>.+)\",(?P<major>\d+(\.\d+)?),(?P<flattening>\d{3}\.\d+),s×   .+UNIT ?\["(?P<unit_name>[\w \'\(\)]+)", ?(?P<unit>[\d\.]+)(,AUTHORITY\["(?P<unit_auth_name>[\w \'\(\)]+)","(?P<unit_auth_val>\d+)"\])?\]([\w ]+)?(,AUTHORITY\["(?P<auth_name>[\w \'\(\)]+)","(?P<auth_val>\d+)"\])?\]$c         C   s½   t  j r­ t |  d ƒ r% |  j j ƒ  Sy  t  j |  j ƒ |  _ |  j SWn t k
 rZ } n Xy  t  j |  j	 ƒ |  _ |  j SWn t k
 r } n Xt d |  j | f ƒ ‚ n t d ƒ ‚ d S(   sO   
        Returns a GDAL SpatialReference object, if GDAL is installed.
        t   _srss9   Could not get OSR SpatialReference from WKT: %s
Error:
%ss   GDAL is not installed.N(
   R    t   HAS_GDALt   hasattrR   t   clonet   SpatialReferencet   wktt   srst	   Exceptiont	   proj4text(   t   selft   msg(    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR
      s    	c         C   s^   t  j r |  j j S|  j j |  j ƒ } | rV t | j d ƒ ƒ t | j d ƒ ƒ f Sd Sd S(   s€   
        Returns a tuple of the ellipsoid parameters:
        (semimajor axis, semiminor axis, and inverse flattening).
        t   majort
   flatteningN(
   R    R   R
   t	   ellipsoidt   spheroid_regext   matchR	   t   floatt   groupt   None(   R   t   m(    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   =   s    	
(c         C   s
   |  j  j S(   s   Returns the projection name.(   R
   t   name(   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   L   s    c         C   s   |  j  d S(   s5   Returns the spheroid name for this spatial reference.t   spheroid(   R
   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   Q   s    c         C   s   |  j  d S(   s-   Returns the datum for this spatial reference.t   datum(   R
   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   V   s    c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s$   Is this Spatial Reference projected?t   PROJCSN(   R    R   R
   t	   projectedR	   t
   startswith(   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   [   s    	
c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s    Is this Spatial Reference local?t   LOCAL_CSN(   R    R   R
   t   localR	   R   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR   c   s    	
c         C   s'   t  j r |  j j S|  j j d ƒ Sd S(   s%   Is this Spatial Reference geographic?t   GEOGCSN(   R    R   R
   t
   geographicR	   R   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR!   k   s    	
c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the linear units name.t	   unit_nameN(
   R    R   R
   t   linear_nameR!   R   t   units_regexR   R	   R   (   R   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR#   s   s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the linear units.t   unitN(
   R    R   R
   t   linear_unitsR!   R   R$   R   R	   R   (   R   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR&   ~   s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s&   Returns the name of the angular units.R"   N(
   R    R   R
   t   angular_nameR   R   R$   R   R	   R   (   R   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR'   ‰   s    	
	c         C   sF   t  j r |  j j S|  j r  d S|  j j |  j ƒ } | j	 d ƒ Sd S(   s   Returns the angular units.R%   N(
   R    R   R
   t   angular_unitsR   R   R$   R   R	   R   (   R   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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'   R   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyt   unitsŸ   s
    	c         C   sK   t  j r t  j | ƒ j S|  j j | ƒ } | j d ƒ | j d ƒ f Sd S(   s°   
        Class method used by GeometryField on initialization to
        retrieve the units on the given WKT, without having to use
        any of the database fields.
        R%   R"   N(   R    R   R   R)   R$   R   R   (   t   clsR	   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyt	   get_units©   s    	c   	      C   sá   t  j r. t  j | ƒ } | j } | d } nX |  j j | ƒ } | r‚ t | j d ƒ ƒ t | j d ƒ ƒ f } | j d ƒ } n d	 S| s– | | 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   R   R   R   i   i    i   s   SPHEROID["%s",%s,%s]N(
   R    R   R   R   R   R   R   R   R   t   len(	   R*   R	   t   stringR
   t   sphere_paramst   sphere_nameR   t   radiusR   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyt   get_spheroid¶   s    		*
c         C   s9   y t  j |  j ƒ SWn t k
 r4 t  j |  j ƒ SXd S(   sp   
        Returns the string representation.  If GDAL is installed,
        it will be 'pretty' OGC WKT.
        N(   R   t	   text_typeR
   R   R	   (   R   (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyt   __str__Ò   s    (   t   __name__t
   __module__t   __doc__t   ret   compileR   R$   t   propertyR
   R   R   R   R   R   R   R!   R#   R&   R'   R(   R)   t   classmethodR+   t   TrueR1   R3   (    (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyR      s*   	
(	   R7   t   django.contrib.gisR    t   django.utilsR   t   django.utils.encodingR   t   objectR   (    (    (    sx   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/gis/db/backends/base/models.pyt   <module>   s
   