Skip to content

Commit 8843c91

Browse files
committed
ART-1434: shst matching robustness improvements
1 parent 9ce6256 commit 8843c91

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/commands/match.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ async function matchLines(outFile, params, lines, flags) {
872872
var gisRef:SharedStreetsReference = forwardReference(line);
873873

874874
matchForward = await matcher.matchGeom(line);
875-
if(matchForward && matchForward.score < matcher.searchRadius * 2) {
875+
if(matchForward) {
876876
matchForwardSegments = getMatchedSegments(matchForward, gisRef);
877877
}
878878
}
@@ -885,7 +885,7 @@ async function matchLines(outFile, params, lines, flags) {
885885

886886
var reversedLine = <turfHelpers.Feature<turfHelpers.LineString>>reverseLineString(line);
887887
matchBackward = await matcher.matchGeom(reversedLine);
888-
if(matchBackward && matchBackward.score < matcher.searchRadius * 2) {
888+
if(matchBackward) {
889889
matchBackwardSegments = getMatchedSegments(matchBackward, gisRef);
890890
}
891891
}

src/graph.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,17 +842,23 @@ export class Graph {
842842
try {
843843
var matches = await new Promise((resolve, reject) => {
844844
this.osrm.match(hmmOptions, function(err, response) {
845-
if (err)
845+
if (err) {
846+
console.log("got error")
846847
reject(err);
847-
else
848+
}
849+
else {
850+
console.log("Succesful match")
848851
resolve(response)
852+
}
849853
});
850854
});
851855

852856
var visitedEdges:Set<string> = new Set();
853857
var visitedEdgeList:string[] = [];
854858

855859
if(matches['matchings'] && matches['matchings'].length > 0) {
860+
//console.log(JSON.stringify(feature.geometry, null, 4))
861+
//console.log(JSON.stringify(matches['matchings'][0]['geometry'], null, 4))
856862

857863
var match = matches['matchings'][0];
858864
if(0 < match.confidence ) {
@@ -902,8 +908,13 @@ export class Graph {
902908
}
903909

904910
if(visitedEdgeList.length > 0) {
905-
var startPoint = turfHelpers.point(feature.geometry.coordinates[0]);
906-
var endPoint = turfHelpers.point(feature.geometry.coordinates[feature.geometry.coordinates.length - 1]);
911+
// Use the first non-null point (in the matches), rather than just the first point from the raw trace
912+
// This way, we are guaranteed to get a match if the OSRM matching was successful
913+
var firstNonNull = 0, lastNonNull = matches['tracepoints'].length - 1
914+
while (!matches['tracepoints'][firstNonNull] && firstNonNull++);
915+
while (!matches['tracepoints'][lastNonNull] && lastNonNull--);
916+
var startPoint = turfHelpers.point(matches['tracepoints'][firstNonNull]['location']);
917+
var endPoint = turfHelpers.point(matches['tracepoints'][lastNonNull]['location']);
907918

908919

909920
var startCandidate:PointCandidate = await this.getPointCandidateFromRefId(startPoint, visitedEdgeList[0], null);

src/tiles.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ export async function getTilesForId(id:string) {
3838
}
3939

4040
export function getTileIdsForPolygon(polygon:turfHelpers.Feature<turfHelpers.Polygon>, buffer:number=0):string[] {
41-
42-
var polyBound = bbox(polygon)
43-
44-
var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'});
45-
var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'});
46-
let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]];
47-
48-
return getTileIdsForBounds(bounds, false);
41+
if (polygon === null) {
42+
return [];
43+
} else {
44+
var polyBound = bbox(polygon)
45+
46+
var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'});
47+
var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'});
48+
let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]];
49+
50+
return getTileIdsForBounds(bounds, false);
51+
}
4952

5053
}
5154

0 commit comments

Comments
 (0)