CONABIO / antares3

Madmex with open data cube and in python3
2 stars 2 forks source link

Change geometry type of Country and Region models #49

Open loicdtx opened 5 years ago

loicdtx commented 5 years ago

In madmex/models.py using GeometryField instead of enforcing MultiPolygonField for Country and Region tables would make things easier. Otherwise region that are not multipolygons have to be coerced to multipolygons.

palmoreck commented 5 years ago

Is not clear why in dict called mapping a value of POLYGON in https://github.com/CONABIO/antares3/blob/ubuntubionic/madmex/management/commands/init.py#L90 still works when GeometryField is being used here: https://github.com/CONABIO/antares3/blob/ubuntubionic/madmex/models.py#L16

With this changes ingesting from GADM administrative boundaries still a MultiPolygon object is loaded when doing:

region = 'Jalisco'
region_geom = Region.objects.get(name=region).the_geom
region_geom
<MultiPolygon object at 0x7f7d4aa2ea28>

(because GADM administrative boundaries are multipolygons)

Also have in mind This note from https://docs.djangoproject.com/es/2.1/ref/contrib/gis/tutorial/:

....Unfortunately, the shapefile data format does not allow for greater specificity with regards to geometry types. This shapefile, like many others, actually includes MultiPolygon geometries, not Polygons. It’s important to use a more general field type in models: a GeoDjango MultiPolygonField will accept a Polygon geometry, but a PolygonField will not accept a MultiPolygon type geometry. This is why the WorldBorder model defined above uses a MultiPolygonField.

palmoreck commented 5 years ago

How can we change a multipolygon to a polygon geometry...? certainly with this change would make things easier...