
    Hwg1                         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)GDALBase)SRSException)GDAL_VERSION)srs)force_bytes	force_strc                       e Zd ZdZdZy)	AxisOrderr      N)__name__
__module____qualname__TRADITIONAL	AUTHORITY     R/var/www/horilla/myenv/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        d      t        f      st        d      |xs t        j                  | _        |dk(  rt        j                  t        d            | _	        | j                  |       | j
                  t        j                  k(  r4t        dk\  r+t        j                  | j                  | j
                         y| j
                  t        j                  k7  r!t        dk  rt        d| j
                  z        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(  r4t        dk\  r+t        j                  | j                  | j
                         n>| j
                  t        j                  k7  r!t        dk  rt        d| j
                  z        |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').
        Nz:SpatialReference.axis_order must be an AxisOrder instance.wktr   )   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: %suser)
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
   bufs          r   __init__zSpatialReference.__init__5   s    *tDz9&=>L  %=	(=(=u||HSM2DHOOI&)"7"77LF<R&&txxA  I$9$99lV>S !E!WXX	3' 9~%,	 	3'H	4==1CH3h>??uC 3-C,,s#C =	I  DH??i3338N""488T__=__	 5 55,:OADOOSTTv""9-Y'  E  s   I$ $	I10I1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__t   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/   r9   indexs      r   r7   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   r8   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   r8   s     r   	auth_codezSpatialReference.auth_code   rE   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   rP   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)	projectedr7   
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)r9   )r*   rH   r,   r"   r=   s    r   r2   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.ra   rc   s      r   rb   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   rc   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.rh   rc   s      r   ri   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)
r[   r]   r$   rb   r&   r   r   r\   ri   r   rc   s      r   rd   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$   rn   r&   r   r   r=   s    r   rn   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$   ro   r&   r   r   r=   s    r   ro   zSpatialReference.semi_minor  rs   r   c                 d    t        j                  | j                  t        t	                           S )z9Return the Inverse Flattening for this Spatial Reference.)r$   invflatteningr&   r   r   r=   s    r   rp   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   r\   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).)rx   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).
        )rx   r$   isprojectedr&   r=   s    r   r[   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_proj2  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_input6  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_wkt:  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.wktC  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_wktH  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.projM  s      ||DHHeHJ&788r   c                     | j                   S )zAlias for proj().)r   r=   s    r   proj4zSpatialReference.proj4R  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.xmlW  s'     {{488U8:%6G8LMMr   ) r   N)r   )r   )+r   r   r   __doc__r$   release_srs
destructorr4   r:   r>   r7   rD   rH   rK   rN   rP   rS   rV   propertyr^   r2   re   rb   rj   ri   rd   rq   rn   ro   rp   r\   r]   r[   r.   r   r-   r'   r   r   r<   r   r   r   r   r   r   r   r   ,   s    !!J=(~+:
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/   sourcer9   s      r   r4   zCoordTransform.__init__a  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__k  s    04QQr   N)	r   r   r   r   r$   
destroy_ctr   r4   r>   r   r   r   r   r   ]  s    2J&Rr   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   <module>r      sO   8 * )  1 6 8 : 8 
nNx nNb	RX Rr   