mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
18 lines
569 B
JavaScript
18 lines
569 B
JavaScript
const analyzeGPS = async (readings, boundary) => {
|
|
const { booleanPointInPolygon, lineString, length } = await import('https://cdn.jsdelivr.net/npm/@turf/turf/+esm');
|
|
|
|
const sortedCoords = readings
|
|
.filter(({ loc }) => booleanPointInPolygon(loc, boundary, { ignoreBoundary: true }))
|
|
.sort((a, b) => a.ts - b.ts)
|
|
.map(({ loc }) => loc);
|
|
|
|
if (sortedCoords.length < 2) {
|
|
return 0;
|
|
}
|
|
|
|
const path = lineString(sortedCoords);
|
|
const dist = length(path, { units: 'kilometers' });
|
|
|
|
return Math.round(dist * 1e2) / 1e2;
|
|
};
|
|
export default analyzeGPS; |