Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using GeoDjango's LayerMapping utility to try and import a set of features. The catch is that aside from the attributes in the source layer, I want all the destination features to have the same value of another attribute. Specifically:

> sourceLayer = theDataSource[5]
> sourceLayer.fields
['DataSources_ID', 'Source', 'Notes', 'Shape']
> from django.contrib.gis.utils import mapping
> fieldMapping = mapping(theDataSource, layer_key=5)
{'datasources_id': 'DataSources_ID', 'source': 'Source', 'notes': 'Notes', 'shape': 'MULTIPOLYGON' }

The destination model has another field, 'owningmap', which is an integer field. I would like to load data from the OGR source via...

> lm = LayerMapping(DestinationModel, theDataSource, fieldMapping, layer=5)

... but I would like every feature to have the same integer value put in to the 'owningmap' field. As though I could somehow add a "static" mapping to fieldMapping...

> fieldMapping['owningmap'] = 2

Is this possible? Otherwise my last resort is to load via LayerMapping, then calculate the value for all the just-loaded features in a separate database transaction...


share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.