let's not crash if there are nodes outside of altitude areas
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:
