mapbox / shp-write

create and write to shapefiles in pure javascript
BSD 3-Clause "New" or "Revised" License
296 stars 189 forks source link

Fix direction of Polygon ring coordinates #76

Open cdbax opened 4 years ago

cdbax commented 4 years ago

The shapefile specification (pg.8) has some concrete requirements for the order of vertices for polygon 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.

The geojson specification requires the opposite orientation:

A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.

This change ensures that rings will be defined in the correct orientation based on whether it is an internal or external ring.

sheindel commented 1 year ago

Hi @cdbax! Thanks so much for putting this together!

I'm sorry this hasn't been addressed in so long. I've been slowly trying to resurrect this repo.

Your implementation mostly makes sense, but I'm curious: Have you used/are still using this fix in production? Or was this a theoretical change?

cdbax commented 1 year ago

It was used in production at the time to address an active problem we had, and it worked. I'm no longer with that company now, so can't say if it's still being used.

I was very new to programming when I wrote this, so I will not be at all offended if you need to modify/improve it.

Thanks for reaching out after so long. It will be great to see this repo get some love again. It's a great resource.

charlieforward9 commented 4 months ago

It would be nice to see the polygon ring coordinates function correctly as the company I am working for has an upcoming feature that will use these polygon structures.