
    Dvg>0                         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
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)srs)force_bytes	force_strc                       e Zd ZdZdZdS )	AxisOrderr      N)__name__
__module____qualname__TRADITIONAL	AUTHORITY     X/var/www/pixelcanvas.ch/venv/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    rqt          j        t          d                    | _	        | 
                    |           | j        t          j        k    rt          j        | j	        | j                   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          j        | j	        | 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').
        z:SpatialReference.axis_order must be an AxisOrder instance.wktr   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_wkt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7&txAAAF	3'' 	@ 9~~%,		   	3'' 	@HH	4=11 	@CHH3h>???uCC 3--C,s##C  	=	I   DH?i333"48T_===v""9-----Y'''''  s   C! !
C.-C.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r.   targets     r   __getitem__zSpatialReference.__getitem__q   s7    0 fe$$ 	+"4?F++??6***r   c                     | j         S )zUse 'pretty' WKT.)
pretty_wktr.   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   )r.   r8   indexs      r   r6   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   r7   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   r7   s     r   	auth_codezSpatialReference.auth_code   rD   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   rO   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)	projectedr6   
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)r8   )r)   rG   r+   r!   r<   s    r   r1   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   r.   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.r`   rb   s      r   ra   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   rb   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.rg   rb   s      r   rh   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)
rZ   r\   r#   ra   r%   r   r   r[   rh   r   rb   s      r   rc   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#   rm   r%   r   r   r<   s    r   rm   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#   rn   r%   r   r   r<   s    r   rn   zSpatialReference.semi_minor
  rr   r   c                 h    t          j        | j        t          t	                                          S )z9Return the Inverse Flattening for this Spatial Reference.)r#   invflatteningr%   r   r   r<   s    r   ro   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).)rw   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).
        )rw   r#   isprojectedr%   r<   s    r   rZ   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%   )r.   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%   )r.   projs     r   import_projzSpatialReference.import_proj/  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   )r.   
user_inputs     r   r,   z"SpatialReference.import_user_input3  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   )r.   r   s     r   r&   zSpatialReference.import_wkt7  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%   )r.   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.wkt@  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   )r.   simplifys     r   r;   zSpatialReference.pretty_wktE  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.projJ  s$     |DHeHJJ&7&7888r   c                     | j         S )zAlias for proj().)r   r<   s    r   proj4zSpatialReference.proj4O  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   )r.   dialects     r   r   zSpatialReference.xmlT  s.     {48U8::%6%6G8L8LMMMr   )r   r   N)r   )r   )+r   r   r   __doc__r#   release_srs
destructorr3   r9   r=   r6   rC   rG   rJ   rM   rO   rR   rU   propertyr]   r1   rd   ra   ri   rh   rc   rp   rm   rn   ro   r[   r\   rZ   r-   r   r,   r&   r   r   r;   r   r   r   r   r   r   r   r   -   sH         !J9( 9( 9( 9(v+ + +:  
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)r.   sourcer8   s      r   r3   zCoordTransform.__init__^  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__h  s     04QQr   N)	r   r   r   r   r#   
destroy_ctr   r3   r=   r   r   r   r   r   Z  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.prototypesr
   r#   django.utils.encodingr   r   r   r   r   r   r   r   <module>r      sD   : * ) ) ) ) ) ) ) ) )             1 1 1 1 1 1 6 6 6 6 6 6 : : : : : : 8 8 8 8 8 8 8 8       
jN jN jN jN jNx jN jN jNZ	R R R R RX R R R R Rr   