ó
®â0_c           @   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 m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   sh  
  The Spatial Reference class, represents 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
   force_textt   SpatialReferencec           B   sÓ  e  Z d  Z e j Z d d 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    t   userc         C   sR  | d k r5 t  j t d ƒ ƒ |  _ |  j | ƒ d St | t j ƒ rx y t | ƒ } d | } WqÄ t	 k
 rt 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 r2|  j | ƒ n | d k rN|  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   wktR
   Ns   EPSG:%dt   epsgt   ogrs   Invalid SRS type "%s"s+   Could not create spatial reference from: %sR   (   t   capit   new_srsR   t   ptrt
   import_wktt
   isinstanceR   t   string_typest   intt
   ValueErrort   integer_typest   ptr_typet	   TypeErrorR   t   import_user_inputt   import_epsg(   t   selft	   srs_inputt   srs_typet   sridR   t   buf(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyt   __init__.   s6    				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 units
        9122
        N(   R   t   tuplet
   attr_value(   R   t   target(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyt   __getitem___   s    c         C   s   |  j  S(   s,   The string representation uses 'pretty' WKT.(   t
   pretty_wkt(   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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$   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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$   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR2   ™   s    c         C   s   t  j |  j ƒ d S(   s.   Morphs this SpatialReference to ESRI's format.N(   R   t   morph_to_esriR   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   unitsR>   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   R@   R   R    R   (   R   RA   R>   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR@   Ä   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   RA   R>   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   RC   R   R    R   (   R   RA   R>   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRC   Ð   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 t
 | ƒ } 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   R@   R   R    R   R;   RC   R   (   R   RA   R>   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRA   Ö   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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   RE   R   R    R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRE   ï   s    c         C   s   t  j |  j t t ƒ  ƒ ƒ S(   s7   Returns the Semi Minor Axis for this Spatial Reference.(   R   RF   R   R    R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRF   ô   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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRG   ù   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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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).(   RJ   R   t   islocalR   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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).
        (   RJ   R   t   isprojectedR   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR     s    c         C   s)   t  j |  j t t t | ƒ ƒ ƒ ƒ d S(   s3   Imports the Spatial Reference from OGC WKT (string)N(   R   t   from_wktR   R    R   R   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR   !  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(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR   *  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(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR&   /  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   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRP   4  s    c         C   s   |  j  S(   s   Alias for proj().(   RP   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyt   proj49  s    c         C   s%   t  j |  j t t ƒ  ƒ t | ƒ ƒ S(   s9   Returns the XML representation of this Spatial Reference.(   R   t   to_xmlR   R    R   R   (   R   t   dialect(    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRV   >  s    (*   t   __name__t
   __module__t   __doc__R   t   release_srst
   destructorR!   R%   R'   R#   R+   R-   R/   R1   R2   R4   R6   t   propertyR>   R   RB   R@   RD   RC   RA   RH   RE   RF   RG   R;   R<   R:   R   RQ   R   R   RW   R   R&   RP   R\   RV   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR	   &   sN   	1																	t   CoordTransformc           B   s)   e  Z d  Z e j 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_ctt   _ptrR   R>   t
   _srs1_namet
   _srs2_name(   R   t   sourceR$   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR!   H  s
     c         C   s   d |  j  |  j f S(   Ns   Transform from "%s" to "%s"(   Rh   Ri   (   R   (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyR'   P  s    (   R_   R`   Ra   R   t
   destroy_ctRc   R!   R'   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyRe   D  s   		N(   Ra   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   R	   Re   (    (    (    s=   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/gis/gdal/srs.pyt   <module>   s   ÿ 