-
Notifications
You must be signed in to change notification settings - Fork 10
[BUG] Invalid polygons/closed linestrings when smoothing is enabled #18
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
Comments
I'm a but surprised, are you getting this result with version 0.13? The spikes that are created without smooth don't normally overflow to make self intersecting polygons but instead give the following result (yellow with smooth option and brown without smooth option): I used to check results of contour-isobands with some validity tests (https://github.com/mthh/geo-validity-check), maybe the same should be done for this crate. EDIT: I just saw your edit with the threshold your are using and I can reproduce the bug. |
Any idea what the problem is here? |
I've clipped your raster onto the problem area and I tried to generate the same contours with d3-contour and with the previous versions of this crate (using the threshold value of See the following screenshots: d3-contour / contour-rs 0.12.1, no smoothing contour-rs 0.13.0, no smoothing d3-contour / contour-rs 0.12.1, with smoothing contour-rs 0.13.0, with smoothing I'm currently investigating the exact cause. |
The culprit change seems to be b32d16b. |
Oof yeah that seems like a mistake with the |
I've tinkered a bit with the code of this function, notably using f64 for intermediate values. With something like Anyway, feel free to propose a fix you're confident with ;)
Well, now we have a test case to avoid this kind of regression in the future (if you allow me to take a small piece of your raster to include in the tests? otherwise I'll manually create values to reproduce it). |
That solution makes sense, maybe #17 could be an opportunity to explore alternative ways later 🤔 |
Alright, I will push a fix and publish a new version.
Thanks! |
Thanks for the data, i took exactly 10x10 values on the problematic area, non-georeferenced, and I modified a bit the values before including them in a test case. |
When smoothing is enabled,

ContourBuilder::contours
and probablyContourBuilder::isobands
can end up generating invalid (self-intersecting) polygons.E.g.:
Without smoothing:
With smoothing:

Overlaid:

I think that this is invalid according to geo-types, and many other geometry standards don't allow this either.
Specifically,
And,
@mthh You can find the areas the screenshots are from in the dataset I sent you recently at about
557500, 5932680
in its CRS, contours were generated at elevation -5.The text was updated successfully, but these errors were encountered: