GeometryColumns

DataSource

>>> # read in a shapefile of zipcodes
>>> from django.contrib.gis.gdal import DataSource
>>> ds = DataSource('zipcodep.shp')
>>>
>>> # get the number of layers in the datasource
>>> ds.layer_count
1
>>>
>>> # this shapefile has one layer, you can access the layer like this
>>> layer = ds[0]
>>>
>>> # get the field names of the layer
>>> print layer.fields
['AREA', 'PERIMETER', 'ZIP']
>>>
>>> # how many features are in this shapefile layer?
>>> layer.num_feat
150
>>>
>>> # get the geometry type of the layer
>>> print layer.geom_type
>>> Polygon
>>>
>>> # get all the areas for the features for this layer (areas of zipcodes)
>>> layer.get_fields('area')
...
<class 'django.contrib.gis.gdal.error.OGRException'>: invalid field name: area
>>>
>>> # note that field names are case sensitive
>>> layer.get_fields('AREA')
...
6144504439.3812199,
0.0]
>>> # get the maximum area of the zipcodes for this layer
>>> max(layer.get_fields('AREA'))
>>> 6144504439.3812199