o a@s|dZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZmZGd d d eZd S) a DataSource is a wrapper for the OGR Data Source object, which provides an interface for reading vector geometry data from many different file formats (including ESRI shapefiles). When instantiating a DataSource object, use the filename of a GDAL-supported data source. For example, a SHP file or a TIGER/Line file from the government. The ds_driver keyword is used internally when a ctypes pointer is passed in directly. Example: ds = DataSource('/home/foo/bar.shp') for layer in ds: for feature in layer: # Getting the geometry for the feature. g = feature.geom # Getting the 'description' field for the feature. desc = feature['description'] # We can also increment through all of the fields # attached to this feature. for field in feature: # Get the name of the field (e.g. 'description') nm = field.name # Get the type (integer) of the field, e.g. 0 => OFTInteger t = field.type # Returns the value the field; OFTIntegers return ints, # OFTReal returns floats, all else returns string. val = field.value )byref)Path)GDALBase)Driver) GDALException)Layer)ds) force_bytes force_strc@sPeZdZdZejZdddZddZdd Z d d Z e d d Z e ddZ dS) DataSourcez Wraps an OGR Data Source object.Futf-8cCs|rd|_nd|_||_tt|ttfr7t}zt t ||jt |}Wn$t y6t d|wt||jrFt|tjrF|}nt dt ||rZ||_t||_dSt d|)Nrz%Could not open the datasource at "%s"z"Invalid data source input type: %szInvalid data source file "%s")_writeencodingrensure_registered isinstancestrrptr_typecapiopen_dsr rrtypeptrdriver)selfds_input ds_driverwriterrrD/usr/lib/python3/dist-packages/django/contrib/gis/gdal/datasource.py__init__7s&   zDataSource.__init__cCst|trz t|jt|}Wn5tytd|wt|tr>d|kr.|j kr8nnt |j |}ntd|t dt |t||S)z@Allows use of the index [] operator to get a layer at the index.z!Invalid OGR layer name given: %s.rz=Index out of range when accessing layers in a datasource: %s.zInvalid index type: %s)rrrget_layer_by_namerr r IndexErrorint layer_count get_layer_ptr TypeErrorrr)rindexlayerrrr __getitem__Xs      zDataSource.__getitem__cCs|jS)z3Return the number of layers within the data source.)r#rrrr__len__hszDataSource.__len__cCsd|j|jfS)z2Return OGR GetName and Driver for the Data Source.z%s (%s))namerr*rrr__str__lszDataSource.__str__cCs t|jS)z/Return the number of layers in the data source.)rget_layer_countr%r*rrrr#ps zDataSource.layer_countcCst|j}t||jddS)z#Return the name of the data source.T) strings_only)r get_ds_namer%r r)rr,rrrr,us zDataSource.nameN)FFr )__name__ __module__ __qualname____doc__r destroy_ds destructorrr)r+r-propertyr#r,rrrrr 3s ! r N)r4ctypesrpathlibrdjango.contrib.gis.gdal.baserdjango.contrib.gis.gdal.driverrdjango.contrib.gis.gdal.errorrdjango.contrib.gis.gdal.layerr"django.contrib.gis.gdal.prototypesrrdjango.utils.encodingr r r rrrrs #