geojson-tidy icon indicating copy to clipboard operation
geojson-tidy copied to clipboard

Tidying leads to significant losses when applied on a dense track or params are chosen too large

Open RobTS opened this issue 7 years ago • 1 comments

The reason behind it is that the algorithm only compares the current point to the next one, not to the last tidied one.

For simplification, I therefore suggest using simplify-geojson

RobTS avatar May 30 '17 08:05 RobTS

I've looked at the code and this was my initial reaction too.

If you have data points collected at 4 seconds, then only the first and last data points are added.

The loop should not use deleted points at the 'current' (i'th) point, but instead use the last kept data point.

Something like:

const keptPoints = dataPoints.reduce((acc, dataPoint, i) => {
  // Always add first data point
  if (i === 0) return acc.concat(dataPoint)
  // Always add last data point
  if (i === dataPoints.length-1) return acc.concat(dataPoint)

  const lastKeptPoint = acc.slice(-1)
  return shouldKeep(lastKeptPoint, dataPoint)
    ? acc.concat(dataPoint)
    : acc
}, [])

ZephD avatar Apr 12 '19 14:04 ZephD