Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
> lm.save()

... 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...

Thanks!

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.