Changes between Version 3 and Version 4 of GeoDjangoExtras


Ignore:
Timestamp:
10/18/2007 09:18:41 PM (8 years ago)
Author:
tlp
Comment:

Documentation on DataSource

Legend:

Unmodified
Added
Removed
Modified
  • GeoDjangoExtras

    v3 v4  
    2727
    2828=== !GeometryColumns ===
     29
     30== !DataSource ==
     31{{{
     32>>> # read in a shapefile of zipcodes
     33>>> from django.contrib.gis.gdal import DataSource
     34>>> ds = DataSource('zipcodep.shp')
     35>>>
     36>>> # get the number of layers in the datasource
     37>>> ds.layer_count
     381
     39>>>
     40>>> # this shapefile has one layer, you can access the layer like this
     41>>> layer = ds[0]
     42>>>
     43>>> # get the field names of the layer
     44>>> print layer.fields
     45['AREA', 'PERIMETER', 'ZIP']
     46>>>
     47>>> # how many features are in this shapefile layer?
     48>>> layer.num_feat
     49150
     50>>>
     51>>> # get the geometry type of the layer
     52>>> print layer.geom_type
     53>>> Polygon
     54>>>
     55>>> # get all the areas for the features for this layer (areas of zipcodes)
     56>>> layer.get_fields('area')
     57...
     58<class 'django.contrib.gis.gdal.error.OGRException'>: invalid field name: area
     59>>>
     60>>> # note that field names are case sensitive
     61>>> layer.get_fields('AREA')
     62...
     63 6144504439.3812199,
     64 0.0]
     65>>> # get the maximum area of the zipcodes for this layer
     66>>> max(layer.get_fields('AREA'))
     67>>> 6144504439.3812199
     68
     69
     70}}}
     71
    2972== !LayerMapping ==
    3073Convenient utility for importing spatial data into geographic models from GDAL-supported data sources (''e.g.'', SHP Files).  See the [browser:django/branches/gis/django/contrib/gis/utils/layermapping.py source code] docstring for more details.
Back to Top