wdtinc / mapbox-vector-tile-java

Java Mapbox Vector Tile Library for Encoding/Decoding
Apache License 2.0
147 stars 73 forks source link

Issues with parsing polygons #15

Closed boldtrn closed 6 years ago

boldtrn commented 6 years ago

I just started test your library and saw there seems to be an issue with parsing Polygons.

When I try to read a polygon the outer and inner rings seem to be switched and many polygons are not accepted because the library thinks that the polygon has no outer ring. The problem seems to be created in MvtReader#classifyRings when running CGAlgorithms.signedArea(r.getCoordinates()).

For example have a look at this tile. The first polygon is a water polygon that has no inner, just an outer. Same thing happens for Mapzen mvt, they also provide a nice geojson debugging version of the tile, where you can see that it's just a big simple polygon.

boldtrn commented 6 years ago

BTW: The code at this point actually looks correct. Maybe the coordinates get mixed up before the actual call or maybe there is a bug in CGAlgorithms?

ShibaBandit commented 6 years ago

Hey @boldtrn thank you for posting the issue. I'm looking at the android legacy pull request tonight but I should be able to get a look at this one some time tomorrow.

ShibaBandit commented 6 years ago

@boldtrn By any chance did you try

// Allow negative-area exterior rings with classifier
JtsMvt jtsMvt = MvtReader.loadMvt(
        Paths.get("path/to/your.mvt"),
        geomFactory,
        new TagKeyValueMapConverter(),
        MvtReader.RING_CLASSIFIER_V1);

? (Using the RING_CLASSIFIER_V1) ?

boldtrn commented 6 years ago

Thanks, using MvtReader.RING_CLASSIFIER_V1 fixes my issue :). I missed that in the docu. Sorry for creating an issue.

ShibaBandit commented 6 years ago

No problem at all. I want to do a pass on the doc's to make some things a bit more clear. RING_CLASSIFIER_V1 mimics that mapbox code.

boldtrn commented 6 years ago

RING_CLASSIFIER_V1 mimics that mapbox code.

Ah ok, I am not familiar with the Mapbox code. Thanks for the explanation.