Skip to content

Commit

Permalink
implement Trackpoint distance threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
derGraph committed Sep 5, 2024
1 parent 6aa4370 commit a5b85b2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/server/simplifyGps.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit a5b85b2

Please sign in to comment.