Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon winding order & holes vs outer rings #59

Closed
mourner opened this issue Sep 23, 2014 · 12 comments
Closed

Polygon winding order & holes vs outer rings #59

mourner opened this issue Sep 23, 2014 · 12 comments
Labels

Comments

@mourner
Copy link
Member

mourner commented Sep 23, 2014

Do geometry rings have a defined winding order in vector tiles? E.g. counter-clockwise for outer rings and clockwise for rings? Or should I expect any order of any particular ring?

Winding order isn't mentioned anywhere in spec, but some polygon algorithms depend on a certain winding order. Also, some algorithms (especially triangulation) need to know if a polygon ring is a hole or an outer ring, which could also be derived from winding order if geometry is flattened.

@mourner mourner changed the title Polygon winding order? Polygon winding order & holes vs outer rings Sep 23, 2014
@mourner
Copy link
Member Author

mourner commented Sep 23, 2014

OK, so Artem says we pass winding order as is, so there's no easy way to derive ring status... Could you consider winding order correction for a future release? It's pretty easy, and given that geometries are flattened, it would be extremely useful. Usual accepted order is CCW for outer rings, CW for rings.

@mourner
Copy link
Member Author

mourner commented Oct 27, 2014

Note that closing #53 will also close this issue, since polygon clipping procedure also resets winding order. Although fixing just the latter is much easier.

@pnorman
Copy link
Contributor

pnorman commented Oct 27, 2014

Could you consider winding order correction for a future release?

Wouldn't the spec need to change for rings to have a defined winding order, or are you suggesting giving an order that wasn't there in the tile when parsing one?

@mourner
Copy link
Member Author

mourner commented Oct 27, 2014

@pnorman yes, I'm suggesting changing the winding order of polygon rings depending on whether it's a hole or an outer ring. I don't see any problems with this since the original winding order is pretty much random and has no practical use.

@jfirebaugh
Copy link

👍 for having a specified winding order.

@pnorman
Copy link
Contributor

pnorman commented Oct 28, 2014

@pnorman yes, I'm suggesting changing the winding order of polygon rings depending on whether it's a hole or an outer ring. I don't see any problems with this since the original winding order is pretty much random and has no practical use.

I don't see an issue with it either, but I'm just questioning if it's a mapnik-vector-tile issue or an issue that the specification doesn't require a winding order.

@jfirebaugh
Copy link

The fix for this would be to update both the specification (to require a winding order), and mapnik-vector-tile (to output spec-compliant windings).

@mourner
Copy link
Member Author

mourner commented Jan 20, 2015

Another thing to note is that Mapnik VT output doesn't have outer1, inner1, inner1, ..., outer2, inner2, ... order — it can have outer rings and holes mixed up in random order, which is a problem when you're trying to figure out which is which.

@mourner
Copy link
Member Author

mourner commented Feb 24, 2015

Another approach is to just split MultiPolygons into several Polygon features. This is how Mapzen solved the issue: tilezen/mapbox-vector-tile#4

@bcamper
Copy link

bcamper commented Feb 24, 2015

@mourner yep, not an ideal solution, it would be nice to have multi-geometries directly supported in the spec.

@springmeyer
Copy link
Contributor

Update here: my plan is to have mapnik-vector-tile ensure:

    1. exterior rings are encoded as CCW
    1. interior rings are encoded as CW
    1. interior rings always follow exterior rings

So, here are some examples then of how you would decode:

  • CCW -> single polygon, no interior rings
  • CCW,CW,CW -> single polygon, two interior rings
  • CCW,CCW,CCW - > Multipolygon with 3 polygons, each with only an exterior ring
  • CCW,CCW,CCW,CW - > Multipolygon with 3 polygons, each with one exterior ring, and the final one with one exterior ring and one interior ring
  • CW -> single interior ring: degenerate, throw it out

As part of this push we need to ensure these winding order expectations are consistently maintained at a variety of steps. To that end I'll update the below set of check boxes as things progress:

@springmeyer
Copy link
Contributor

springmeyer commented Apr 28, 2016

This ticket is now resolved thanks to the work of many. Going to close with a short recap:

https://www.mapbox.com/blog/vector-tile-spec-changes/ is a good resource to learn more about what changed.

/cc @rouault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants