
    `f 2                         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 dd	lmZmZ  G d
 de          Z G d de
          Z G 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)NoneType)GDALBase)SRSException)GDAL_VERSION)srs)force_bytes	force_strc                       e Zd ZdZdZdS )	AxisOrderr      N)__name__
__module____qualname__TRADITIONAL	AUTHORITY     M/var/www/html/env/lib/python3.11/site-packages/django/contrib/gis/gdal/srs.pyr   r   (   s        KIIIr   r   c                   *   e Zd ZdZej        Z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*dS ),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                    t          |t          t          f          st          d          |pt          j        | _        |dk    rt          j        t          d                    | _	        | 
                    |           | j        t          j        k    r+t          dk    r t          j        | j	        | j                   n7| j        t          j        k    r"t          dk     rt          d| j        z            dS t          |t                    r&	 t          |          }d|z  }nT# t          $ r Y nHw xY wt          |t                    rd}n,t          || j                  r|}d	}nt!          d
|z            |d	k    r|}n#t          d          }t          j        |          }|st#          d|z            || _	        | j        t          j        k    r+t          dk    r t          j        | j	        | j                   n7| j        t          j        k    r"t          dk     rt          d| j        z            |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').
        z:SpatialReference.axis_order must be an AxisOrder instance.wktr   )   r   z"%s is not supported in GDAL < 3.0.NzEPSG:%depsgogrzInvalid SRS type "%s"z+Could not create spatial reference from: %sr   )
isinstancer   r   
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   bufs          r   __init__zSpatialReference.__init__6   s    *x&;<< 	L   %=	(=u|HSMM22DHOOI&&&)"777LF<R<R&txAAAAI$999lV>S>S !E!WXXXF	3'' 	@ 9~~%,		   	3'' 	@HH	4=11 	@CHH3h>???uCC 3--C,s##C  	=	I   DH?i3338N8N"48T_====_	 555,:O:OADOSTTTv""9-----Y'''''  s   D$ $
D10D1c                 j    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r0   targets     r   __getitem__zSpatialReference.__getitem__u   s7    0 fe$$ 	+"4?F++??6***r   c                     | j         S )zUse 'pretty' WKT.)
pretty_wktr0   s    r   __str__zSpatialReference.__str__   s
    r   r   c                     t          |t                    rt          |t                    st          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%   get_attr_valuer'   r   )r0   r:   indexs      r   r8   zSpatialReference.attr_value   sK    
 &#&& 	j.D.D 	O"48[-@-@%HHHr   c                 X    t          j        | j        ||nt          |                    S )z;Return the authority name for the given string target node.)r%   get_auth_namer'   r   r9   s     r   	auth_namezSpatialReference.auth_name   .    !HffK4G4G
 
 	
r   c                 X    t          j        | j        ||nt          |                    S )z;Return the authority code for the given string target node.)r%   get_auth_coder'   r   r9   s     r   	auth_codezSpatialReference.auth_code   rF   r   c                 \    t          t          j        | j                  | j                  S )z/Return a clone of this SpatialReference object.)r$   )r   r%   	clone_srsr'   r$   r>   s    r   clonezSpatialReference.clone   s#    tx 8 8T_UUUUr   c                 8    t          j        | j                   dS )z7Morph this SpatialReference from ESRI's format to EPSG.N)r%   morph_from_esrir'   r>   s    r   	from_esrizSpatialReference.from_esri   s    TX&&&&&r   c                 8    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>   s    r   rQ   zSpatialReference.identify_epsg   s    
 	48$$$$$r   c                 8    t          j        | j                   dS )z-Morph this SpatialReference to ESRI's format.N)r%   morph_to_esrir'   r>   s    r   to_esrizSpatialReference.to_esri   s    48$$$$$r   c                 8    t          j        | j                   dS )z5Check to see if the given spatial reference is valid.N)r%   srs_validater'   r>   s    r   validatezSpatialReference.validate   s    $(#####r   c                     | 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)	projectedr8   
geographiclocalr>   s    r   namezSpatialReference.name   s]     > 	??8,,,_ 	??8,,,Z 	??:...4r   c                 z    	 t          |                     d                    S # t          t          f$ r Y dS w xY w)z=Return the SRID of top-level authority, or None if undefined.N)r:   )r+   rI   r-   r#   r>   s    r   r3   zSpatialReference.srid   sJ    	t~~T~22333:& 	 	 	44	s   "% ::c                 r    t          j        | j        t          t	                                          \  }}|S )z$Return the name of the linear units.r%   linear_unitsr'   r   r   r0   unitsr_   s      r   linear_namezSpatialReference.linear_name   s-     '%

2C2CDDtr   c                 r    t          j        | j        t          t	                                          \  }}|S )z%Return the value of the linear units.rb   rd   s      r   rc   zSpatialReference.linear_units   s-     '%

2C2CDDtr   c                 r    t          j        | j        t          t	                                          \  }}|S )z%Return the name of the angular units.r%   angular_unitsr'   r   r   rd   s      r   angular_namezSpatialReference.angular_name   s-     (53D3DEEtr   c                 r    t          j        | j        t          t	                                          \  }}|S )z&Return the value of the angular units.ri   rd   s      r   rj   zSpatialReference.angular_units   s-     (53D3DEEtr   c                 :   d\  }}| j         s| j        r7t          j        | j        t          t                                          \  }}n=| j        r6t          j        | j        t          t                                          \  }}|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.
        )NN)
r\   r^   r%   rc   r'   r   r   r]   rj   r   rd   s      r   re   zSpatialReference.units   s     !t> 	JTZ 	J+DHeHJJ6G6GHHKE44_ 	J,TXuXZZ7H7HIIKE4T??Dt}r   c                 *    | 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_flatteningr>   s    r   	ellipsoidzSpatialReference.ellipsoid  s     $2IJJr   c                 h    t          j        | j        t          t	                                          S )z6Return the Semi Major Axis for this Spatial Reference.)r%   ro   r'   r   r   r>   s    r   ro   zSpatialReference.semi_major	  "     txuww888r   c                 h    t          j        | j        t          t	                                          S )z6Return the Semi Minor Axis for this Spatial Reference.)r%   rp   r'   r   r   r>   s    r   rp   zSpatialReference.semi_minor  rt   r   c                 h    t          j        | j        t          t	                                          S )z9Return the Inverse Flattening for this Spatial Reference.)r%   invflatteningr'   r   r   r>   s    r   rq   z#SpatialReference.inverse_flattening  s#     !$(E%''NN;;;r   c                 N    t          t          j        | j                            S )zd
        Return True if this SpatialReference is geographic
         (root node is GEOGCS).
        )boolr%   isgeographicr'   r>   s    r   r]   zSpatialReference.geographic  s     D%dh//000r   c                 N    t          t          j        | j                            S )zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)ry   r%   islocalr'   r>   s    r   r^   zSpatialReference.local!  s     DL**+++r   c                 N    t          t          j        | j                            S )zw
        Return True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )ry   r%   isprojectedr'   r>   s    r   r\   zSpatialReference.projected&  s     D$TX..///r   c                 :    t          j        | j        |           dS )z=Import the Spatial Reference from the EPSG code (an integer).N)r%   	from_epsgr'   )r0   r    s     r   r/   zSpatialReference.import_epsg/      tx&&&&&r   c                 :    t          j        | j        |           dS )z0Import the Spatial Reference from a PROJ string.N)r%   	from_projr'   )r0   projs     r   import_projzSpatialReference.import_proj3  r   r   c                 T    t          j        | j        t          |                     dS )z>Import the Spatial Reference from the given user input string.N)r%   from_user_inputr'   r   )r0   
user_inputs     r   r.   z"SpatialReference.import_user_input7  s%    TX{:'>'>?????r   c           
          t          j        | j        t          t	          t          |                                         dS )z2Import the Spatial Reference from OGC WKT (string)N)r%   from_wktr'   r   r   r   )r0   r   s     r   r(   zSpatialReference.import_wkt;  s4    dhh{3/?/?&@&@ A ABBBBBr   c                 :    t          j        | j        |           dS )z0Import the Spatial Reference from an XML string.N)r%   from_xmlr'   )r0   xmls     r   
import_xmlzSpatialReference.import_xml?  s    dh$$$$$r   c                 h    t          j        | j        t          t	                                          S )z8Return the WKT representation of this Spatial Reference.)r%   to_wktr'   r   r   r>   s    r   r   zSpatialReference.wktD  s$     {48U8::%6%6777r   c                 j    t          j        | j        t          t	                                |          S )z.Return the 'pretty' representation of the WKT.)r%   to_pretty_wktr'   r   r   )r0   simplifys     r   r=   zSpatialReference.pretty_wktI  s'     !$(E(**,=,=xHHHr   c                 h    t          j        | j        t          t	                                          S )z:Return the PROJ representation for this Spatial Reference.)r%   to_projr'   r   r   r>   s    r   r   zSpatialReference.projN  s$     |DHeHJJ&7&7888r   c                     | j         S )zAlias for proj().)r   r>   s    r   proj4zSpatialReference.proj4S  s     yr   c                     t          j        | j        t          t	                                t          |                    S )z8Return the XML representation of this Spatial Reference.)r%   to_xmlr'   r   r   r   )r0   dialects     r   r   zSpatialReference.xmlX  s.     {48U8::%6%6G8L8LMMMr   )r   r   N)r   )r   )+r   r   r   __doc__r%   release_srs
destructorr5   r;   r?   r8   rE   rI   rL   rO   rQ   rT   rW   propertyr_   r3   rf   rc   rk   rj   re   rr   ro   rp   rq   r]   r^   r\   r/   r   r.   r(   r   r   r=   r   r   r   r   r   r   r   r   -   sH         !J=( =( =( =(~+ + +:  
I I I I
 
 

 
 
V V V' ' '% % %% % %$ $ $
 	 	 X	   X   X
   X
   X
   X
   X K K XK 9 9 X9 9 9 X9 < < X<
 1 1 X1 , , X, 0 0 X0' ' '' ' '@ @ @C C C% % %
 8 8 X8 I I I XI 9 9 X9   X N N N XN N Nr   r   c                   ,    e Zd ZdZej        Zd Zd ZdS )CoordTransformz,The coordinate system transformation object.c                     t          |t                    rt          |t                    st          d          t          j        |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'   r_   
_srs1_name
_srs2_name)r0   sourcer:   s      r   r5   zCoordTransform.__init__b  sl    &"233 	R:$<
 <
 	R PQQQ;v{FK88 + +r   c                 (    d| j         d| j        dS )NzTransform from "z" to "")r   r   r>   s    r   r?   zCoordTransform.__str__l  s     04QQr   N)	r   r   r   r   r%   
destroy_ctr   r5   r?   r   r   r   r   r   ^  sD        22J& & &R R R R Rr   r   N)r   ctypesr   r   r   enumr   typesr   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   <module>r      sV   8 * ) ) ) ) ) ) ) ) )             1 1 1 1 1 1 6 6 6 6 6 6 8 8 8 8 8 8 : : : : : : 8 8 8 8 8 8 8 8       
nN nN nN nN nNx nN nN nNb	R R R R RX R R R R Rr   