ó
J~‰Pc           @   s¢   d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d l	 m
 Z d d l m Z d d l m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   sk  
  The Spatial Reference class, represensents OGR Spatial Reference objects.

  Example:
  >>> from django.contrib.gis.gdal import SpatialReference
  >>> srs = SpatialReference('WGS84')
  >>> print(srs)
  GEOGCS["WGS 84",
      DATUM["WGS_1984",
          SPHEROID["WGS 84",6378137,298.257223563,
              AUTHORITY["EPSG","7030"]],
          TOWGS84[0,0,0,0,0,0,0],
          AUTHORITY["EPSG","6326"]],
      PRIMEM["Greenwich",0,
          AUTHORITY["EPSG","8901"]],
      UNIT["degree",0.01745329251994328,
          AUTHORITY["EPSG","9122"]],
      AUTHORITY["EPSG","4326"]]
  >>> print(srs.proj)
  +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
  >>> print(srs.ellipsoid)
  (6378137.0, 6356752.3142451793, 298.25722356300003)
  >>> print(srs.projected, srs.geographic)
  False True
  >>> srs.import_epsg(32140)
  >>> print(srs.name)
  NAD83 / Texas South Central
iÿÿÿÿ(   t   byreft   c_char_pt   c_int(   t   GDALBase(   t   SRSException(   t   srs(   t   six(   t   force_bytest   SpatialReferencec           B   sÐ  e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  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 d „  Z d „  Z d „  Z  d  „  Z! d! „  Z" e d" „  ƒ Z# e d d# „ ƒ Z$ e d$ „  ƒ Z% e d% „  ƒ Z& e d d& „ ƒ Z' RS('   sê   
    A wrapper for the OGRSpatialReference object.  According to the GDAL Web site,
    the SpatialReference object "provide[s] services to represent coordinate
    systems (projections and datums) and to transform between them."
    t    c         C   sG  d } t  | t j ƒ rm t  | t j ƒ r< | j d ƒ } n  y t | ƒ } d | } Wq¹ t k
 ri q¹ XnL t  | t j ƒ rˆ d } n1 t  | |  j ƒ r© | } d } n t	 d | ƒ ‚ | d k rÎ | } n t
 d ƒ } t j | ƒ } | st d | ƒ ‚ n	 | |  _ | d k r'|  j | ƒ n | d k rC|  j | ƒ n  d	 S(
   s'  
        Creates a GDAL OSR Spatial Reference object from the given input.
        The input may be string of OGC Well Known Text (WKT), an integer
        EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand
        string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
        t   usert   asciis   EPSG:%dt   epsgt   ogrs   Invalid SRS type "%s"R	   s+   Could not create spatial reference from: %sN(   t
   isinstanceR   t   string_typest	   text_typet   encodet   intt
   ValueErrort   integer_typest   ptr_typet	   TypeErrorR   t   capit   new_srsR   t   ptrt   import_user_inputt   import_epsg(   t   selft	   srs_inputt   srs_typet   sridR   t   buf(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   __init__1   s4    				c         C   s    |  j  r t j |  j  ƒ n  d S(   s    Destroys this spatial reference.N(   t   _ptrR   t   release_srs(   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   __del__b   s    	 c         C   s-   t  | t ƒ r |  j | Œ  S|  j | ƒ Sd S(   s‰  
        Returns the value of the given string attribute node, None if the node
        doesn't exist.  Can also take a tuple as a parameter, (target, child),
        where child is the index of the attribute in the WKT.  For example:

        >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
        >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
        >>> print(srs['GEOGCS'])
        WGS 84
        >>> print(srs['DATUM'])
        WGS_1984
        >>> print(srs['AUTHORITY'])
        EPSG
        >>> print(srs['AUTHORITY', 1]) # The authority value
        4326
        >>> print(srs['TOWGS84', 4]) # the fourth value in this wkt
        0
        >>> print(srs['UNIT|AUTHORITY']) # For the units authority, have to use the pipe symbole.
        EPSG
        >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the untis
        9122
        N(   R   t   tuplet
   attr_value(   R   t   target(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   __getitem__f   s    c         C   s   |  j  S(   s,   The string representation uses 'pretty' WKT.(   t
   pretty_wkt(   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   __str__‚   s    i    c         C   sH   t  | t j ƒ s# t  | t ƒ r, t ‚ n  t j |  j t | ƒ | ƒ S(   sš   
        The attribute value for the given target node (e.g. 'PROJCS'). The index
        keyword specifies an index of the child node to return.
        (	   R   R   R   R   R   R   t   get_attr_valueR   R   (   R   R'   t   index(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR&   ‡   s    #	c         C   s   t  j |  j t | ƒ ƒ S(   s<   Returns the authority name for the given string target node.(   R   t   get_auth_nameR   R   (   R   R'   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt	   auth_name   s    c         C   s   t  j |  j t | ƒ ƒ S(   s<   Returns the authority code for the given string target node.(   R   t   get_auth_codeR   R   (   R   R'   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt	   auth_code”   s    c         C   s   t  t j |  j ƒ ƒ S(   s0   Returns a clone of this SpatialReference object.(   R   R   t	   clone_srsR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   clone˜   s    c         C   s   t  j |  j ƒ d S(   s8   Morphs this SpatialReference from ESRI's format to EPSG.N(   R   t   morph_from_esriR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt	   from_esriœ   s    c         C   s   t  j |  j ƒ d S(   sš   
        This method inspects the WKT of this SpatialReference, and will
        add EPSG authority nodes where an EPSG identifier is applicable.
        N(   R   t   identify_epsgR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR5       s    c         C   s   t  j |  j ƒ d S(   s.   Morphs this SpatialReference to ESRI's format.N(   R   t   morph_to_esriR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   to_esri§   s    c         C   s   t  j |  j ƒ d S(   s6   Checks to see if the given spatial reference is valid.N(   R   t   srs_validateR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   validate«   s    c         C   sJ   |  j  r |  j d ƒ S|  j r, |  j d ƒ S|  j rB |  j d ƒ Sd Sd S(   s+   Returns the name of this Spatial Reference.t   PROJCSt   GEOGCSt   LOCAL_CSN(   t	   projectedR&   t
   geographict   localt   None(   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   name°   s    	 	 	 c         C   s9   y t  |  j d d ƒ ƒ SWn t t f k
 r4 d SXd S(   s>   Returns the SRID of top-level authority, or None if undefined.t	   AUTHORITYi   N(   R   R&   R   R   R@   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR   ¸   s    c         C   s(   t  j |  j t t ƒ  ƒ ƒ \ } } | S(   s%   Returns the name of the linear units.(   R   t   linear_unitsR   R    R   (   R   t   unitsRA   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   linear_nameÁ   s    $c         C   s(   t  j |  j t t ƒ  ƒ ƒ \ } } | S(   s&   Returns the value of the linear units.(   R   RC   R   R    R   (   R   RD   RA   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRC   Ç   s    $c         C   s(   t  j |  j t t ƒ  ƒ ƒ \ } } | S(   s&   Returns the name of the angular units.(   R   t   angular_unitsR   R    R   (   R   RD   RA   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   angular_nameÍ   s    $c         C   s(   t  j |  j t t ƒ  ƒ ƒ \ } } | S(   s'   Returns the value of the angular units.(   R   RF   R   R    R   (   R   RD   RA   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRF   Ó   s    $c         C   s˜   d \ } } |  j s |  j rE t j |  j t t ƒ  ƒ ƒ \ } } n0 |  j ru t j	 |  j t t ƒ  ƒ ƒ \ } } n  | d k	 rŽ | j
 ƒ  n  | | f S(   s«   
        Returns a 2-tuple of the units value and the units name,
        and will automatically determines whether to return the linear
        or angular units.
        N(   NN(   R@   R=   R?   R   RC   R   R    R   R>   RF   t   decode(   R   RD   RA   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRD   Ù   s    '	'c         C   s   |  j  |  j |  j f S(   s€   
        Returns a tuple of the ellipsoid parameters:
         (semimajor axis, semiminor axis, and inverse flattening)
        (   t
   semi_majort
   semi_minort   inverse_flattening(   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt	   ellipsoidê   s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s7   Returns the Semi Major Axis for this Spatial Reference.(   R   RI   R   R    R   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRI   ò   s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s7   Returns the Semi Minor Axis for this Spatial Reference.(   R   RJ   R   R    R   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRJ   ÷   s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s:   Returns the Inverse Flattening for this Spatial Reference.(   R   t   invflatteningR   R    R   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRK   ü   s    c         C   s   t  t j |  j ƒ ƒ S(   se   
        Returns True if this SpatialReference is geographic
         (root node is GEOGCS).
        (   t   boolR   t   isgeographicR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR>     s    c         C   s   t  t j |  j ƒ ƒ S(   sG   Returns True if this SpatialReference is local (root node is LOCAL_CS).(   RN   R   t   islocalR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR?   
  s    c         C   s   t  t j |  j ƒ ƒ S(   sx   
        Returns True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        (   RN   R   t   isprojectedR   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR=     s    c         C   s   t  j |  j | ƒ d S(   s>   Imports the Spatial Reference from the EPSG code (an integer).N(   R   t	   from_epsgR   (   R   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR     s    c         C   s   t  j |  j | ƒ d S(   s3   Imports the Spatial Reference from a PROJ.4 string.N(   R   t	   from_projR   (   R   t   proj(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   import_proj  s    c         C   s   t  j |  j t | ƒ ƒ d S(   s?   Imports the Spatial Reference from the given user input string.N(   R   t   from_user_inputR   R   (   R   t
   user_input(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR      s    c         C   s#   t  j |  j t t | ƒ ƒ ƒ d S(   s3   Imports the Spatial Reference from OGC WKT (string)N(   R   t   from_wktR   R    R   (   R   t   wkt(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt
   import_wkt$  s    c         C   s   t  j |  j | ƒ d S(   s1   Imports the Spatial Reference from an XML string.N(   R   t   from_xmlR   (   R   t   xml(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt
   import_xml(  s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s9   Returns the WKT representation of this Spatial Reference.(   R   t   to_wktR   R    R   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRY   -  s    c         C   s   t  j |  j t t ƒ  ƒ | ƒ S(   s/   Returns the 'pretty' representation of the WKT.(   R   t   to_pretty_wktR   R    R   (   R   t   simplify(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR)   2  s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s=   Returns the PROJ.4 representation for this Spatial Reference.(   R   t   to_projR   R    R   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRT   7  s    c         C   s   |  j  S(   s   Alias for proj().(   RT   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   proj4<  s    c         C   s   t  j |  j t t ƒ  ƒ | ƒ S(   s9   Returns the XML representation of this Spatial Reference.(   R   t   to_xmlR   R    R   (   R   t   dialect(    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR\   A  s    ((   t   __name__t
   __module__t   __doc__R!   R$   R(   R*   R&   R.   R0   R2   R4   R5   R7   R9   t   propertyRA   R   RE   RC   RG   RF   RD   RL   RI   RJ   RK   R>   R?   R=   R   RU   R   RZ   R]   RY   R)   RT   Rb   R\   (    (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR   )   sN   1																		t   CoordTransformc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s,   The coordinate system transformation object.c         C   sf   t  | t ƒ s  t  | t ƒ r/ t d ƒ ‚ n  t j | j | j ƒ |  _ | j |  _ | j |  _	 d S(   s<   Initializes on a source and target SpatialReference objects.s2   source and target must be of type SpatialReferenceN(
   R   R   R   R   t   new_ctR"   R   RA   t
   _srs1_namet
   _srs2_name(   R   t   sourceR'   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR!   I  s
     c         C   s    |  j  r t j |  j  ƒ n  d S(   s.   Deletes this Coordinate Transformation object.N(   R"   R   t
   destroy_ct(   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR$   Q  s    	 c         C   s   d |  j  |  j f S(   Ns   Transform from "%s" to "%s"(   Rk   Rl   (   R   (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyR*   U  s    (   Re   Rf   Rg   R!   R$   R*   (    (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyRi   F  s   		N(   Rg   t   ctypesR    R   R   t   django.contrib.gis.gdal.baseR   t   django.contrib.gis.gdal.errorR   t"   django.contrib.gis.gdal.prototypesR   R   t   django.utilsR   t   django.utils.encodingR   R   Ri   (    (    (    s4   ../Django//lib/python/django/contrib/gis/gdal/srs.pyt   <module>   s   ÿ 