-
Notifications
You must be signed in to change notification settings - Fork 953
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
@turf/simplify gets stuck in an infinite loop on certain geometries #1788
Comments
Thanks for the detailed writeup @senritsu |
Haven't heavily tested yet, however we ran into this issue in our codebase and swapping for https://github.com/maxogden/simplify-geojson |
Is this still an issue with |
Thanks for the tip @mbullington - I believe it's still an issue. Would be interestenig to run a benchmark against simplify-geojson and the current turf (which is a wrapper around simplify.js) |
Got this issue today, the problem is still here. From my point of view simplify-geojson (https://github.com/maxogden/simplify-geojson) is just very tiny wrapper around simplify-geometry (https://github.com/seabre/simplify-geometry) and does not really provide any usefull code. simplify-geometry is an alternative to simplify-js. So if turfjs wants to switch I would switch directly to simplify-geometry (simplify-geojson does not provide anything). But the real question is what the code should produce when non-valid linear ring is returned from simplify-js/simplify-geometry and from my point of view it would be much better just to return an invalid polygon, let the user of the library handle it. |
I was able to also reproduce this using the following geometry: {
type: 'Feature',
properties: {},
geometry: { type: 'Polygon', coordinates: [
[
[ 4.0881641, 6.8121605 ],
[ 4.0881639, 6.8121607 ],
[ 4.0881638, 6.8121608 ],
[ 4.0881641, 6.8121605 ]
]
] }
} |
I was able to reproduce this issue using the following code
|
Any updates? |
same for me, unfortunately! Maybe MultiPolygons are the issue? At least for me it loops on a MultiPolygon too . @rowanwins could you take a look? |
Suspect this might be related to issues in cleanCoords. Just waiting for a couple of other PRs to merge first. |
Under certain circumstances the
turf/simplify
function never terminates.The issue appeared with a geometry resulting from a union of 2 adjacent geometries that left a small gap in between the original polygons.
Full geometry on geojson.io and the problematic ring by itself on geojson.io
This fiddle reproduces the issue using only the problematic ring itself, not the full geometry.
The freeze occurs in the commented part of this function here in
simplify/index.js
For the given example geometry the
simplifyJS
call returns an invalid ring (with only 3 points:[[11.662180661499999, 50.1081498005], [11.662192661499999, 50.108041800500004], [11.662180661499999, 50.1081498005]]
) no matter how small the tolerance gets. This means the loop never terminates, and the page hangs.The text was updated successfully, but these errors were encountered: