B
    ¥0H[-  ã               @   sp   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mZ G dd„ deƒZG d	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)Úforce_bytesÚ
force_textc               @   s‚  e Zd ZdZejZdLdd„Zdd„ Zdd	„ Z	dMd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d1d2„ ƒZed3d4„ ƒZed5d6„ ƒZ d7d8„ Z!d9d:„ Z"d;d<„ Z#d=d>„ Z$d?d@„ Z%edAdB„ ƒZ&edNdCdD„ƒZ'edEdF„ ƒZ(edGdH„ ƒZ)edOdIdJ„ƒZ*dKS )PÚ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   sð   |dkr&t  tdƒ¡| _|  |¡ dS t|tƒr\yt|ƒ}d| }W qŽ tk
rX   Y qŽX n2t|tƒrld}n"t|| j	ƒr‚|}d}nt
d| ƒ‚|dkrœ|}ntdƒ}t  |¡}|sÀtd| ƒ‚n|| _|d	krÚ|  |¡ n|dkrì|  |¡ dS )
a&  
        Create 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Ú
isinstanceÚstrÚintÚ
ValueErrorZptr_typeÚ	TypeErrorr   Úimport_user_inputÚimport_epsg)ÚselfZ	srs_inputZsrs_typeÚsridr   Úbuf© r   ú_C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\gis\gdal\srs.pyÚ__init__-   s6    



zSpatialReference.__init__c             C   s"   t |tƒr| j|Ž S |  |¡S dS )a‡  
        Return 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Use 'pretty' WKT.)Ú
pretty_wkt)r   r   r   r   Ú__str__z   s    zSpatialReference.__str__r   c             C   s,   t |tƒrt |tƒst‚t | 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   Zget_attr_valuer   r   )r   r"   Úindexr   r   r   r!      s    zSpatialReference.attr_valuec             C   s   t  | jt|ƒ¡S )z;Return 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t|ƒ¡S )z;Return 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¡ƒS )z/Return a clone of this SpatialReference object.)r
   r   Z	clone_srsr   )r   r   r   r   Úclone�   s    zSpatialReference.clonec             C   s   t  | j¡ dS )z7Morph 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¡ 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¡ dS )z-Morph 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¡ dS )z5Check to see if the given spatial reference is valid.N)r   Zsrs_validater   )r   r   r   r   Úvalidate£   s    zSpatialReference.validatec             C   s8   | j r|  d¡S | jr |  d¡S | jr0|  d¡S dS dS )z*Return 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 |  dd¡ƒS  ttfk
r(   dS X dS )z=Return 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ttƒ ƒ¡\}}|S )z$Return the name of the linear units.)r   Úlinear_unitsr   r   r   )r   Úunitsr1   r   r   r   Úlinear_name½   s    zSpatialReference.linear_namec             C   s   t  | jttƒ ƒ¡\}}|S )z%Return the value of the linear units.)r   r3   r   r   r   )r   r4   r1   r   r   r   r3   Ã   s    zSpatialReference.linear_unitsc             C   s   t  | jttƒ ƒ¡\}}|S )z%Return the name of the angular units.)r   Úangular_unitsr   r   r   )r   r4   r1   r   r   r   Úangular_nameÉ   s    zSpatialReference.angular_namec             C   s   t  | jttƒ ƒ¡\}}|S )z&Return the value of the angular units.)r   r6   r   r   r   )r   r4   r1   r   r   r   r6   Ï   s    zSpatialReference.angular_unitsc             C   sd   d\}}| j s| jr.t | jttƒ ƒ¡\}}n| jrLt | jttƒ ƒ¡\}}|dk	r\t	|ƒ}||fS )z˜
        Return a 2-tuple of the units value and the units name. Automatically
        determine whether to return the linear or angular units.
        )NNN)
r.   r0   r   r3   r   r   r   r/   r6   r	   )r   r4   r1   r   r   r   r4   Õ   s    zSpatialReference.unitsc             C   s   | j | j| jfS )z
        Return 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ttƒ ƒ¡S )z6Return the Semi Major Axis for this Spatial Reference.)r   r8   r   r   r   )r   r   r   r   r8   í   s    zSpatialReference.semi_majorc             C   s   t  | jttƒ ƒ¡S )z6Return the Semi Minor Axis for this Spatial Reference.)r   r9   r   r   r   )r   r   r   r   r9   ò   s    zSpatialReference.semi_minorc             C   s   t  | jttƒ ƒ¡S )z9Return 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¡ƒS )zd
        Return True if this SpatialReference is geographic
         (root node is GEOGCS).
        )Úboolr   Zisgeographicr   )r   r   r   r   r/   ý   s    zSpatialReference.geographicc             C   s   t t | j¡ƒS )zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)r<   r   Zislocalr   )r   r   r   r   r0     s    zSpatialReference.localc             C   s   t t | j¡ƒS )zw
        Return True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )r<   r   Zisprojectedr   )r   r   r   r   r.   
  s    zSpatialReference.projectedc             C   s   t  | j|¡ dS )z=Import 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|¡ dS )z2Import 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t|ƒ¡ dS )z>Import 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ttt|ƒƒƒ¡ dS )z2Import 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|¡ dS )z0Import 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ttƒ ƒ¡S )z8Return 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ttƒ ƒ|¡S )z.Return 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ttƒ ƒ¡S )z<Return the PROJ.4 representation for this Spatial Reference.)r   Zto_projr   r   r   )r   r   r   r   r=   2  s    zSpatialReference.projc             C   s   | j S )zAlias for proj().)r=   )r   r   r   r   Úproj47  s    zSpatialReference.proj4c             C   s   t  | jttƒ ƒt|ƒ¡S )z8Return the XML representation of this Spatial Reference.)r   Zto_xmlr   r   r   r   )r   Údialectr   r   r   r?   <  s    zSpatialReference.xmlN)r   r   )r   )r   )r   )+Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Zrelease_srsÚ
destructorr   r#   r%   r!   r'   r(   r)   r*   r+   r,   r-   Úpropertyr1   r   r5   r3   r7   r6   r4   r;   r8   r9   r:   r/   r0   r.   r   r>   r   r   r@   r   r$   r=   rA   r?   r   r   r   r   r
   %   sN   
1
			r
   c               @   s&   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   sB   t |tƒrt |tƒstdƒ‚t |j|j¡| _|j| _|j| _	dS )z;Initialize on a source and target SpatialReference objects.z2source and target must be of type SpatialReferenceN)
r   r
   r   r   Znew_ctZ_ptrr   r1   Ú
_srs1_nameÚ
_srs2_name)r   Úsourcer"   r   r   r   r   F  s
    zCoordTransform.__init__c             C   s   d| j | jf S )NzTransform from "%s" to "%s")rJ   rK   )r   r   r   r   r%   N  s    zCoordTransform.__str__N)	rC   rD   rE   rF   r   Z
destroy_ctrG   r   r%   r   r   r   r   rI   B  s   rI   N)rF   Úctypesr   r   r   Zdjango.contrib.gis.gdal.baser   Zdjango.contrib.gis.gdal.errorr   Z"django.contrib.gis.gdal.prototypesr   r   Zdjango.utils.encodingr   r	   r
   rI   r   r   r   r   Ú<module>   s     