o
    ˜¨Êhƒ1  ã                   @   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dlmZmZ G d	d
„ d
eƒ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)ÚIntEnum)ÚGDALBase)ÚSRSException)ÚGDAL_VERSION)Úsrs)Úforce_bytesÚ	force_strc                   @   s   e Zd ZdZdZdS )Ú	AxisOrderr   é   N)Ú__name__Ú
__module__Ú__qualname__ÚTRADITIONALÚ	AUTHORITY© r   r   úM/var/www/html/env/lib/python3.10/site-packages/django/contrib/gis/gdal/srs.pyr   '   s    r   c                   @   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d0d1„ ƒZed2d3„ ƒZed4d5„ ƒZed6d7„ ƒZ d8d9„ Z!d:d;„ Z"d<d=„ Z#d>d?„ Z$d@dA„ Z%edBdC„ ƒZ&edMdDdE„ƒZ'edFdG„ ƒZ(edHdI„ ƒZ)edNdJdK„ƒZ*dS )OÚ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."
    Ú ÚuserNc                 C   s¨  t |tdƒtfƒstdƒ‚|ptj| _|dkrKt tdƒ¡| _	|  
|¡ | jtjkr8tdkr8t | j	| j¡ dS | jtjkrItdk rItd| j ƒ‚dS t |tƒrdz
t|ƒ}d| }W n" tyc   Y nw t |tƒrld}nt || jƒrw|}d	}ntd
| ƒ‚|d	kr„|}n	tdƒ}t |¡}|s•td| ƒ‚|| _	| jtjkr«tdkr«t | j	| j¡ n| jtjkr¼tdk r¼td| j ƒ‚|dkrÇ|  |¡ dS |dkrÒ|  |¡ dS 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 string, and/or a projection "well known" shorthand
        string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
        Nz:SpatialReference.axis_order must be an AxisOrder instance.Úwktó    )é   r   z"%s is not supported in GDAL < 3.0.zEPSG:%dÚepsgÚogrzInvalid SRS type "%s"z+Could not create spatial reference from: %sr   )Ú
isinstanceÚtyper   Ú
ValueErrorr   Ú
axis_orderÚcapiÚnew_srsr   ÚptrÚ
import_wktr   Úset_axis_strategyÚstrÚintÚptr_typeÚ	TypeErrorr   Úimport_user_inputÚimport_epsg)ÚselfÚ	srs_inputÚsrs_typer    Úsridr	   Úbufr   r   r   Ú__init__5   sZ   ÿ
þ
ÿ

ÿÿzSpatialReference.__init__c                 C   s   t |tƒr
| j|Ž S |  |¡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
        >>> # For the units authority, have to use the pipe symbole.
        >>> print(srs['UNIT|AUTHORITY'])
        EPSG
        >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the units
        9122
        )r   ÚtupleÚ
attr_value©r,   Útargetr   r   r   Ú__getitem__t   s   


zSpatialReference.__getitem__c                 C   ó   | j S )zUse 'pretty' WKT.)Ú
pretty_wkt©r,   r   r   r   Ú__str__‘   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!   Úget_attr_valuer#   r
   )r,   r5   Úindexr   r   r   r3   –   s   zSpatialReference.attr_valuec                 C   ó   t  | jt|ƒ¡S )z;Return the authority name for the given string target node.)r!   Úget_auth_namer#   r
   r4   r   r   r   Ú	auth_nameŸ   ó   zSpatialReference.auth_namec                 C   r=   )z;Return the authority code for the given string target node.)r!   Úget_auth_coder#   r
   r4   r   r   r   Ú	auth_code£   r@   zSpatialReference.auth_codec                 C   s   t t | j¡| jd�S )z/Return a clone of this SpatialReference object.)r    )r   r!   Ú	clone_srsr#   r    r9   r   r   r   Úclone§   ó   zSpatialReference.clonec                 C   ó   t  | j¡ dS )z7Morph this SpatialReference from ESRI's format to EPSG.N)r!   Úmorph_from_esrir#   r9   r   r   r   Ú	from_esri«   ó   zSpatialReference.from_esric                 C   rF   )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#   r9   r   r   r   rJ   ¯   s   zSpatialReference.identify_epsgc                 C   rF   )z-Morph this SpatialReference to ESRI's format.N)r!   Úmorph_to_esrir#   r9   r   r   r   Úto_esri¶   rI   zSpatialReference.to_esric                 C   rF   )z5Check to see if the given spatial reference is valid.N)r!   Úsrs_validater#   r9   r   r   r   Úvalidateº   rI   zSpatialReference.validatec                 C   s4   | j r|  d¡S | jr|  d¡S | jr|  d¡S dS )z*Return the name of this Spatial Reference.ÚPROJCSÚGEOGCSÚLOCAL_CSN)Ú	projectedr3   Ú
geographicÚlocalr9   r   r   r   Úname¿   s   


zSpatialReference.namec              	   C   s,   z	t |  dd¡ƒW S  ttfy   Y dS w )z=Return the SRID of top-level authority, or None if undefined.r   r   N)r'   r3   r)   r   r9   r   r   r   r/   Ë   s
   ÿzSpatialReference.sridc                 C   ó   t  | jttƒ ƒ¡\}}|S )z$Return the name of the linear units.©r!   Úlinear_unitsr#   r   r   ©r,   ÚunitsrU   r   r   r   Úlinear_nameÔ   ó   zSpatialReference.linear_namec                 C   ó   t  | jttƒ ƒ¡\}}|S )z%Return the value of the linear units.rW   rY   r   r   r   rX   Ú   r\   zSpatialReference.linear_unitsc                 C   rV   )z%Return the name of the angular units.©r!   Úangular_unitsr#   r   r   rY   r   r   r   Úangular_nameà   r\   zSpatialReference.angular_namec                 C   r]   )z&Return the value of the angular units.r^   rY   r   r   r   r_   æ   r\   zSpatialReference.angular_unitsc                 C   sd   d\}}| j s
