Multipolygons 

For the three other shapefiles with multipolygon geometry types, we'll pass the argument—multi to manage.py and ogrinspect. Using this option generates a MultiPolygon geometry column in the data model.

This command generates a data model from the US States shapefile:

C:Projectschapter12>python manage.py ogrinspect arenasdataUS_States.shp US_States 
--srid=4326 --mapping --multi

The output will look like this:

# This is an auto-generated Django model module created by ogrinspect.
from django.contrib.gis.db import models
class US_States(models.Model):
stfips = models.CharField(max_length=2)
state = models.CharField(max_length=66)
stpostal = models.CharField(max_length=2)
version = models.CharField(max_length=2)
dotregion = models.IntegerField()
shape_leng = models.FloatField()
shape_area = models.FloatField()
geom = models.MultiPolygonField(srid=4326)
# Auto-generated `LayerMapping` dictionary for US_States model
us_states_mapping = {
'stfips': 'STFIPS',
'state': 'STATE',
'stpostal': 'STPOSTAL',
'version': 'VERSION',
'dotregion': 'DotRegion',
'shape_leng': 'Shape_Leng',
'shape_area': 'Shape_Area',
'geom': 'MULTIPOLYGON',
}

Copy the output to models.py, including both the data model and the field mapping dictionary. Repeat the process for the counties and districts shapefiles by adjusting the arguments to manage.py (that is, the shapefile name and the table name), and save models.py once the models have been added.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset