o
    :Zc-                     @   sp   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m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)GDALBase)SRSException)srs)force_bytes	force_strc                   @   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d/d0 Zed1d2 Zed3d4 Zed5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%edAdB Z&edMdCdDZ'edEdF Z(edGdH Z)edNdIdJZ*dKS )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."
     userc                 C   s   |dkrt td| _| | dS t|tr,z
t|}d| }W n" ty+   Y nw t|tr4d}nt|| j	r?|}d}nt
d| |dkrL|}n	td}t |}|s]td| || _|d	krk| | dS |dkrv| | 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.4 string, and/or a projection "well known" shorthand
        string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
        wkt    NzEPSG:%depsgogrzInvalid SRS type "%s"z+Could not create spatial reference from: %sr   )capinew_srsr   ptr
import_wkt
isinstancestrint
ValueErrorptr_type	TypeErrorr   import_user_inputimport_epsg)self	srs_inputsrs_typesridr   buf r"   Q/var/www/chikooza/env/lib/python3.10/site-packages/django/contrib/gis/gdal/srs.py__init__-   s:   



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
        >>> print(srs['UNIT|AUTHORITY']) # For the units authority, have to use the pipe symbole.
        EPSG
        >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the units
        9122
        )r   tuple
attr_valuer   targetr"   r"   r#   __getitem__^   s   


zSpatialReference.__getitem__c                 C      | j S )zUse 'pretty' WKT.)
pretty_wktr   r"   r"   r#   __str__z   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   r(   indexr"   r"   r#   r&      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   r'   r"   r"   r#   	auth_name      zSpatialReference.auth_namec                 C   r0   )z;Return the authority code for the given string target node.)r   get_auth_coder   r   r'   r"   r"   r#   	auth_code   r3   zSpatialReference.auth_codec                 C      t t| jS )z/Return a clone of this SpatialReference object.)r
   r   	clone_srsr   r,   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   r,   r"   r"   r#   	from_esri   r9   zSpatialReference.from_esric                 C   r:   )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,   r"   r"   r#   r=      s   zSpatialReference.identify_epsgc                 C   r:   )z-Morph this SpatialReference to ESRI's format.N)r   morph_to_esrir   r,   r"   r"   r#   to_esri   r9   zSpatialReference.to_esric                 C   r:   )z5Check to see if the given spatial reference is valid.N)r   srs_validater   r,   r"   r"   r#   validate   r9   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)	projectedr&   
geographiclocalr,   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.	AUTHORITY   N)r   r&   r   r   r,   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   unitsrH   r"   r"   r#   linear_name      zSpatialReference.linear_namec                 C      t | jtt \}}|S )z%Return the value of the linear units.rL   rN   r"   r"   r#   rM      rQ   zSpatialReference.linear_unitsc                 C   rK   )z%Return the name of the angular units.r   angular_unitsr   r   r   rN   r"   r"   r#   angular_name   rQ   zSpatialReference.angular_namec                 C   rR   )z&Return the value of the angular units.rS   rN   r"   r"   r#   rT      rQ   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)
rE   rG   r   rM   r   r   r   rF   rT   r	   rN   r"   r"   r#   rO      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_flatteningr,   r"   r"   r#   	ellipsoid      zSpatialReference.ellipsoidc                 C      t | jtt S )z6Return the Semi Major Axis for this Spatial Reference.)r   rV   r   r   r   r,   r"   r"   r#   rV         zSpatialReference.semi_majorc                 C   r[   )z6Return the Semi Minor Axis for this Spatial Reference.)r   rW   r   r   r   r,   r"   r"   r#   rW      r\   zSpatialReference.semi_minorc                 C   r[   )z9Return the Inverse Flattening for this Spatial Reference.)r   invflatteningr   r   r   r,   r"   r"   r#   rX      r\   z#SpatialReference.inverse_flatteningc                 C   r6   )zd
        Return True if this SpatialReference is geographic
         (root node is GEOGCS).
        )boolr   isgeographicr   r,   r"   r"   r#   rF      rZ   zSpatialReference.geographicc                 C   r6   )zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)r^   r   islocalr   r,   r"   r"   r#   rG     s   zSpatialReference.localc                 C   r6   )zw
        Return True if this SpatialReference is a projected coordinate system
         (root node is PROJCS).
        )r^   r   isprojectedr   r,   r"   r"   r#   rE   
  rZ   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     r3   zSpatialReference.import_epsgc                 C   rb   )z2Import the Spatial Reference from a PROJ.4 string.N)r   	from_projr   )r   projr"   r"   r#   import_proj  r3   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     s   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     s   zSpatialReference.import_wktc                 C   rb   )z0Import the Spatial Reference from an XML string.N)r   from_xmlr   )r   xmlr"   r"   r#   
import_xml#  r3   zSpatialReference.import_xmlc                 C   r[   )z8Return the WKT representation of this Spatial Reference.)r   to_wktr   r   r   r,   r"   r"   r#   r   (  r\   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#   r+   -  s   zSpatialReference.pretty_wktc                 C   r[   )z<Return the PROJ.4 representation for this Spatial Reference.)r   to_projr   r   r   r,   r"   r"   r#   re   2  r\   zSpatialReference.projc                 C   r*   )zAlias for proj().)re   r,   r"   r"   r#   proj47  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#   rk   <  s   zSpatialReference.xmlN)r   r   )r   )r   )+__name__
__module____qualname____doc__r   release_srs
destructorr$   r)   r-   r&   r2   r5   r8   r<   r=   r?   rA   propertyrH   r    rP   rM   rU   rT   rO   rY   rV   rW   rX   rF   rG   rE   r   rf   r   r   rl   r   r+   re   rq   rk   r"   r"   r"   r#   r
   %   sr    
1
	
















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   rH   
_srs1_name
_srs2_name)r   sourcer(   r"   r"   r#   r$   F  s
   zCoordTransform.__init__c                 C   s   d| j | jf S )NzTransform from "%s" to "%s")r~   r   r,   r"   r"   r#   r-   N  s   zCoordTransform.__str__N)	rt   ru   rv   rw   r   
destroy_ctry   r$   r-   r"   r"   r"   r#   r{   B  s
    r{   N)rw   ctypesr   r   r   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>   s      