Skip to content

Commit

Permalink
routing: looking for FTU, port, and connector
Browse files Browse the repository at this point in the history
  • Loading branch information
napakalas committed Dec 18, 2023
1 parent 9c704a0 commit d243b5f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions mapmaker/routing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
import math
import sys
from typing import TYPE_CHECKING, Any, Optional
from mapmaker.knowledgebase.sckan import PATH_TYPE

from mapmaker.settings import settings
from mapmaker.knowledgebase.celldl import CD_CLASS, FC_CLASS, FC_KIND
from mapmaker.knowledgebase.celldl import FC_CLASS, FC_KIND


#===============================================================================
Expand Down Expand Up @@ -952,17 +953,32 @@ def get_centreline_from_containing_features(start_dict, end_dict, feature_ids: s
route_graph.add_edge(*edge, **edge_dict)
path_node_ids.update(node.feature_id for node in edge_dict['network-nodes'])

def get_ftu_node(feature):
# looking for FTU if possible
if feature.properties.get('fc-class') != FC_CLASS.FTU:
for child in feature.properties.get('children', []):
child_feature = self.__flatmap.get_feature_by_geojson_id(child)
if child_feature.properties.get('fc-class') == FC_CLASS.FTU and child_feature.models == feature.models:
feature = child_feature
break
# looking for correct connector or port
for child in feature.properties.get('children', []):
child_feature = self.__flatmap.get_feature_by_geojson_id(child)
if (child_feature.properties.get('fc-kind') in [FC_KIND.CONNECTOR_NODE, FC_KIND.CONNECTOR_PORT, FC_KIND.GANGLION] and \
path.path_type is not None and \
child_feature.properties.get('path-type') != PATH_TYPE.UNKNOWN) and \
(path.path_type == child_feature.properties.get('path-type') or \
PATH_TYPE.PRE_GANGLIONIC|child_feature.properties.get('path-type') == path.path_type or \
PATH_TYPE.POST_GANGLIONIC|child_feature.properties.get('path-type') == path.path_type):
return child_feature
return feature

def get_node_feature(node_dict) -> Feature:
if len(node_dict['features']) > 1:
log.error(f'{path.id}: Terminal node {node_dict["name"]} has multiple features {sorted(set(f.id for f in node_dict["features"]))}')
selected_feature = list(f for f in node_dict['features'])[0]
if settings.get('NPO', False):
for child in selected_feature.properties.get('children'):
child_feature = self.__flatmap.get_feature_by_geojson_id(child)
print('**', path.id, path.path_type, child_feature.properties.get('path-type'), child_feature.properties.get('fc-kind'))
if child_feature.properties.get('fc-kind') in [FC_KIND.CONNECTOR_NODE, FC_KIND.CONNECTOR_PORT] and path.path_type is not None:
if (path.path_type | child_feature.properties.get('path-type')) == path.path_type:
return child_feature
return get_ftu_node(selected_feature)
return selected_feature

terminal_graphs: dict[tuple, nx.Graph] = {}
Expand Down

0 comments on commit d243b5f

Please sign in to comment.