mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
14 lines
490 B
JavaScript
14 lines
490 B
JavaScript
const analyzeGPS = async (readings, boundary) => {
|
|
const { booleanPointInPolygon, point, lineString, length } = await import('https://esm.sh/@turf/turf');
|
|
|
|
const coords = readings
|
|
.filter(({ loc }) => booleanPointInPolygon(point(loc), boundary))
|
|
.sort((a, b) => a.ts - b.ts)
|
|
.map(({ loc }) => loc);
|
|
|
|
if (coords.length < 2) return 0;
|
|
|
|
const total = length(lineString(coords), { units: 'kilometers' });
|
|
return Math.round(total * 100) / 100;
|
|
};
|
|
export default analyzeGPS; |