turf.simplify option does not work, always use default 1
Please provide the following when reporting an issue:
- [ ] The version of Turf you are using, and any other relevant versions. 6.5.0
- [ ] GeoJSON data as a gist file or geojson.io (filename extension must be
.geojson). - [ ] Snippet of source code or for complex examples use jsfiddle.
var turfjs_simplify_options = {
tolerance: 0.01, // DOUGLAS-PEUCKER ALGORITHM https://cartography-playground.gitlab.io/playgrounds/douglas-peucker-algorithm/
highQuality: true
//mutate: false
};
var _geojson_clicked_simplify = turf.simplify(_geojson_clicked, turfjs_simplify_options);
no matter what tolerence I use, 0.01 or 1 I always get same result as 1,
reduce to 3 vertex for 2500 vertex polygon.
option, tolerence does not hornered, during simplify process
Can you add a snippet or the entirety of the input polygon? This needs more information to be something we could debug and fix.
I am experiencing similar behavior, where the attached LineString geojson is being simplified to 2 points, start and end, regardles the provided tolerance. Also using version 6.5.0 Also tried to utilize simplify-js where I experienced the same behavior. simplifies-to-two-points.zip
Tried to remove altitude information, which also did not work. Here the result:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"lap": 1,
}
"geometry": {
"type": "LineString",
"coordinates": [
[
"8.641456933692098",
"47.45174003764987"
],
[
"8.692795420065522",
"47.40378515794873"
]
]
}
}
]
}
Further, this might be more of a feature request, but when simplifying: could it make sense to reduce the lat and lng precision a bit? I imagine it saving lots of data in certain scenarios without introducing any notable representation issues
That's available as turf/truncate http://turfjs.org/docs/#truncate - it's best to keep the two as separate functions, but you can just run one after the other if you want to both simplify & truncate.
To debug this we need:
- Input data
- And the code you're using
HI @tmcw thanks a lot for the hint, wasn't aware about the function. Makes perfect sense to me as well to keep it separate.
Hope the data in the message above is helpful for the solution to the original question. Let me know if I can help any further.
I am utilizing the raw es6 import from the @turf/turf lib, where the passed data is the above provided FeatureCollection, the result as well.
OS: Ubuntu 22.04.1 LTS Browser: Chrome, Version 108.0.5359.98 (Official Build) (64-bit) Turf: 6.5.0 Angular: 14.1.0
I tried to put tolerance values between 200 and 0.00002 all yield the same result. Here is an example snippet:
import { simplify, FeatureCollection } from '@turf/turf';
export class Simplify {
static geoJson(data: FeatureCollection): FeatureCollection {
return simplify(data, { tolerance: 0.08 });
}
}
I can confirm that the same behavior is happening with node.js and express backend. Node version 18.10. OS and Turf verison same as above
Still happens with 7.0.0-alpha.114. Are you planning to fix it?
Same here, tolerance has absolutely no effect
@kaligrafy @elsueno @astukanov @hoogw Found the below comment on a similar issue in the simplify-js repo (which Turf uses):
This is because your tolerance is too high. Try something like 0.00001
Took @astukanov's example and ran it with a tolerance of 0.001 and got the resulting red line:
0.00002 gives the below. I had to zoom right in to see any deviation:
Suspect making the tolerance value smaller will greatly improve the situation. Not sure why 0.00002 didn't work previously though.
Closing as this seems to be an issue with the tolerance value passed.