From 1c6e91682306195909d40766dbc0e21b4ad61fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Wed, 12 Dec 2018 21:53:26 +0100 Subject: [PATCH] let's not crash if there are nodes outside of altitude areas --- src/c3nav/routing/router.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/c3nav/routing/router.py b/src/c3nav/routing/router.py index b20b04b7..c3302d39 100644 --- a/src/c3nav/routing/router.py +++ b/src/c3nav/routing/router.py @@ -1,4 +1,5 @@ import json +import logging import operator import os import pickle @@ -24,6 +25,8 @@ from c3nav.mapdata.utils.locations import CustomLocation from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable from c3nav.routing.route import Route +logger = logging.getLogger('c3nav') + class Router: filename = os.path.join(settings.CACHE_ROOT, 'router') @@ -138,6 +141,17 @@ class Router: space.altitudeareas.append(area) + for node in space_nodes: + if node.altitude is not None: + continue + logger.warning('Node %d in space %d is not inside an altitude area' % (node.pk, space.pk)) + node_altitudearea = min(space.altitudeareas, key=lambda a: a.distance(node.point), default=None) + if node_altitudearea: + node.altitude = node_altitudearea.get_altitude(node) + else: + node.altitude = float(level.base_altitude) + logger.info('Space %d has no altitude areas' % space.pk) + for area in space.altitudeareas: # create fallback nodes if not area.nodes and space_nodes: