mapbox / mapnik-vector-tile

Mapnik implemention of Mapbox Vector Tile specification
BSD 3-Clause "New" or "Revised" License
553 stars 117 forks source link

Polygon winding order & holes vs outer rings #59

Closed mourner closed 8 years ago

mourner commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

@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 commented 10 years ago

:+1: for having a specified winding order.

pnorman commented 10 years ago

@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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Another approach is to just split MultiPolygons into several Polygon features. This is how Mapzen solved the issue: https://github.com/mapzen/mapbox-vector-tile/issues/4

bcamper commented 9 years ago

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

springmeyer commented 9 years ago

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

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

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 commented 8 years ago

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