Update Pipline

Hamza 2026-03-30 09:21:06 +02:00
parent 30aa84faa0
commit 0c2316a536

@ -113,8 +113,147 @@ Advanced methods use probabilistic models like Hidden Markov Models (HMMs) to gu
# Gap Detections
GPS records are not perfect, and sometimes you get gaps, so when we do Map Matching you may not get one path, we may get multiple paths, if we get multiple paths it means that we have a gap.
Number of gaps is determined by gap_n = Number_Of_Paths - 1
Number of gaps is determined by $n_{\text{gaps}} = n_{\text{paths}} - 1$
### How to handle gaps
Handling gaps is very simple, we take last point from PATH_1, then we take first point from PATH_2, then we run Routing Engine OSRM on these two points. We do this on all gaps.
Handling gaps is very simple, we take last point from PATH_1, then we take first point from PATH_2, then we run Routing Engine OSRM on these two points. We do this to all gaps.
# Rendering
### Polyline
A polyline in GPS/Maps is a compact way of encoding a series of latitude/longitude points (a path or route) into a short string. It widely used to efficiently transmit route data.
Normally, a route looks like this:
```json
[
[36.7525, 3.04197],
[36.7530, 3.04250],
[36.7540, 3.04320]
]
```
That's a lot of data. A polyline encoding compresses it into something like:
```
}_p~F~ps|U_ulLnnqC_mqNvxq`@
```
This reduces size for faster transmission over APIs.
### How Polyline Encoding Works (Simplified)
The algorithm:
1. Multiplies coordinates by 1e5 (to preserve precision).
2. Converts to integers.
3. Stores the difference between points (delta encoding).
4. Applies binary + Base64-like encoding.
### Polyline in JS
In JS we use `@mapbox/polyline` library:
```js
const polyline = require('@mapbox/polyline');
const encoded = '}_p~F~ps|U_ulLnnqC_mqNvxq`@';
const decoded = polyline.decode(encoded);
// Render it in leaflet.
L.polyline(decoded);
```
Or you can decode it manuly
#### Java
```java
import java.util.ArrayList;
import java.util.List;
public class PolylineDecoder {
public static List<double[]> decode(String encoded) {
List<double[]> coordinates = new ArrayList<>();
int index = 0, lat = 0, lng = 0;
while (index < encoded.length()) {
int b, shift = 0, result = 0;
// Decode latitude
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int deltaLat = ((result & 1) != 0)
? ~(result >> 1)
: (result >> 1);
lat += deltaLat;
// Decode longitude
shift = 0;
result = 0;
do {
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int deltaLng = ((result & 1) != 0)
? ~(result >> 1)
: (result >> 1);
lng += deltaLng;
coordinates.add(new double[] {
lat / 1E5,
lng / 1E5
});
}
return coordinates;
}
public static void main(String[] args) {
String encoded = "}_p~F~ps|U_ulLnnqC_mqNvxq`@";
List<double[]> points = decode(encoded);
for (double[] point : points) {
System.out.println(point[0] + ", " + point[1]);
}
}
}
```
#### JavaScript
```js
function decodePolyline(str) {
let index = 0, lat = 0, lng = 0;
const coordinates = [];
while (index < str.length) {
let result = 0, shift = 0, b;
do {
b = str.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
const deltaLat = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += deltaLat;
result = 0;
shift = 0;
do {
b = str.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
const deltaLng = ((result & 1) ? ~(result >> 1) : (result >> 1));
lng += deltaLng;
coordinates.push([lat / 1e5, lng / 1e5]);
}
return coordinates;
}
```