geojson-tidy
geojson-tidy copied to clipboard
Tidying leads to significant losses when applied on a dense track or params are chosen too large
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
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
}, [])