
^Q\-                 @   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 Gd d	   d	 e  Z Gd
 d   d e  Z d S)ah  
  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
    )byrefc_char_pc_int)GDALBase)SRSException)srs)six)force_bytes
force_textc               @   sD  e  Z d  Z d Z e j Z d d d d  Z d d   Z d d	   Z	 d
 d d  Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z 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/ d0    Z e d1 d2    Z e d3 d4    Z e d5 d6    Z  d7 d8   Z! d9 d:   Z" d; d<   Z# d= d>   Z$ d? d@   Z% e dA dB    Z& e d
 dC dD   Z' e dE dF    Z( e dG dH    Z) e d dI dJ   Z* dK S)LSpatialReferencez
    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."
     userc             C   sS  | d k r5 t  j t d   |  _ |  j |  d St | t j  ry y t |  } d | } Wq t	 k
 ru Yq 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 r3|  j |  n | d k rO|  j |  n  d S)
a'  
        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').
        wkt    NzEPSG:%depsgZogrzInvalid SRS type "%s"z+Could not create spatial reference from: %sr   )capiZnew_srsr   ptr
import_wkt
isinstancer   string_typesint
ValueErrorinteger_typesZptr_type	TypeErrorr   import_user_inputimport_epsg)selfZ	srs_inputZsrs_typesridr   buf r   A/var/www/dbchiro/venv/build/Django/django/contrib/gis/gdal/srs.py__init__.   s6    				zSpatialReference.__init__c             C   s-   t  | t  r |  j |   S|  j |  Sd S)a  
        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   tuple
attr_value)r   targetr   r   r    __getitem___   s    zSpatialReference.__getitem__c             C   s   |  j  S)z,The string representation uses 'pretty' WKT.)
pretty_wkt)r   r   r   r    __str__{   s    zSpatialReference.__str__r   c             C   sH   t  | t j  s# t  | t  r, t  n  t j |  j t |  |  S)z
        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   Zget_attr_valuer   r	   )r   r$   indexr   r   r    r#      s    #	zSpatialReference.attr_valuec             C   s   t  j |  j t |   S)z<Returns the authority name for the given string target node.)r   Zget_auth_namer   r	   )r   r$   r   r   r    	auth_name   s    zSpatialReference.auth_namec             C   s   t  j |  j t |   S)z<Returns the authority code for the given string target node.)r   Zget_auth_coder   r	   )r   r$   r   r   r    	auth_code   s    zSpatialReference.auth_codec             C   s   t  t j |  j   S)z0Returns a clone of this SpatialReference object.)r   r   Z	clone_srsr   )r   r   r   r    clone   s    zSpatialReference.clonec             C   s   t  j |  j  d S)z8Morphs this SpatialReference from ESRI's format to EPSG.N)r   Zmorph_from_esrir   )r   r   r   r    	from_esri   s    zSpatialReference.from_esric             C   s   t  j |  j  d S)z
        This method inspects the WKT of this SpatialReference, and will
        add EPSG authority nodes where an EPSG identifier is applicable.
        N)r   identify_epsgr   )r   r   r   r    r-      s    zSpatialReference.identify_epsgc             C   s   t  j |  j  d S)z.Morphs this SpatialReference to ESRI's format.N)r   Zmorph_to_esrir   )r   r   r   r    to_esri   s    zSpatialReference.to_esric             C   s   t  j |  j  d S)z6Checks to see if the given spatial reference is valid.N)r   Zsrs_validater   )r   r   r   r    validate   s    zSpatialReference.validatec             C   sJ   |  j  r |  j d  S|  j r, |  j d  S|  j rB |  j d  Sd Sd S)z+Returns the name of this Spatial Reference.ZPROJCSZGEOGCSZLOCAL_CSN)	projectedr#   
geographiclocal)r   r   r   r    name   s    			zSpatialReference.namec             C   s=   y t  |  j d d   SWn t t f k
 r8 d SYn Xd S)z>Returns the SRID of top-level authority, or None if undefined.Z	AUTHORITY   N)r   r#   r   r   )r   r   r   r    r      s    zSpatialReference.sridc             C   s(   t  j |  j t t     \ } } | S)z%Returns the name of the linear units.)r   linear_unitsr   r   r   )r   unitsr3   r   r   r    linear_name   s    $zSpatialReference.linear_namec             C   s(   t  j |  j t t     \ } } | S)z&Returns the value of the linear units.)r   r5   r   r   r   )r   r6   r3   r   r   r    r5      s    $zSpatialReference.linear_unitsc             C   s(   t  j |  j t t     \ } } | S)z&Returns the name of the angular units.)r   angular_unitsr   r   r   )r   r6   r3   r   r   r    angular_name   s    $zSpatialReference.angular_namec             C   s(   t  j |  j t t     \ } } | S)z'Returns the value of the angular units.)r   r8   r   r   r   )r   r6   r3   r   r   r    r8      s    $zSpatialReference.angular_unitsc             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)z
        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)
