Code

Changes between Version 5 and Version 6 of GeoDjangoExtras


Ignore:
Timestamp:
10/22/07 18:57:58 (6 years ago)
Author:
tlp
Comment:

Adding information about LayerMapping

Legend:

Unmodified
Added
Removed
Modified
  • GeoDjangoExtras

    v5 v6  
    9494{{{ 
    9595from django.contrib.gis.utils import LayerMapping 
     96from django.contrib.gis.gdal import DataSource 
     97from geoapp.models import Zipcode 
     98 
     99ds = DataSource('/data/zipcodep.shp') 
     100 
     101# set up a mapping dictionary 
     102# the key corresponds to the attribute of the model you are saving to 
     103# the value corresponds to the field name in the shapefile 
     104mapping = {'zipcode' : 'ZIP', 
     105           'area' : 'AREA', 
     106           'perimeter' : 'PERIMETER', 
     107           'poly' : 'POLYGON'} 
     108 
     109# if the shapefile does not have the srid explicitly set you will need to pass a srs 
     110srs = SpatialRefSys.objects.get(srid=2278) 
     111 
     112 
     113lm = LayerMapping(Zipcode, ds, mapping, source_srs=srs) 
     114lm.save(verbose=True) 
     115 
     116 
     117 
    96118}}} 
    97119