Skip to content

Commit

Permalink
accommodates changes to the OS Open Roads GPKG layer keys
Browse files Browse the repository at this point in the history
  • Loading branch information
songololo committed Dec 1, 2023
1 parent 771f66c commit 2e815e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cityseer"
version = '4.5.8'
version = '4.6.0'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.12"
Expand Down
14 changes: 8 additions & 6 deletions pysrc/cityseer/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ def _process_node(nd_key: NodeKey) -> tuple[float, float]:

def nx_from_open_roads(
open_roads_path: str | Path,
road_node_layer_key: str = "road_node",
road_link_layer_key: str = "road_link",
target_bbox: BboxType | None = None,
) -> nx.MultiGraph:
"""
Expand All @@ -620,7 +622,10 @@ def nx_from_open_roads(
target_bbox: tuple[int]
A tuple of integers or floats representing the `[s, w, n, e]` bounding box extents for which to load the
dataset. Set to `None` for no bounding box.
road_node_layer_key: str
The `GPKG` layer key for the OS Open Roads road nodes layer. This may change from time to time.
road_link_layer_key: str
The `GPKG` layer key for the OS Open Roads road links layer. This may change from time to time.
Returns
-------
nx.MultiGraph
Expand All @@ -629,19 +634,17 @@ def nx_from_open_roads(
"""
# create a networkX multigraph
g_multi = nx.MultiGraph()

# load the nodes
with fiona.open(open_roads_path, layer="RoadNode") as nodes:
with fiona.open(open_roads_path, layer=road_node_layer_key) as nodes:
for node_data in nodes.values(bbox=target_bbox):
node_id: str = node_data["properties"]["id"]
x: float
y: float
x, y = node_data["geometry"]["coordinates"]
g_multi.add_node(node_id, x=x, y=y)

# load the edges
n_dropped = 0
with fiona.open(open_roads_path, layer="RoadLink") as edges:
with fiona.open(open_roads_path, layer=road_link_layer_key) as edges:
for edge_data in edges.values(bbox=target_bbox):
# x, y = edge_data['geometry']['coordinates']
props: dict = edge_data["properties"] # type: ignore
Expand Down Expand Up @@ -687,7 +690,6 @@ def nx_from_open_roads(
g_multi.add_edge(
start_nd, end_nd, names=list(names), routes=list(routes), highways=list(highways), geom=geom
)

logger.info(f"Nodes: {g_multi.number_of_nodes()}")
logger.info(f"Edges: {g_multi.number_of_edges()}")
logger.info(f"Dropped {n_dropped} edges where not both start and end nodes were present.")
Expand Down

0 comments on commit 2e815e1

Please sign in to comment.