Skip to content

Commit 2ae1391

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

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,13 @@ export class Graph {
902902
}
903903

904904
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]);
905+
// Use the first non-null point (in the matches), rather than just the first point from the raw trace
906+
// This way, we are guaranteed to get a match if the OSRM matching was successful
907+
var firstNonNull = 0, lastNonNull = matches['tracepoints'].length - 1
908+
while (!matches['tracepoints'][firstNonNull] && firstNonNull++);
909+
while (!matches['tracepoints'][lastNonNull] && lastNonNull--);
910+
var startPoint = turfHelpers.point(matches['tracepoints'][firstNonNull]['location']);
911+
var endPoint = turfHelpers.point(matches['tracepoints'][lastNonNull]['location']);
907912

908913

909914
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)