turf icon indicating copy to clipboard operation
turf copied to clipboard

turf.simplify option does not work, always use default 1

Open hoogw opened this issue 3 years ago • 9 comments

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

hoogw avatar Oct 21 '22 16:10 hoogw

Can you add a snippet or the entirety of the input polygon? This needs more information to be something we could debug and fix.

tmcw avatar Nov 21 '22 19:11 tmcw

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"
          ]
        ]
      }
    }
  ]
}

astukanov avatar Dec 24 '22 12:12 astukanov

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

astukanov avatar Dec 24 '22 13:12 astukanov

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

tmcw avatar Dec 26 '22 15:12 tmcw

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 });
 }
}

astukanov avatar Dec 28 '22 20:12 astukanov

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

astukanov avatar Apr 17 '23 20:04 astukanov

Still happens with 7.0.0-alpha.114. Are you planning to fix it?

elsueno avatar Mar 25 '24 23:03 elsueno

Same here, tolerance has absolutely no effect

kaligrafy avatar Sep 20 '24 15:09 kaligrafy

@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:

Screenshot 2024-10-12 at 2 45 59 PM

0.00002 gives the below. I had to zoom right in to see any deviation:

Screenshot 2024-10-12 at 3 16 48 PM

Suspect making the tolerance value smaller will greatly improve the situation. Not sure why 0.00002 didn't work previously though.

smallsaucepan avatar Oct 12 '24 04:10 smallsaucepan

Closing as this seems to be an issue with the tolerance value passed.

smallsaucepan avatar Dec 05 '24 09:12 smallsaucepan