r0   r2   r   r5   r   r   r   r1   r8   r
   )r   r6   r3   r   r   r    r6      s    '	'zSpatialReference.unitsc             C   s   |  j  |  j |  j f S)z
        Returns a tuple of the ellipsoid parameters:
         (semimajor axis, semiminor axis, and inverse flattening)
        )
semi_major
semi_minorinverse_flattening)r   r   r   r    	ellipsoid   s    zSpatialReference.ellipsoidc             C   s   t  j |  j t t     S)z7Returns the Semi Major Axis for this Spatial Reference.)r   r:   r   r   r   )r   r   r   r    r:      s    zSpatialReference.semi_majorc             C   s   t  j |  j t t     S)z7Returns the Semi Minor Axis for this Spatial Reference.)r   r;   r   r   r   )r   r   r   r    r;      s    zSpatialReference.semi_minorc             C   s   t  j |  j t t     S)z:Returns the Inverse Flattening for this Spatial Reference.)r   Zinvflatteningr   r   r   )r   r   r   r    r<      s    z#SpatialReference.inverse_flatteningc             C   s   t  t j |  j   S)ze
        Returns True if this SpatialReference is geographic
         (root node is GEOGCS).
        )boolr   Zisgeographicr   )r   r   r   r    r1      s    zSpatialReference.geographicc             C   s   t  t j |  j   S)zGReturns True if this SpatialReference is local (root node is LOCAL_CS).)r>   r   Zislocalr   )r   r   r   r    r2     s    zSpatialReference.localc             C   s   t  t j |  j   S)zx
        Returns True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )r>   r   Zisprojectedr   )r   r   r   r    r0     s    zSpatialReference.projectedc             C   s   t  j |  j |  d S)z>Imports the Spatial Reference from the EPSG code (an integer).N)r   Z	from_epsgr   )r   r   r   r   r    r     s    zSpatialReference.import_epsgc             C   s   t  j |  j |  d S)z3Imports the Spatial Reference from a PROJ.4 string.N)r   Z	from_projr   )r   projr   r   r    import_proj  s    zSpatialReference.import_projc             C   s   t  j |  j t |   d S)z?Imports the Spatial Reference from the given user input string.N)r   Zfrom_user_inputr   r	   )r   Z
user_inputr   r   r    r     s    z"SpatialReference.import_user_inputc             C   s)   t  j |  j t t t |     d S)z3Imports the Spatial Reference from OGC WKT (string)N)r   Zfrom_wktr   r   r   r	   )r   r   r   r   r    r   !  s    zSpatialReference.import_wktc             C   s   t  j |  j |  d S)z1Imports the Spatial Reference from an XML string.N)r   Zfrom_xmlr   )r   xmlr   r   r    
import_xml%  s    zSpatialReference.import_xmlc             C   s   t  j |  j t t     S)z9Returns the WKT representation of this Spatial Reference.)r   Zto_wktr   r   r   )r   r   r   r    r   *  s    zSpatialReference.wktc             C   s   t  j |  j t t    |  S)z/Returns the 'pretty' representation of the WKT.)r   Zto_pretty_wktr   r   r   )r   Zsimplifyr   r   r    r&   /  s    zSpatialReference.pretty_wktc             C   s   t  j |  j t t     S)z=Returns the PROJ.4 representation for this Spatial Reference.)r   Zto_projr   r   r   )r   r   r   r    r?   4  s    zSpatialReference.projc             C   s   |  j  S)zAlias for proj().)r?   )r   r   r   r    proj49  s    zSpatialReference.proj4c             C   s%   t  j |  j t t    t |   S)z9Returns the XML representation of this Spatial Reference.)r   Zto_xmlr   r   r   r	   )r   dialectr   r   r    rA   >  s    zSpatialReference.xmlN)+__name__
__module____qualname____doc__r   Zrelease_srs
destructorr!   r%   r'   r#   r)   r*   r+   r,   r-   r.   r/   propertyr3   r   r7   r5   r9   r8   r6   r=   r:   r;   r<   r1   r2   r0   r   r@   r   r   rB   r   r&   r?   rC   rA   r   r   r   r    r   &   sN   	1			r   c               @   s7   e  Z d  Z d Z e j Z d d   Z d d   Z d S)CoordTransformz,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)z<Initializes on a source and target SpatialReference objects.z2source and target must be of type SpatialReferenceN)
r   r   r   r   Znew_ctZ_ptrr   r3   
_srs1_name
_srs2_name)r   sourcer$   r   r   r    r!   H  s
     zCoordTransform.__init__c             C   s   d |  j  |  j f S)NzTransform from "%s" to "%s")rL   rM   )r   r   r   r    r'   P  s    zCoordTransform.__str__N)	rE   rF   rG   rH   r   Z
destroy_ctrI   r!   r'   r   r   r   r    rK   D  s   	rK   N)rH   ctypesr   r   r   Zdjango.contrib.gis.gdal.baser   Zdjango.contrib.gis.gdal.errorr   Z"django.contrib.gis.gdal.prototypesr   r   Zdjango.utilsr   Zdjango.utils.encodingr	   r
   r   rK   r   r   r   r    <module>   s    