| jrt | jttƒ ƒ¡\}}n| jr&t | jttƒ ƒ¡\}}|du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)
rR   rT   r!   rX   r#   r   r   rS   r_   r   rY   r   r   r   rZ   ì   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_flatteningr9   r   r   r   Ú	ellipsoidü   ó   zSpatialReference.ellipsoidc                 C   ó   t  | jttƒ ƒ¡S )z6Return the Semi Major Axis for this Spatial Reference.)r!   ra   r#   r   r   r9   r   r   r   ra     ó   zSpatialReference.semi_majorc                 C   rf   )z6Return the Semi Minor Axis for this Spatial Reference.)r!   rb   r#   r   r   r9   r   r   r   rb   	  rg   zSpatialReference.semi_minorc                 C   rf   )z9Return the Inverse Flattening for this Spatial Reference.)r!   Úinvflatteningr#   r   r   r9   r   r   r   rc     rg   z#SpatialReference.inverse_flatteningc                 C   ó   t t | j¡ƒS )zd
        Return True if this SpatialReference is geographic
         (root node is GEOGCS).
        )Úboolr!   Úisgeographicr#   r9   r   r   r   rS     re   zSpatialReference.geographicc                 C   ri   )zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)rj   r!   Úislocalr#   r9   r   r   r   rT     s   zSpatialReference.localc                 C   ri   )zw
        Return True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )rj   r!   Úisprojectedr#   r9   r   r   r   rR   !  re   zSpatialReference.projectedc                 C   ó   t  | j|¡ dS )z=Import the Spatial Reference from the EPSG code (an integer).N)r!   Ú	from_epsgr#   )r,   r   r   r   r   r+   *  r@   zSpatialReference.import_epsgc                 C   rn   )z0Import the Spatial Reference from a PROJ string.N)r!   Ú	from_projr#   )r,   Úprojr   r   r   Úimport_proj.  r@   zSpatialReference.import_projc                 C   s   t  | jt|ƒ¡ dS )z>Import the Spatial Reference from the given user input string.N)r!   Úfrom_user_inputr#   r
   )r,   Ú
user_inputr   r   r   r*   2  rE   z"SpatialReference.import_user_inputc                 C   s   t  | jttt|ƒƒƒ¡ dS )z2Import the Spatial Reference from OGC WKT (string)N)r!   Úfrom_wktr#   r   r   r
   )r,   r   r   r   r   r$   6  s   zSpatialReference.import_wktc                 C   rn   )z0Import the Spatial Reference from an XML string.N)r!   Úfrom_xmlr#   )r,   Úxmlr   r   r   Ú
import_xml:  r@   zSpatialReference.import_xmlc                 C   rf   )z8Return the WKT representation of this Spatial Reference.)r!   Úto_wktr#   r   r   r9   r   r   r   r   ?  rg   zSpatialReference.wktc                 C   s   t  | jttƒ ƒ|¡S )z.Return the 'pretty' representation of the WKT.)r!   Úto_pretty_wktr#   r   r   )r,   Úsimplifyr   r   r   r8   D  s   zSpatialReference.pretty_wktc                 C   rf   )z:Return the PROJ representation for this Spatial Reference.)r!   Úto_projr#   r   r   r9   r   r   r   rq   I  rg   zSpatialReference.projc                 C   r7   )zAlias for proj().)rq   r9   r   r   r   Úproj4N  s   zSpatialReference.proj4c                 C   s   t  | jttƒ ƒt|ƒ¡S )z8Return the XML representation of this Spatial Reference.)r!   Úto_xmlr#   r   r   r
   )r,   Údialectr   r   r   rw   S  s   zSpatialReference.xml)r   r   N)r   )r   )+r   r   r   Ú__doc__r!   Úrelease_srsÚ
destructorr1   r6   r:   r3   r?   rB   rD   rH   rJ   rL   rN   ÚpropertyrU   r/   r[   rX   r`   r_   rZ   rd   ra   rb   rc   rS   rT   rR   r+   rr   r*   r$   rx   r   r8   rq   r}   rw   r   r   r   r   r   ,   sr    
?
	
















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!   Únew_ctÚ_ptrr#   rU   Ú
_srs1_nameÚ
_srs2_name)r,   Úsourcer5   r   r   r   r1   ]  s   ÿzCoordTransform.__init__c                 C   s   d| j | jf S )NzTransform from "%s" to "%s")r‡   rˆ   r9   r   r   r   r:   g  s   zCoordTransform.__str__N)	r   r   r   r€   r!   Ú
destroy_ctr‚   r1   r:   r   r   r   r   r„   Y  s
    
r„   N)r€   Úctypesr   r   r   Úenumr   Údjango.contrib.gis.gdal.baser   Údjango.contrib.gis.gdal.errorr   Údjango.contrib.gis.gdal.libgdalr   Ú"django.contrib.gis.gdal.prototypesr	   r!   Údjango.utils.encodingr
   r   r   r   r„   r   r   r   r   Ú<module>   s      /