[Django]-GeoDjango inteprets MultiPolygon as LinearRing

2👍

Each polygon of a MultiPolygon should still form a closed linestring. Your data is probably malformed or corrupted.

You can try to fix this by using ST_MakeValid.

UPDATE aeroway_polygon
SET geom = ST_Multi(ST_CollectionExtract(ST_Makevalid(geom), 3))
WHERE ST_IsValid(geom) = false;

Note that I didn’t test this query, I found it here on gis.stackexchange.

1👍

Polygons by definition are closed geometries, which means that the first and last Point must be the same exact Point.
For Multipolygons the same principle exists, hence every Polygon of a Multipolygon must be closed and there must not be “free” edges inside the geometry.

If you check your dataset you will find that some of those LineStrings are not closing.

@AntoinePinsard gives a good PostGIS solution.
In GeoDjango version >= 1.10, MakeValid exists as a database function and we can use it on queries:

AerowayPolygon.objects.all().update(geom=MakeValid('geom'))

If your Django version < 1.10, I have a set of answers on how to create a custom database function and use it as in the example above:

from django.contrib.gis.db.models.functions import GeoFunc

class MyMakeValid(GeoFunc):
      function='ST_MakeValid'

AerowayPolygon.objects.all().update(geom=MyMakeValid('geom'))

Leave a comment