From 2ae1391ae7876080f650247913aa894a1440bd85 Mon Sep 17 00:00:00 2001 From: edmabon Date: Fri, 12 Jan 2024 11:57:21 +0000 Subject: [PATCH 1/2] ART-1434: shst matching robustness improvements --- src/commands/match.ts | 4 ++-- src/graph.ts | 9 +++++++-- src/tiles.ts | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/commands/match.ts b/src/commands/match.ts index cca9db5..5a871cc 100644 --- a/src/commands/match.ts +++ b/src/commands/match.ts @@ -872,7 +872,7 @@ async function matchLines(outFile, params, lines, flags) { var gisRef:SharedStreetsReference = forwardReference(line); matchForward = await matcher.matchGeom(line); - if(matchForward && matchForward.score < matcher.searchRadius * 2) { + if(matchForward) { matchForwardSegments = getMatchedSegments(matchForward, gisRef); } } @@ -885,7 +885,7 @@ async function matchLines(outFile, params, lines, flags) { var reversedLine = >reverseLineString(line); matchBackward = await matcher.matchGeom(reversedLine); - if(matchBackward && matchBackward.score < matcher.searchRadius * 2) { + if(matchBackward) { matchBackwardSegments = getMatchedSegments(matchBackward, gisRef); } } diff --git a/src/graph.ts b/src/graph.ts index f6626b8..7962e52 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -902,8 +902,13 @@ export class Graph { } if(visitedEdgeList.length > 0) { - var startPoint = turfHelpers.point(feature.geometry.coordinates[0]); - var endPoint = turfHelpers.point(feature.geometry.coordinates[feature.geometry.coordinates.length - 1]); + // Use the first non-null point (in the matches), rather than just the first point from the raw trace + // This way, we are guaranteed to get a match if the OSRM matching was successful + var firstNonNull = 0, lastNonNull = matches['tracepoints'].length - 1 + while (!matches['tracepoints'][firstNonNull] && firstNonNull++); + while (!matches['tracepoints'][lastNonNull] && lastNonNull--); + var startPoint = turfHelpers.point(matches['tracepoints'][firstNonNull]['location']); + var endPoint = turfHelpers.point(matches['tracepoints'][lastNonNull]['location']); var startCandidate:PointCandidate = await this.getPointCandidateFromRefId(startPoint, visitedEdgeList[0], null); diff --git a/src/tiles.ts b/src/tiles.ts index 04e9c3c..b04d4a3 100644 --- a/src/tiles.ts +++ b/src/tiles.ts @@ -38,14 +38,17 @@ export async function getTilesForId(id:string) { } export function getTileIdsForPolygon(polygon:turfHelpers.Feature, buffer:number=0):string[] { - - var polyBound = bbox(polygon) - - var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'}); - var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'}); - let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]]; - - return getTileIdsForBounds(bounds, false); + if (polygon === null) { + return []; + } else { + var polyBound = bbox(polygon) + + var nwPoint = destination([polyBound[0],polyBound[1]], buffer, 315, {'units':'meters'}); + var sePoint = destination([polyBound[2],polyBound[3]], buffer, 135, {'units':'meters'}); + let bounds = [nwPoint.geometry.coordinates[0], nwPoint.geometry.coordinates[1], sePoint.geometry.coordinates[0], sePoint.geometry.coordinates[1]]; + + return getTileIdsForBounds(bounds, false); + } } From 010bfb5951bc953d3235261e2d578323b036467d Mon Sep 17 00:00:00 2001 From: edmabon Date: Fri, 12 Jan 2024 13:33:46 +0000 Subject: [PATCH 2/2] ART-1434: shst match at all confidence --- src/graph.ts | 74 +++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/src/graph.ts b/src/graph.ts index 7962e52..01f0aa1 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -855,50 +855,48 @@ export class Graph { if(matches['matchings'] && matches['matchings'].length > 0) { var match = matches['matchings'][0]; - if(0 < match.confidence ) { - // this is kind of convoluted due to the sparse info returned in the OSRM annotations... - // write out sequence of nodes and edges as emitted from walking OSRM-returned nodes - // finding the actual posistion and directionality of the OSRM-edge within the ShSt graph - // edge means that we have to snap start/end points in the OSRM geom - - //console.log(JSON.stringify(match.geometry)); - - var edgeCandidates; - var nodes:number[] = []; - var visitedNodes:Set = new Set(); - // ooof this is brutual -- need to unpack legs and reduce list... - for(var leg of match['legs']) { - //console.log(leg['annotation']['nodes']) - for(var n of leg['annotation']['nodes']){ - if(!visitedNodes.has(n) || nodes.length == 0) - nodes.push(n); - - visitedNodes.add(n); - } + // this is kind of convoluted due to the sparse info returned in the OSRM annotations... + // write out sequence of nodes and edges as emitted from walking OSRM-returned nodes + // finding the actual posistion and directionality of the OSRM-edge within the ShSt graph + // edge means that we have to snap start/end points in the OSRM geom + + //console.log(JSON.stringify(match.geometry)); + + var edgeCandidates; + var nodes:number[] = []; + var visitedNodes:Set = new Set(); + // ooof this is brutual -- need to unpack legs and reduce list... + for(var leg of match['legs']) { + //console.log(leg['annotation']['nodes']) + for(var n of leg['annotation']['nodes']){ + if(!visitedNodes.has(n) || nodes.length == 0) + nodes.push(n); + + visitedNodes.add(n); } + } - // then group node pairs into unique edges... - var previousNode = null; - for(var nodeId of nodes) { - if(await this.db.has('node:' + nodeId)) { - - if(previousNode) { - if(await this.db.has('node-pair:' + nodeId + '-' + previousNode)) { - var edges = JSON.parse(await this.db.get('node-pair:' + nodeId + '-' + previousNode)); - for(var edge of edges) { - - if(!visitedEdges.has(edge)) - visitedEdgeList.push(edge); - - visitedEdges.add(edge); - } + // then group node pairs into unique edges... + var previousNode = null; + for(var nodeId of nodes) { + if(await this.db.has('node:' + nodeId)) { + + if(previousNode) { + if(await this.db.has('node-pair:' + nodeId + '-' + previousNode)) { + var edges = JSON.parse(await this.db.get('node-pair:' + nodeId + '-' + previousNode)); + for(var edge of edges) { + + if(!visitedEdges.has(edge)) + visitedEdgeList.push(edge); + + visitedEdges.add(edge); } } - previousNode = nodeId; } - } - } + previousNode = nodeId; + } + } } if(visitedEdgeList.length > 0) {