o 3aC1@sdZddlmZmZmZddlmZddlmZddl m Z ddl m Z ddl mZddlmZmZGd d d eZGd d d eZGd ddeZdS)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 )byrefc_char_pc_int)IntEnum)GDALBase) SRSException) GDAL_VERSION)srs) force_bytes force_strc@seZdZdZdZdS) AxisOrderrN)__name__ __module__ __qualname__ TRADITIONAL AUTHORITYrr=/usr/lib/python3/dist-packages/django/contrib/gis/gdal/srs.pyr 'sr c@seZdZdZejZdLddZddZd d Z dMd d Z ddZ ddZ ddZ ddZddZddZddZeddZeddZed d!Zed"d#Zed$d%Zed&d'Zed(d)Zed*d+Zed,d-Zed.d/Zed0d1Zed2d3Zed4d5Zed6d7Z d8d9Z!d:d;Z"dd?Z$d@dAZ%edBdCZ&edMdDdEZ'edFdGZ(edHdIZ)edNdJdKZ*dS)OSpatialReferencez 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." userNcCst|tdtfs td|ptj|_|dkrKttd|_ | ||jtjkr8t dkr8t |j |jdS|jtjkrIt dkrItd|jdSt|t rdz t|}d|}Wn"tycYnwt|trld}nt||jrw|}d }ntd ||d kr|}n td}t|}|std |||_ |jtjkrt dkrt |j |jn|jtjkrt dkrtd|j|d kr||dS|dkr||dSdS) 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.wkt)rz"%s is not supported in GDAL < 3.0.zEPSG:%depsgogrzInvalid SRS type "%s"z+Could not create spatial reference from: %sr) isinstancetyper ValueErrorr axis_ordercapinew_srsrptr import_wktrset_axis_strategystrintptr_type TypeErrorrimport_user_input import_epsg)self srs_inputsrs_typer sridr bufrrr__init__4sV          zSpatialReference.__init__cCst|tr |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 )rtuple attr_valuer,targetrrr __getitem__qs   zSpatialReference.__getitem__cC|jS)zUse 'pretty' WKT.) pretty_wktr,rrr__str__szSpatialReference.__str__rcCs,t|tr t|ts tt|jt||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. )rr&r'r)r!get_attr_valuer#r )r,r5indexrrrr3szSpatialReference.attr_valuecCt|jt|S)z;Return the authority name for the given string target node.)r! get_auth_namer#r r4rrr auth_namezSpatialReference.auth_namecCr=)z;Return the authority code for the given string target node.)r! get_auth_coder#r r4rrr auth_coder@zSpatialReference.auth_codecCstt|j|jdS)z/Return a clone of this SpatialReference object.)r )rr! clone_srsr#r r9rrrclonezSpatialReference.clonecCt|jdS)z7Morph this SpatialReference from ESRI's format to EPSG.N)r!morph_from_esrir#r9rrr from_esrizSpatialReference.from_esricCrF)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#r9rrrrJszSpatialReference.identify_epsgcCrF)z-Morph this SpatialReference to ESRI's format.N)r! morph_to_esrir#r9rrrto_esrirIzSpatialReference.to_esricCrF)z5Check to see if the given spatial reference is valid.N)r! srs_validater#r9rrrvalidaterIzSpatialReference.validatecCs4|jr|dS|jr|dS|jr|dSdS)z*Return the name of this Spatial Reference.PROJCSGEOGCSLOCAL_CSN) projectedr3 geographiclocalr9rrrnames   zSpatialReference.namec Cs,z t|ddWSttfyYdSw)z=Return the SRID of top-level authority, or None if undefined.rr N)r'r3r)rr9rrrr/s zSpatialReference.sridcCt|jtt\}}|S)z$Return the name of the linear units.r! linear_unitsr#rrr,unitsrUrrr linear_namezSpatialReference.linear_namecCt|jtt\}}|S)z%Return the value of the linear units.rWrYrrrrXr\zSpatialReference.linear_unitscCrV)z%Return the name of the angular units.r! angular_unitsr#rrrYrrr angular_namer\zSpatialReference.angular_namecCr])z&Return the value of the angular units.r^rYrrrr_r\zSpatialReference.angular_unitscCsdd\}}|js |jrt|jtt\}}n|jr&t|jtt\}}|dur.t |}||fS)z Return a 2-tuple of the units value and the units name. Automatically determine whether to return the linear or angular units. )NNN) rRrTr!rXr#rrrSr_r rYrrrrZs zSpatialReference.unitscCs|j|j|jfS)z Return a tuple of the ellipsoid parameters: (semimajor axis, semiminor axis, and inverse flattening) ) semi_major semi_minorinverse_flatteningr9rrr ellipsoidzSpatialReference.ellipsoidcCt|jttS)z6Return the Semi Major Axis for this Spatial Reference.)r!rar#rrr9rrrrazSpatialReference.semi_majorcCrf)z6Return the Semi Minor Axis for this Spatial Reference.)r!rbr#rrr9rrrrbrgzSpatialReference.semi_minorcCrf)z9Return the Inverse Flattening for this Spatial Reference.)r! invflatteningr#rrr9rrrrc rgz#SpatialReference.inverse_flatteningcCtt|jS)zd Return True if this SpatialReference is geographic (root node is GEOGCS). )boolr! isgeographicr#r9rrrrSrezSpatialReference.geographiccCri)zFReturn True if this SpatialReference is local (root node is LOCAL_CS).)rjr!islocalr#r9rrrrTszSpatialReference.localcCri)zw Return True if this SpatialReference is a projected coordinate system (root node is PROJCS). )rjr! isprojectedr#r9rrrrRrezSpatialReference.projectedcCt|j|dS)z=Import the Spatial Reference from the EPSG code (an integer).N)r! from_epsgr#)r,rrrrr+&r@zSpatialReference.import_epsgcCrn)z0Import the Spatial Reference from a PROJ string.N)r! from_projr#)r,projrrr import_proj*r@zSpatialReference.import_projcCst|jt|dS)z>Import the Spatial Reference from the given user input string.N)r!from_user_inputr#r )r, user_inputrrrr*.rEz"SpatialReference.import_user_inputcCst|jttt|dS)z2Import the Spatial Reference from OGC WKT (string)N)r!from_wktr#rrr )r,rrrrr$2szSpatialReference.import_wktcCrn)z0Import the Spatial Reference from an XML string.N)r!from_xmlr#)r,xmlrrr import_xml6r@zSpatialReference.import_xmlcCrf)z8Return the WKT representation of this Spatial Reference.)r!to_wktr#rrr9rrrr;rgzSpatialReference.wktcCst|jtt|S)z.Return the 'pretty' representation of the WKT.)r! to_pretty_wktr#rr)r,simplifyrrrr8@szSpatialReference.pretty_wktcCrf)z:Return the PROJ representation for this Spatial Reference.)r!to_projr#rrr9rrrrqErgzSpatialReference.projcCr7)zAlias for proj().)rqr9rrrproj4JszSpatialReference.proj4cCst|jttt|S)z8Return the XML representation of this Spatial Reference.)r!to_xmlr#rrr )r,dialectrrrrwOszSpatialReference.xml)rrN)r)r)+rrr__doc__r! release_srs destructorr1r6r:r3r?rBrDrHrJrLrNpropertyrUr/r[rXr`r_rZrdrarbrcrSrTrRr+rrr*r$rxrr8rqr}rwrrrrr,sr =                    rc@s&eZdZdZejZddZddZdS)CoordTransformz,The coordinate system transformation object.cCsBt|tr t|tstdt|j|j|_|j|_|j|_ dS)z;Initialize on a source and target SpatialReference objects.z2source and target must be of type SpatialReferenceN) rrr)r!new_ct_ptrr#rU _srs1_name _srs2_name)r,sourcer5rrrr1Ys  zCoordTransform.__init__cCsd|j|jfS)NzTransform from "%s" to "%s")rrr9rrrr:aszCoordTransform.__str__N) rrrrr! destroy_ctrr1r:rrrrrUs  rN)rctypesrrrenumrdjango.contrib.gis.gdal.baserdjango.contrib.gis.gdal.errorrdjango.contrib.gis.gdal.libgdalr"django.contrib.gis.gdal.prototypesr r!django.utils.encodingr r r rrrrrrs     +