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

[FEATURE] Consider Visvalingam-Whyatt algorithm for simplification #1105

Closed
brawer opened this issue Nov 17, 2024 · 2 comments · Fixed by #1109
Closed

[FEATURE] Consider Visvalingam-Whyatt algorithm for simplification #1105

brawer opened this issue Nov 17, 2024 · 2 comments · Fixed by #1109

Comments

@brawer
Copy link

brawer commented Nov 17, 2024

Looking at the Planetiler codebase, it seems that line simplification is currently done with the Douglas-Peucker algorithm. As an alternative, have you considered the Visvalingam-Whyatt algorithm, which may give better-looking results? Tilemaker seems to be using Visvalingam-Whyatt through a C++ library originally made for Tippecanoe inspired by a Go implementation, but there’s also a Java function in JTS. See also here and here for interactive explanations of the algorithm, and the original paper.

@msbarry
Copy link
Contributor

msbarry commented Nov 17, 2024

Yes! That would be a great addition. The one issue with JTS library is that it should use a priority queue but instead does a brute force approach to find the next smallest triangle to remove, and probably has some other inefficiencies. It wouldn't be hard to implement an efficient version in planetiler though. That would also give us flexibility to use the effective area weighting function used on https://mapshaper.org

Beyond that it's mostly just a question of what the API should look like to switch between DP and VW. Could we specify "strategy=retain effective areas" and somehow transform the DP tolerance to a VW effective area limit? Or maybe we just need a more flexible way to configure the simplification algorithm like the GeometryPipeline I describe here... open to suggestions!

See more discussion at #534 and #708

@msbarry
Copy link
Contributor

msbarry commented Nov 25, 2024

Added Visvalingam Whyatt simplification option in #1109. You can opt-into it on a feature by using feature.setSimplifyMethod(SimplifyMethod.RETAIN_EFFECTIVE_AREAS) or feature.setSimplifyMethod(SimplifyMethod.RETAIN_WEIGHTED_EFFECTIVE_AREAS). By default "tolerance" gets squared and used as the minimum area threshold, so you need to tune tolerance up a bit in order to end up with similar output size as DP simplification. The weighted version drops more sharp corners as well.

I'll tackle the GeometryPipeline in a followup PR.

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

Successfully merging a pull request may close this issue.

2 participants