o a6@sZddlmZmZddlmZmZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZeeaed gd Zd d ZGd ddeZGdddeZ Gddde Z!Gddde Z"Gddde Z#Gddde Z$Gddde Z%Gddde Z&Gddde Z'Gdd d eZ(Gd!d"d"eZ)d#S)$) defaultdict namedtuple)formsgdal) SpatialProxy) GDALException) GeometryCollection GEOSException GEOSGeometry LineStringMultiLineString MultiPoint MultiPolygonPointPolygon)ImproperlyConfigured)Field) gettext_lazySRIDCacheEntryunits units_namespheroidgeodeticcsddlm}zjWn tydYnwr%jfddfnd|f\}}|t|vrP||}|j\}}t||d|d|j |j f|j dt||<t||S) z Return the units, unit name, and spheroid WKT associated with the given SRID from the `spatial_ref_sys` (or equivalent) spatial database table for the given database connection. These results are cached. r)SpatialReferenceNcsjjj|djS)Nsrid)objectsusingaliasgetsrsr SpatialRefSys connectionE/usr/lib/python3/dist-packages/django/contrib/gis/db/models/fields.py'szget_srid_info..zSPHEROID["%s",%s,%s]rr) django.contrib.gis.gdalropsspatial_ref_sysNotImplementedErrorr _srid_cacherr semi_majorinverse_flattening geographic)rr$rrget_srsr!rrr%r"r& get_srid_infos(     r1cseZdZdZedZdZdfdd Zfd d Zd d Z d dZ ddZ ddZ ddZ ddZddZfddZddZfddZZS) BaseSpatialFieldz The Base GIS Field. It's used as a base class for GeometryField and RasterField. Defines properties that are common to all GIS fields such as the characteristics of the spatial reference system of the field. zThe base GIS field.FNTc s*||_||_||d<tjdi|dS)a The initialization function for base spatial fields. Takes the following as keyword arguments: srid: The spatial reference system identifier, an OGC standard. Defaults to 4326 (WGS84). spatial_index: Indicates whether to create a spatial index. Defaults to True. Set this instead of 'db_index' for geographic fields since index creation is different for geometry columns. verbose_nameNr%) spatial_indexrsuper__init__)selfr4rr5kwargs __class__r%r&r7CszBaseSpatialField.__init__cs<t\}}}}|j|d<|jdur|j|d<||||fS)NrTr5)r6 deconstructrr5r8namepathargsr9r:r%r&r<_s     zBaseSpatialField.deconstructcCs |j|SN)r) geo_db_typer8r$r%r%r&db_typeh zBaseSpatialField.db_typecCt|j|jSrA)r1rrrCr%r%r&rkzBaseSpatialField.spheroidcCrFrA)r1rrrCr%r%r&rnrGzBaseSpatialField.unitscCrFrA)r1rrrCr%r%r&rqrGzBaseSpatialField.units_namecCrF)z Return true if this field's SRID corresponds with a coordinate system that uses non-projected units (e.g., latitude/longitude). )r1rrrCr%r%r&rtszBaseSpatialField.geodeticcCs|j|||S)z\ Return the placeholder for the spatial column for the given value. )r)get_geom_placeholder)r8valuecompilerr$r%r%r&get_placeholder{sz BaseSpatialField.get_placeholdercCs4|j}|dus|jdks|dkr|jdkr|jS|S)a Return the default SRID for the given geometry or raster, taking into account the SRID set for the field. For example, if the input geometry or raster doesn't have an SRID, then the SRID of the field will be returned. Nr)r8objrr%r%r&get_srids$zBaseSpatialField.get_sridcsR|durdS|jjtj||g|Ri|fi|jr%|jjr%ddiSiS)N geographyT)r)Adapterr6get_db_prep_valuerOfeaturessupports_geography)r8rIr$r@r9r:r%r&rQsz"BaseSpatialField.get_db_prep_valuecCslt|tjr|S|rzt|WStyYdSwt|tr4zt|WSty3td|wdS)zY Return a GDALRaster if conversion is successful, otherwise return None. 6Couldn't create spatial object from lookup value '%s'.N) isinstancer GDALRasterrdict ValueError)r8rI is_candidater%r%r&get_raster_prep_values       z&BaseSpatialField.get_raster_prep_valuec st|}|dur dSt|trn8t|ttfpt|d}|||}|r)|}n!|rAzt|}Wntt fy@t d|wt dt |j | ||_|S)N__geo_interface__rTz>Cannot use object with type %s for a spatial lookup parameter.)r6get_prep_valuerUr bytesstrhasattrrZr rrXtype__name__rNr)r8rIrMrYrasterr:r%r&r\s$      zBaseSpatialField.get_prep_value)Nr3T)ra __module__ __qualname____doc___ descriptionempty_strings_allowedr7r<rDrrrrrKrNrQrZr\ __classcell__r%r%r:r&r28s     r2csleZdZdZedZejZdZ dZ dddd fd d Z fd d Z fddZ fddZddZZS) GeometryFieldzU The base Geometry field -- maps to the OpenGIS Specification Geometry type. uLThe base Geometry field — maps to the OpenGIS Specification Geometry type.GEOMETRYNFgfgVgf@gV@皙?)extent tolerancec s2||_||_||_||_tjdd|i|dS)a The initialization function for geometry fields. In addition to the parameters from BaseSpatialField, it takes the following as keyword arguments: dim: The number of dimensions for this geometry. Defaults to 2. extent: Customize the extent, in a 4-tuple of WGS 84 coordinates, for the geometry field entry in the `USER_SDO_GEOM_METADATA` table. Defaults to (-180.0, -90.0, 180.0, 90.0). tolerance: Define the tolerance, in meters, to use for the geometry field entry in the `USER_SDO_GEOM_METADATA` table. Defaults to 0.05. r4Nr%)dimrO_extent _tolerancer6r7)r8r4rqrOrorpr9r:r%r&r7s zGeometryField.__init__csnt\}}}}|jdkr|j|d<|jdur|j|d<|jdkr'|j|d<|jdkr1|j|d<||||fS) NrlrqFrOrmrornrp)r6r<rqrOrrrsr=r:r%r&r<s         zGeometryField.deconstructc s8tj||fi|t||jt|jpt|tddS)N) load_func)r6contribute_to_classsetattrattnamer geom_classr r8clsr>r9r:r%r&rus"z!GeometryField.contribute_to_classc sR|j|j|jd|}|jdkr t|djdds |dtjt j di|S)N) form_class geom_typerrlr{ supports_3dFwidgetr%) r{r|rrqgetattrr~ setdefaultrTextarear6 formfield)r8r9defaultsr:r%r&rszGeometryField.formfieldcCs"|jjs |jjj||fS||fS)z Return the selection format string, depending on the requirements of the spatial backend. For example, Oracle and MySQL require custom selection formats in order to retrieve geometries in OGC WKB. )querysubqueryr$r)select)r8rJsqlparamsr%r%r& select_formatszGeometryField.select_format)NrlF)rarcrdrerfrgrrjr{r|rxr7r<rurrrir%r%r:r&rjs  rjc@"eZdZdZeZejZe dZ dS) PointFieldPOINTrN) rarcrdr|rrxrrr{rfrgr%r%r%r&r  rc@r)LineStringField LINESTRINGz Line stringN) rarcrdr|r rxrrr{rfrgr%r%r%r&r$rrc@r) PolygonFieldPOLYGONrN) rarcrdr|rrxrrr{rfrgr%r%r%r&r+rrc@r)MultiPointField MULTIPOINTz Multi-pointN) rarcrdr|r rxrrr{rfrgr%r%r%r&r2rrc@r)MultiLineStringFieldMULTILINESTRINGzMulti-line stringN) rarcrdr|r rxrrr{rfrgr%r%r%r&r9rrc@r)MultiPolygonField MULTIPOLYGONz Multi polygonN) rarcrdr|rrxrrr{rfrgr%r%r%r&r@rrc@r)GeometryCollectionFieldGEOMETRYCOLLECTIONzGeometry collectionN) rarcrdr|rrxrrr{rfrgr%r%r%r&rGrrc@s(eZdZdZedZddZddZdS) ExtentFieldz/Used as a return value from an extent aggregatezExtent Aggregate FieldcCsdS)Nrr%)r8r%r%r&get_internal_typeSszExtentField.get_internal_typecCs"|jjj}|r |||fS||fSrA)r$r) select_extent)r8rJrrrr%r%r&rVs zExtentField.select_formatN)rarcrdrerfrgrrr%r%r%r&rNs  rcsXeZdZdZedZdZdZddZfddZ d d Z fd d Z fd dZ Z S) RasterFieldzJ Raster field for GeoDjango -- evaluates into GDALRaster objects. z Raster FieldRASTERFcCs|jjr|jjs tddS)Nz3Raster fields require backends with raster support.)rR gis_enabledsupports_rasterrrCr%r%r&_check_connectiondszRasterField._check_connectioncs||t|SrA)rr6rDrCr:r%r&rDis  zRasterField.db_typecCs |j|SrA)r) parse_raster)r8rI expressionr$r%r%r& from_db_valuemrEzRasterField.from_db_valuec s0tj||fi|t||jttj|dSrA)r6rurvrwrrrVryr:r%r&rupszRasterField.contribute_to_classcsHddlm}zt|}td|fd|iWStyYnwt|S)Nr)RasterBandTransformSpecificRasterBandTransform band_index)$django.contrib.gis.db.models.lookupsrintr`rXr6 get_transform)r8r>rrr:r%r&rxs   zRasterField.get_transform)rarcrdrerfrgr|rOrrDrrurrir%r%r:r&r[s  rN)* collectionsrrdjango.contrib.gisrr"django.contrib.gis.db.models.proxyrdjango.contrib.gis.gdal.errorrdjango.contrib.gis.geosrr r r r r rrrdjango.core.exceptionsrdjango.db.modelsrdjango.utils.translationrrfrWr,rr1r2rjrrrrrrrrrr%r%r%r&s.  ,   !T