Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -885,7 +885,7 @@ async function matchLines(outFile, params, lines, flags) {

var reversedLine = <turfHelpers.Feature<turfHelpers.LineString>>reverseLineString(line);
matchBackward = await matcher.matchGeom(reversedLine);
if(matchBackward && matchBackward.score < matcher.searchRadius * 2) {
if(matchBackward) {
matchBackwardSegments = getMatchedSegments(matchBackward, gisRef);
}
}
Expand Down
83 changes: 43 additions & 40 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,55 +855,58 @@ 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<number> = 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<number> = 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) {
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);
Expand Down
19 changes: 11 additions & 8 deletions src/tiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ export async function getTilesForId(id:string) {
}

export function getTileIdsForPolygon(polygon:turfHelpers.Feature<turfHelpers.Polygon>, 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);
}

}

Expand Down