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