Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.2k stars 934 forks source link

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

Open hoogw opened 1 year ago

hoogw commented 1 year ago

Please provide the following when reporting an issue:

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

tmcw commented 1 year ago

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

astukanov commented 1 year ago

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 commented 1 year ago

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

tmcw commented 1 year ago

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:

astukanov commented 1 year ago

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 commented 1 year ago

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

elsueno commented 5 months ago

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