
    g>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y)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y)	AxisOrderr      N)__name__
__module____qualname__TRADITIONAL	AUTHORITY     s/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/gdal/srs.pyr   r   (   s    KIr   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*y))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."
    Nc                    t        |t        t        f      st        d      |xs t        j                  | _        |dk(  r|t        j                  t        d            | _	        | j                  |       | j
                  t        j                  k(  r*t        j                  | j                  | j
                         yt        |t              r	 t        |      }d|z  }n<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| j#                  |       y|dk(  r| j%                  |       yy# t        $ r Y w xY w)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: %suser)
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||HSM2DHOOI&)"7"77&&txxA	3' 9~%,	 	3'H	4==1CH3h>??uC 3-C,,s#C =	I  DH??i333""488T__=v""9-Y'  A  s   G 	GGc                 b    t        |t              r | j                  | S | j                  |      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   s.    0 fe$"4??F++??6**r   c                     | j                   S )zUse 'pretty' WKT.)
pretty_wktr-   s    r   __str__zSpatialReference.__str__   s    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-   r7   indexs      r   r5   zSpatialReference.attr_value   s:    
 &#&j.DO""488[-@%HHr   c                 d    t        j                  | j                  ||      S t        |            S )z;Return the authority name for the given string target node.)r"   get_auth_namer$   r   r6   s     r   	auth_namezSpatialReference.auth_name   4    !!HHf
 	
4?4G
 	
r   c                 d    t        j                  | j                  ||      S t        |            S )z;Return the authority code for the given string target node.)r"   get_auth_coder$   r   r6   s     r   	auth_codezSpatialReference.auth_code   rC   r   c                 j    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     txx 8T__UUr   c                 B    t        j                  | j                         y)z7Morph this SpatialReference from ESRI's format to EPSG.N)r"   morph_from_esrir$   r;   s    r   	from_esrizSpatialReference.from_esri   s    TXX&r   c                 B    t        j                  | j                         y)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   rN   zSpatialReference.identify_epsg   s    
 	488$r   c                 B    t        j                  | j                         y)z-Morph this SpatialReference to ESRI's format.N)r"   morph_to_esrir$   r;   s    r   to_esrizSpatialReference.to_esri   s    488$r   c                 B    t        j                  | j                         y)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| j                  d      S | j                  r| j                  d      S | j                  r| j                  d      S y)z*Return the name of this Spatial Reference.PROJCSGEOGCSLOCAL_CSN)	projectedr5   
geographiclocalr;   s    r   namezSpatialReference.name   sI     >>??8,,__??8,,ZZ??:..r   c                 d    	 t        | j                  d            S # t        t        f$ r Y yw xY w)z=Return the SRID of top-level authority, or None if undefined.N)r7   )r(   rF   r*   r    r;   s    r   r0   zSpatialReference.srid   s4    	t~~T~233:& 		s    //c                 n    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*     ''%
2CDtr   c                 n    t        j                  | j                  t        t	                           \  }}|S )z%Return the value of the linear units.r_   ra   s      r   r`   zSpatialReference.linear_units   s*     ''%
2CDtr   c                 n    t        j                  | j                  t        t	                           \  }}|S )z%Return the name of the angular units.r"   angular_unitsr$   r   r   ra   s      r   angular_namezSpatialReference.angular_name   s*     ((53DEtr   c                 n    t        j                  | j                  t        t	                           \  }}|S )z&Return the value of the angular units.rf   ra   s      r   rg   zSpatialReference.angular_units   s*     ((53DEtr   c                 H   d\  }}| j                   s| j                  r5t        j                  | j                  t        t                           \  }}n@| j                  r4t        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)
rY   r[   r"   r`   r$   r   r   rZ   rg   r   ra   s      r   rb   zSpatialReference.units   s|     !t>>TZZ++DHHeHJ6GHKE4__,,TXXuXZ7HIKE4T?Dt}r   c                 H    | 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     $2I2IJJr   c                 d    t        j                  | j                  t        t	                           S )z6Return the Semi Major Axis for this Spatial Reference.)r"   rl   r$   r   r   r;   s    r   rl   zSpatialReference.semi_major       txxuw88r   c                 d    t        j                  | j                  t        t	                           S )z6Return the Semi Minor Axis for this Spatial Reference.)r"   rm   r$   r   r   r;   s    r   rm   zSpatialReference.semi_minor
  rq   r   c                 d    t        j                  | j                  t        t	                           S )z9Return the Inverse Flattening for this Spatial Reference.)r"   invflatteningr$   r   r   r;   s    r   rn   z#SpatialReference.inverse_flattening  s!     !!$((E%'N;;r   c                 R    t        t        j                  | j                              S )zd
        Return True if this SpatialReference is geographic
         (root node is GEOGCS).
        )boolr"   isgeographicr$   r;   s    r   rZ   zSpatialReference.geographic  s     D%%dhh/00r   c                 R    t        t        j                  | j                              S )zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)rv   r"   islocalr$   r;   s    r   r[   zSpatialReference.local  s     DLL*++r   c                 R    t        t        j                  | j                              S )zw
        Return True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )rv   r"   isprojectedr$   r;   s    r   rY   zSpatialReference.projected"  s     D$$TXX.//r   c                 D    t        j                  | j                  |       y)z=Import the Spatial Reference from the EPSG code (an integer).N)r"   	from_epsgr$   )r-   r   s     r   r,   zSpatialReference.import_epsg+      txx&r   c                 D    t        j                  | j                  |       y)z0Import the Spatial Reference from a PROJ string.N)r"   	from_projr$   )r-   projs     r   import_projzSpatialReference.import_proj/  r~   r   c                 V    t        j                  | j                  t        |             y)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    TXX{:'>?r   c           
      z    t        j                  | j                  t        t	        t        |                         y)z2Import the Spatial Reference from OGC WKT (string)N)r"   from_wktr$   r   r   r   )r-   r   s     r   r%   zSpatialReference.import_wkt7  s#    dhhh{3/?&@ ABr   c                 D    t        j                  | j                  |       y)z0Import the Spatial Reference from an XML string.N)r"   from_xmlr$   )r-   xmls     r   
import_xmlzSpatialReference.import_xml;  s    dhh$r   c                 d    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      {{488U8:%677r   c                 f    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Hr   c                 d    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      ||DHHeHJ&788r   c                     | j                   S )zAlias for proj().)r   r;   s    r   proj4zSpatialReference.proj4O  s     yyr   c                 x    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'     {{488U8:%6G8LMMr   ) r   N)r   )r   )+r   r   r   __doc__r"   release_srs
destructorr2   r8   r<   r5   rB   rF   rI   rL   rN   rQ   rT   propertyr\   r0   rc   r`   rh   rg   rb   ro   rl   rm   rn   rZ   r[   rY   r,   r   r+   r%   r   r   r:   r   r   r   r   r   r   r   r   -   s    !!J9(v+:
I

V'%%$
 	 	    
  
  
  
   K K 9 9 9 9 < <
 1 1 , , 0 0''@C%
 8 8 I I 9 9   N Nr   r   c                   4    e Zd ZdZej
                  Zd Zd Zy)CoordTransformz,The coordinate system transformation object.c                     t        |t              rt        |t              st        d      t        j                  |j
                  |j
                        | _        |j                  | _        |j                  | _	        y)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-   sourcer7   s      r   r2   zCoordTransform.__init__^  sX    &"23:$<
 PQQ;;v{{FKK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   r2   r<   r   r   r   r   r   Z  s    2J&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      sO   : * )   1 6 : 8 
jNx jNZ	RX Rr   