Dan
Dan

Reputation: 416

Geodjango - how to close holes in multipolygons?

I'm using postgis and geodjango and have a lot of region geometry as multipolygon fields and it seems many of these have holes in them, is there any method I can use to close these holes and retain the outer boundary?

Thanks

Upvotes: 1

Views: 364

Answers (1)

ewcz
ewcz

Reputation: 13087

the documentation states

Whereas indexing on a Polygon will return the ring (a LinearRing object) corresponding to the index:

so in principle if P is your polygon, you can extract just the exterior ring (index 0), thus ignoring all the inner rings (defining the "holes"), and use it to construct a new polygon:

from django.contrib.gis.geos import Polygon
P_ext = Polygon(P[0])

Upvotes: 2

Related Questions