mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-19 05:24:10 +08:00
version: lp-dp v0.9.3 for EON/C2 date: 2023-06-12T05:58:26 commit: a6e632fddf5e5e22867c0fd549b4e701cbc35d63
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
|
|
|
|
class WayRelationIndex():
|
|
"""
|
|
A class containing an index of WayRelations by node ids of internal nodes and edge nodes.
|
|
"""
|
|
def __init__(self, way_relations):
|
|
self._edge_nodes_index_dict = {}
|
|
self._full_nodes_index_dict = {}
|
|
|
|
for wr in way_relations:
|
|
self.add(wr)
|
|
|
|
def add(self, way_relation):
|
|
for node in way_relation.way.nodes:
|
|
node_id = node.id
|
|
self._full_nodes_index_dict[node_id] = self._full_nodes_index_dict.get(node_id, []) + [way_relation]
|
|
if node_id in way_relation.edge_nodes_ids:
|
|
self._edge_nodes_index_dict[node_id] = self._edge_nodes_index_dict.get(node_id, []) + [way_relation]
|
|
|
|
def remove(self, way_relation):
|
|
for node in way_relation.way.nodes:
|
|
node_id = node.id
|
|
self._full_nodes_index_dict[node_id] = [wr for wr in self._full_nodes_index_dict.get(node_id, [])
|
|
if wr is not way_relation]
|
|
if node_id in way_relation.edge_nodes_ids:
|
|
self._edge_nodes_index_dict[node_id] = [wr for wr in self._edge_nodes_index_dict.get(node_id, [])
|
|
if wr is not way_relation]
|
|
|
|
def way_relations_with_edge_node_id(self, node_id):
|
|
return self._edge_nodes_index_dict.get(node_id, [])
|
|
|
|
def way_relations_with_node_id(self, node_id):
|
|
return self._full_nodes_index_dict.get(node_id, [])
|