I want to use LayerMapping to insert any shapefile to PostGIS. I insert the geometry only, into generic tables. For that i need a mapping between the shapefile field names and the django models field name, like in: the LayerMapping documentation. How can I do this dynamically? I know i can do:
ds = DataSource(shapefile_directory) lyr = ds print lyr.fields ['FIPS', 'ISO2', 'ISO3', 'UN', 'NAME', 'AREA', 'POP2005', 'REGION', 'SUBREGION', 'LON', 'LAT']
but that does not return the field name of the geometry. And
print lyr.geom_type Polygon #Even if it actually is Multipolygon
only gives the basic geom type. I read in LayerMapping doc that for 'For geometry fields use OGC name', but then I need to know if the geom type is e.g 'MULTIPOLYGON' or 'POLYGON'. I would like something like this: field_name = lyr.geomfield
Edit: I solved it by instead of having one DB-table for each of Multi-Point, -Poly and -Line, having one with a Geometry-field. Then I didn't need the LayerMapping-magic. I also got to know that the germ-field in a shapefile does in fact not have a field-name, so the solution I requested was not possible.