From a5b85b2e8d1d2a4fcda54e60c0cea3eff661614e Mon Sep 17 00:00:00 2001 From: derGraph Date: Thu, 5 Sep 2024 20:34:10 +0200 Subject: [PATCH] implement Trackpoint distance threshold --- src/lib/server/simplifyGps.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/server/simplifyGps.ts b/src/lib/server/simplifyGps.ts index 23f0546..8412fc4 100644 --- a/src/lib/server/simplifyGps.ts +++ b/src/lib/server/simplifyGps.ts @@ -1,6 +1,6 @@ import { prisma } from '$lib/server/prisma'; import type { Decimal } from '@prisma/client/runtime/library'; -import { getDistanceFromLine } from 'geolib'; +import { getDistance, getDistanceFromLine } from 'geolib'; export async function simplifyGps(trip: string, amount: number) { let totalAmount = 0; @@ -35,8 +35,13 @@ export async function simplifyGps(trip: string, amount: number) { if ((inputData[i].heading != null, inputData[i - 1].heading != null)) { turnRate = Number(inputData[i - 1].heading) - Number(inputData[i].heading); } + + let distFromLastPoint = getDistance( + { lat: Number(inputData[i].lat), lng: Number(inputData[i].long)} , + { lat: Number(lastPoint.lat), lng: Number(lastPoint.long) } + ); - if (crosstrackError < 5 && Math.abs(turnRate) < 20) { + if (crosstrackError < 8 && Math.abs(turnRate) < 20 && distFromLastPoint > 50) { // Delete Datapoint await prisma.datapoint.update({ where: { id: inputData[i].id },