[GIS] How are the coordinates for multipolygons arranged

coordinatesholespolygonvector

How are the coordinates for a multipolygon (i.e. polygon with a hole in it) arranged?

Do shapefiles and geoJSON files always save the coordinates for the outer ring first?

I'm asking because I have a set of multipolygons with holes and I'm looking to convert them to standard polygons by removing the coordinates of the holes.

If the outer ring of the polygon is always saved as the first set of coordinates, then I know I can easily select those.

Best Answer

I recommend to read the specifications. GeoJSON https://www.rfc-editor.org/rfc/rfc7946

For type "Polygon", the "coordinates" member MUST be an array of linear ring coordinate arrays.

o For Polygons with more than one of these rings, the first MUST be the exterior ring, and any others MUST be interior rings. The exterior ring bounds the surface, and the interior rings (if present) bound holes within the surface.

3.1.7. MultiPolygon

For type "MultiPolygon", the "coordinates" member is an array of
Polygon coordinate arrays.

Shapefile https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf. Notise that the specification defines also features with several exterior rings as polygons.

Polygon A polygon consists of one or more rings. A ring is a connected sequence of four or more points that form a closed, non-self-intersecting loop. A polygon may contain multiple outer rings. The order of vertices or orientation for a ring indicates which side of the ring is the interior of the polygon. The neighborhood to the right of an observer walking along the ring in vertex order is the neighborhood inside the polygon. Vertices of rings defining holes in polygons are in a counterclockwise direction. Vertices for a single, ringed polygon are, therefore, always in clockwise order. The rings of a polygon are referred to as its parts.

Later in the shapefile spec comes The order of rings in the points array is not significant.

Conclusion: From GeoJSON find the polygon members and from those select the first rings. From ESRI Shapefiles select rings which are ordered clockwise. But if you use some existing library for reading the shapefiles you must learn how it works.