mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
462 stars 150 forks source link

Add ability to disable Douglas-Peucker simplification algorithm in GeoJSONSource #1101

Open merindorium opened 2 years ago

merindorium commented 2 years ago

New Feature

Add ability to disable Douglas-Peucker simplification algorithm in GeoJSONSource.

Why

We are trying to draw high precision (< 50cm) geospatial geometry (e.g. lines, arcs, splines) but Douglas-Peucker algorithm simplifies it to lines.

Screenshot 2022-02-08 at 16 34 03

We've found out that the tolerance parameter of GeoJSONSource drives this algorithm. Setting this parameter to 0 fixes the issue a little bit, but the final geometry looks noisy. The algorithm still applies some simplification.

Screenshot 2022-02-08 at 16 27 36

It's crucial for our app to draw precise geometry. That's why it would be very handy to have the ability to disable the simplification algorithm.

ZiZasaurus commented 2 years ago

@merindorium thank you for reporting this. To bette assist you, can you please provide a sample geojson, as well as a screenshot of how you expect the geometry to appear?

merindorium commented 2 years ago

Hi @ZiZasaurus, thanks for the quick response!

GeoJSON - geometry.txt

It's created using LineString(coordinates).bezier() function.

Setup details #### LineString control points: ``` [ (latitude: 47.59151408823743, longitude: 3.1193280531209666), (latitude: 47.59151563564072, longitude: 3.1193279436751027), (latitude: 47.591515695713724, longitude: 3.119329588366611), (latitude: 47.59151433547524, longitude: 3.119329773882612), (latitude: 47.59151437217821, longitude: 3.119331780059241), (latitude: 47.59151599673862, longitude: 3.1193315986023435) ] ``` #### GeoJSONSource settings ```swift var source = GeoJSONSource() source.tolerance = 0 ``` #### LineLayer settings ```swift var lineLayer = LineLayer(id: "line") lineLayer.lineColor = .constant(StyleColor(.red)) lineLayer.lineWidth = .constant(5) ```

The result of this setup is:

Screenshot 2022-02-09 at 13 49 38

Expected result

Screenshot 2022-02-09 at 13 45 33

It's made using Metal and CustomLayerHost from https://docs.mapbox.com/ios/maps/guides/migrate-to-v10/#custom-rendered-layers

merindorium commented 2 years ago

Hi @ZiZasaurus, is there any updates regarding this topic or maybe a workaround?

ArtemBurmistrov commented 2 years ago

@ZiZasaurus, is there any new developments?

ArtemBurmistrov commented 2 years ago

Hi @ZiZasaurus So I've looked at the public sources and found this algorithm in the Turf Swift package. But it looks like it is not used. At least the breakpoint doesn't work and disabling the simplification doesn't work either. Why tho? Is there another implementation in the private part? Is there any way you could expose more arguments to the public API? Or am I missing something here and we already could modify the simplification behavior?

ArtemBurmistrov commented 2 years ago

@ZiZasaurus, is there any update regarding this issue?