throw correct exceptions during routing
This commit is contained in:
parent
56542cf54e
commit
e51f790ed5
2 changed files with 13 additions and 9 deletions
|
@ -19,7 +19,7 @@ from c3nav.mapdata.models import AltitudeArea, Area, GraphEdge, Level, LocationG
|
|||
from c3nav.mapdata.models.geometry.space import POI
|
||||
from c3nav.mapdata.utils.geometry import assert_multipolygon, get_rings, good_representative_point
|
||||
from c3nav.mapdata.utils.locations import CustomLocation
|
||||
from c3nav.routing.exceptions import NotYetRoutable
|
||||
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
||||
from c3nav.routing.route import Route
|
||||
|
||||
|
||||
|
@ -277,7 +277,10 @@ class Router:
|
|||
location.nodes = set(i for i in location_nodes.keys())
|
||||
location.nodes_addition = location_nodes
|
||||
locations = tuple((location, ))
|
||||
return RouterLocation(locations)
|
||||
result = RouterLocation(locations)
|
||||
if not result.nodes:
|
||||
raise LocationUnreachable
|
||||
return result
|
||||
|
||||
def space_for_point(self, level, point, restrictions=None):
|
||||
point = Point(point.x, point.y)
|
||||
|
@ -324,8 +327,6 @@ class Router:
|
|||
origins = self.get_locations(origin, restrictions)
|
||||
destinations = self.get_locations(destination, restrictions)
|
||||
|
||||
# todo: throw error if route is impossible
|
||||
|
||||
# calculate shortest path matrix
|
||||
distances, predecessors = self.shortest_path(restrictions)
|
||||
|
||||
|
@ -339,6 +340,9 @@ class Router:
|
|||
origin_node = origin_nodes[origin_node]
|
||||
destination_node = destination_nodes[destination_node]
|
||||
|
||||
if distances[origin_node, destination_node] == np.inf:
|
||||
raise NoRouteFound
|
||||
|
||||
# get best origin and destination
|
||||
origin = origins.get_location_for_node(origin_node)
|
||||
destination = destinations.get_location_for_node(destination_node)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue