Skip to content

Commit

Permalink
Resolves #1997 - Filter out GPS jamming in Israel
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed May 7, 2024
1 parent 98359d4 commit 00e8e1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export class RecordedRouteService {
}

private isValid(test: LatLngAltTime, position: GeolocationPosition): string {
const distance = SpatialService.getDistanceInMeters(test, GeoLocationService.positionToLatLngTime(position));
const positionLatLng = GeoLocationService.positionToLatLngTime(position);
const distance = SpatialService.getDistanceInMeters(test, positionLatLng);
const timeDifference = Math.abs(position.timestamp - new Date(test.timestamp).getTime()) / 1000;
if (timeDifference === 0) {
return "Time difference is 0";
Expand All @@ -195,6 +196,9 @@ export class RecordedRouteService {
if (position.coords.accuracy > RecordedRouteService.MIN_ACCURACY) {
return "Accuracy too low: " + position.coords.accuracy;
}
if (SpatialService.isJammingTarget(positionLatLng)) {
return "Position is inside a jamming target";
}
return "";
}
}
23 changes: 16 additions & 7 deletions IsraelHiking.Web/src/application/services/spatial.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@angular/core";
import { Map, LngLatBounds, LngLatLike } from "maplibre-gl";
import { lineString, featureCollection, point, Units } from "@turf/helpers";
import { lineString, featureCollection, point, Units, BBox } from "@turf/helpers";
import simplify from "@turf/simplify";
import distance from "@turf/distance";
import center from "@turf/center";
Expand Down Expand Up @@ -139,16 +139,14 @@ export class SpatialService {
if (!lineToCheck.bbox) {
lineToCheck.bbox = bbox(lineToCheck);
}
if (start[0] >= lineToCheck.bbox[0] && start[0] <= lineToCheck.bbox[2] &&
start[1] >= lineToCheck.bbox[1] && start[1] <= lineToCheck.bbox[3]) {
if (SpatialService.insideBbox(start, lineToCheck.bbox)) {
const nearestPoint = nearestPointOnLine(lineToCheck, start);
if (nearestPoint.properties.dist < 1e-5) {
lineToCheck.geometry.coordinates.splice(nearestPoint.properties.index + 1, 0, nearestPoint.geometry.coordinates);
continue;
}
}
if (end[0] >= lineToCheck.bbox[0] && end[0] <= lineToCheck.bbox[2] &&
end[1] >= lineToCheck.bbox[1] && end[1] <= lineToCheck.bbox[3]) {
if (SpatialService.insideBbox(end, lineToCheck.bbox)) {
const nearestPoint = nearestPointOnLine(lineToCheck, end);
if (nearestPoint.properties.dist < 1e-5) {
lineToCheck.geometry.coordinates.splice(nearestPoint.properties.index + 1, 0, nearestPoint.geometry.coordinates);
Expand Down Expand Up @@ -355,8 +353,19 @@ export class SpatialService {
};
}

public static insideBbox(position: GeoJSON.Position, bbox: BBox): boolean {
return position[0] >= bbox[0] && position[0] <= bbox[2] &&
position[1] >= bbox[1] && position[1] <= bbox[3];
}

public static isInIsrael(latlng: LatLngAlt): boolean {
return latlng.lat > 29.37711 && latlng.lat < 33.35091 &&
latlng.lng > 34.07929 && latlng.lng < 35.91531;
const position = SpatialService.toCoordinate(latlng);
return SpatialService.insideBbox(position, [34.07929, 29.37711, 35.91531, 33.35091]);
}

public static isJammingTarget(latlng: LatLngAlt): boolean {
const position = SpatialService.toCoordinate(latlng);
return SpatialService.insideBbox(position, [35.48, 33.811, 35.50, 33.823]) ||
SpatialService.insideBbox(position, [31.350, 30.0817, 31.355, 30.0860]);
}
}

2 comments on commit 00e8e1e

@zstadler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like jamming is not blocked.

For example, New location BGLocation[gps 33.818169,35.490792 does not produce "Position is inside a jamming target" although
33.811 < 33.818169 < 33.823 and
35.48 < 35.490792 < 35.50

Perhaps the code mixed lat and lon!?

2024-05-17 10:14:03 | DEBUG | Received MSG_ON_LOCATION
2024-05-17 10:14:03 | DEBUG | New location BGLocation[gps 33.818260,35.490789 id=null acc=6 t=1715930044966 et=+2d11h44m56s705ms alt=181.3424072265625 vel=0.39 bear=238.4 {Bundle[mParcelledData.dataSize=96]} locprov=2]
2024-05-17 10:14:03 | DEBUG | Location change: Location[gps 33.82****,35.49**** hAcc=5.908667 et=+2d11h44m56s705ms alt=181.3424072265625 vAcc=4.8218284 vel=0.39 sAcc=0.8261961 bear=238.4 bAcc=28.620216 {Bundle[mParcelledData.dataSize=96]}]
2024-05-17 10:14:02 | DEBUG | Received MSG_ON_LOCATION
2024-05-17 10:14:02 | DEBUG | New location BGLocation[gps 33.818169,35.490792 id=null acc=19 t=1715930043902 et=+2d11h44m55s706ms alt=219.894287109375 vel=1.35 bear=238.4 {Bundle[mParcelledData.dataSize=96]} locprov=2]
2024-05-17 10:14:02 | DEBUG | Location change: Location[gps 33.82****,35.49**** hAcc=18.554583 et=+2d11h44m55s706ms alt=219.894287109375 vAcc=16.937239 vel=1.35 sAcc=1.1182575 bear=238.4 bAcc=41.431858 {Bundle[mParcelledData.dataSize=96]}]
2024-05-17 10:13:26 | DEBUG | Received MSG_ON_SERVICE_STARTED

@HarelM
Copy link
Member Author

@HarelM HarelM commented on 00e8e1e May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the background plugin log.
From the app log.txt:

2024-05-17 10:17:13 | DEBUG | [GeoLocation] Received position: {"lat":32.48727931,"lng":35.04797004,"alt":75.13299560546875,"timestamp":"2024-05-17T07:17:14.857Z"}
2024-05-17 10:14:38 |  INFO | [Record] Starting recording
2024-05-17 10:14:36 | DEBUG | [GeoLocation] Received position: {"lat":33.81825023,"lng":35.4907784,"alt":184.94921875,"timestamp":"2024-05-17T07:14:38.000Z"}
2024-05-17 10:14:34 | DEBUG | [GeoLocation] Received position: {"lat":33.81826973,"lng":35.49072923,"alt":186.803955078125,"timestamp":"2024-05-17T07:14:36.000Z"}
2024-05-17 10:14:34 |  INFO | [POIs] Connection status changed to: true
2024-05-17 10:14:34 |  INFO | [POIs] Upload queue changed and now it is empty
2024-05-17 10:14:34 |  INFO | [POIs] Finished getting pois from database and adding to memory: 38587
2024-05-17 10:14:34 |  INFO | [POIs] Unsubscribing from move end, pois are from database now
2024-05-17 10:14:34 | DEBUG | [Database] Finished getting pois for clustering in chunks: 38587
2024-05-17 10:14:03 | DEBUG | [GeoLocation] Received position: {"lat":33.81826041,"lng":35.49078859,"alt":181.3424072265625,"timestamp":"2024-05-17T07:14:04.966Z"}
2024-05-17 10:14:02 | DEBUG | [GeoLocation] Received position: {"lat":33.81816864,"lng":35.49079226,"alt":219.894287109375,"timestamp":"2024-05-17T07:14:03.902Z"}

These are not part of a recording as far as I can see as the recording starts afterwards, only the recoding points are validated against the jamming target (as this was the easiest solution).

Please sign in to comment.