o aP!@sddlmZmZddlmZddlmZmZddlm Z m Z ddl m Z ddl mZddlmZddlmZdd lmZmZmZdd lmZdd lmZmZGd d d eZdS))byrefc_double)GDALBase)Envelope OGREnvelope) GDALException SRSException)Feature) OGRFieldTypes) OGRGeometry) OGRGeomType)dsgeomsrs)SpatialReference) force_bytes force_strc@seZdZdZddZddZddZdd Zd d Zd d Z e ddZ e ddZ e d/ddZ e ddZe ddZe ddZe ddZe ddZe dd Ze d!d"Zd#d$Zd%d&Ze eeZd'd(Zd0d*d+Zd,d-Zd.S)1LayerzSA class that wraps an OGR Layer, needs to be instantiated from a DataSource object.cCs6|std||_||_t|j|_|d|_dS)a7 Initialize on an OGR C pointer to the Layer and the `DataSource` object that owns this layer. The `DataSource` object is required so that a reference to it is kept with this Layer. This prevents garbage collection of the `DataSource` while this Layer is still active. z*Cannot create Layer, invalid pointer givens RandomReadN) rptr_dscapiget_layer_defn_ptr_ldefntest_capability _random_read)self layer_ptrr r?/usr/lib/python3/dist-packages/django/contrib/gis/gdal/layer.py__init__s zLayer.__init__csbt|tr|dkr td|St|tr-|j\}}}fddt|||DStd)z'Get the Feature at the specified index.rz/Negative indices are not allowed on OGR Layers.csg|]}|qSr) _make_feature).0fidrrr 3z%Layer.__getitem__..z>Integers and slices may only be used when indexing OGR Layers.) isinstanceint IndexErrorr!sliceindicesnum_featrange TypeError)rindexstartstopstriderr$r __getitem__'s   zLayer.__getitem__ccs6t|jt|jD] }tt|j|Vq dS)z'Iterate over each Feature in the Layer.N)r reset_readingrr-r,r get_next_feature)rirrr__iter__7s  zLayer.__iter__cC|jS)z%The length is the number of features.)r,r$rrr__len__>z Layer.__len__cCr8)zThe string name of the layer.)namer$rrr__str__Br:z Layer.__str__cCsX|jrz tt|j||WStyYnw|D] }|j|kr%|Sqtd|)a. Helper routine for __getitem__ that constructs a Feature from the given Feature ID. If the OGR Layer does not support random-access reading, then each feature of the layer will be incremented through until the a Feature is found matching the given feature ID. zInvalid feature id: %s.)rr r get_featurerrr#r))rfeat_idfeatrrrr!Fs   zLayer._make_featurecCs"t}t|jt|dt|S)z.Return the extent (an Envelope) of this layer.)rr get_extentrrr)renvrrrextent]sz Layer.extentcCst|j}t||jjddS)z1Return the name of this layer in the Data Source.T strings_only)r get_fd_namerrrencoding)rr;rrrr;ds z Layer.namer@cCst|j|S)z+Return the number of features in the Layer.)rget_feature_countr)rforcerrrr,jszLayer.num_featcCs t|jS)z)Return the number of fields in the Layer.)rget_field_countrr$rrr num_fieldsos zLayer.num_fieldscCstt|jS)z4Return the geometry type (OGRGeomType) of the Layer.)r rget_fd_geom_typerr$rrr geom_typetszLayer.geom_typecCs2zt|j}tt|WStyYdSw)z0Return the Spatial Reference used in this Layer.N)r get_layer_srsrrsrs_api clone_srsr)rrrrrrys   z Layer.srscfddtjDS)zt Return a list of string names corresponding to each of the Fields available in this Layer. c s.g|]}tttj|jjddqS)TrD)rrget_field_nameget_field_defnrrrGr"r6r$rrr%s  z Layer.fields..r-rKr$rr$rfieldss z Layer.fieldscrQ)z Return a list of the types of fields in this Layer. For example, return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that has an integer, a floating-point, and string fields. c s$g|]}tttj|qSr)r rget_field_typerSrrTr$rrr%sz%Layer.field_types..rUr$rr$r field_typess zLayer.field_typescrQ)z;Return a list of the maximum field widths for the features.c g|] }ttj|qSr)rget_field_widthrSrrTr$rrr%z&Layer.field_widths..rUr$rr$r field_widths zLayer.field_widthscrQ)z-Return the field precisions for the features.crYr)rget_field_precisionrSrrTr$rrr%r[z*Layer.field_precisions..rUr$rr$rfield_precisionsr]zLayer.field_precisionscCs.z ttt|jWStyYdSw)N)r geom_api clone_geomrget_spatial_filterrrr$rrr_get_spatial_filters  zLayer._get_spatial_filtercCst|trt|j|jdSt|ttfr5t|dks tdt t |\}}}}t |j||||dS|durBt|jddSt d)Nz/Spatial filter list/tuple must have 4 elements.zJSpatial filter must be either an OGRGeometry instance, a 4-tuple, or None.) r'r rset_spatial_filterrtuplelistlen ValueErrormaprset_spatial_filter_rectr.)rfilterxminyminxmaxymaxrrr_set_spatial_filters  zLayer._set_spatial_filtercs(|jvr tdfdd|DS)zg Return a list containing the given field name for every Feature in the Layer. zinvalid field name: %scsg|]}|qSr)getr"r? field_namerrr%r&z$Layer.get_fields..)rVr)rrurrtr get_fieldss  zLayer.get_fieldsFcs0|rddlmfdd|DSdd|DS)zb Return a list containing the OGRGeometry for every Feature in the Layer. r GEOSGeometrycsg|]}|jjqSr)rwkbrsrwrrr%sz#Layer.get_geoms..cSsg|]}|jqSr)rrsrrrr%s)django.contrib.gis.geosrx)rgeosrrwr get_geomss zLayer.get_geomscCstt|jt|S)ah Return a bool indicating whether the this Layer supports the given capability (a string). Valid capability strings include: 'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter', 'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions', 'DeleteFeature', and 'FastSetNextByIndex'. )boolrrrr)r capabilityrrrrszLayer.test_capabilityN)r@)F)__name__ __module__ __qualname____doc__r r3r7r9r<r!propertyrCr;r,rKrMrrVrXr\r_rcrqspatial_filterrvr|rrrrrrsD            rN) ctypesrrdjango.contrib.gis.gdal.baser django.contrib.gis.gdal.enveloperrdjango.contrib.gis.gdal.errorrrdjango.contrib.gis.gdal.featurer django.contrib.gis.gdal.fieldr "django.contrib.gis.gdal.geometriesr django.contrib.gis.gdal.geomtyper "django.contrib.gis.gdal.prototypesr rrr`rrOdjango.contrib.gis.gdal.srsrdjango.utils.encodingrrrrrrrs