node-shp icon indicating copy to clipboard operation
node-shp copied to clipboard

Added support for GeoJSON MultiPolygon with holes

Open icetan opened this issue 12 years ago • 1 comments

To determine if a polygon has multiple parts with or without holes I walk each ring and each time a clockwise ring is parsed it is added as a new polygon part. Each time a counter-clockwise ring appears it is added to the previously parsed clockwise ring and forms only one polygon together with holes.

If there is more than one clockwise ring in a feature the geometry type is set to "MultiPolygon".

I used this this file as reference (page nr. 8): http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

icetan avatar Mar 07 '13 08:03 icetan

I realized that there might be a problem with this tough.

Rings in a polygon stored in a Shape-file may occur in any order. If a counter-clockwise ring occurs in the wrong order and does not reside inside the previously parsed clockwise ring the counter-clockwise ring will be added incorrectly as a hole to the previous polygon part.

The only way to split the rings into separate GeoJSON polygons correctly and combine them into a multipolygon, that I can see, is to check intersection between the rings. This is a costly process though but the GeoJSON spec. says that each ring following the first in a polygon must be interior rings or holes.

Anyway this is something to think about and improve on in the future.

icetan avatar Mar 07 '13 08:03 icetan