Skip to content

Commit

Permalink
Check that returned routes are free of gaps (#138)
Browse files Browse the repository at this point in the history
* return source and target nodes

* check for gaps in returned route
  • Loading branch information
Nate-Wessel authored Jul 24, 2024
1 parent 46a4215 commit 65c6a59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions backend/app/get_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
results.seq,
seg_lookup.segment_id,
ST_AsGeoJSON(streets.geom) AS geojson,
ST_Length( ST_Transform(streets.geom,2952) ) AS length_m
ST_Length( ST_Transform(streets.geom,2952) ) AS length_m,
streets.source,
streets.target
FROM results
JOIN here.routing_streets_22_2 AS streets USING ( link_dir )
JOIN here_gis.streets_att_22_2 AS attr
Expand Down Expand Up @@ -45,8 +47,10 @@ def get_links(from_node_id, to_node_id):
'sequence': seq,
'segment_id': segment_id,
'geometry': json.loads(geojson),
'length_m': length_m
} for link_dir, st_name, seq, segment_id, geojson, length_m in cursor.fetchall()
'length_m': length_m,
'source': source,
'target': target
} for link_dir, st_name, seq, segment_id, geojson, length_m, source, target in cursor.fetchall()
]

connection.close()
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/corridor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ export class Corridor extends Factor {
super(dataContext)
}
get isComplete(){
return this.intersections.length > 1 && this.links.length > 0
return this.intersections.length > 1 && this.routeIsValid
}
get routeIsValid(){
if(this.links.length == 0) return false;
// need to assert that there are no gaps in the route
return this.links.every( (link, i, links) => {
if(i == 0) return true
return link.source == links[i-1].target
} )
}
addIntersection(intersection,logActivity){
console.assert(intersection instanceof Intersection)
Expand Down

0 comments on commit 65c6a59

Please sign in to comment.