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