Skip to content

Commit

Permalink
Merge pull request #117 from benchmark-urbanism/dev
Browse files Browse the repository at this point in the history
OSM clean method with hwy tags
  • Loading branch information
songololo authored Jun 18, 2024
2 parents 095b43c + 5754619 commit 7690392
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 247 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

293 changes: 152 additions & 141 deletions pdm.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cityseer"
version = '4.13.3'
version = '4.14.0'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.13"
Expand Down Expand Up @@ -106,6 +106,7 @@ dev = [
"pdoc>=14.1.0",
"docstring-parser>=0.15",
"dominate>=2.8.0",
"utm>=0.7.0",
]

[build-system]
Expand Down
177 changes: 128 additions & 49 deletions pysrc/cityseer/tools/graphs.py

Large diffs are not rendered by default.

56 changes: 27 additions & 29 deletions pysrc/cityseer/tools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ def osm_graph_from_poly(
(
way["highway"]
["area"!="yes"]
["highway"!~"motorway|motorway_link|bus_guideway|busway|escape|raceway|proposed|planned|abandoned|platform|construction|emergency_bay|rest_area"]
["tunnel"!="yes"]
["highway"!~"bus_guideway|busway|escape|raceway|proposed|planned|abandoned|platform|construction|emergency_bay|rest_area"]
["footway"!="sidewalk"]
["service"!~"parking_aisle|driveway|drive-through|slipway"]
["amenity"!~"charging_station|parking|fuel|motorcycle_parking|parking_entrance|parking_space"]
Expand Down Expand Up @@ -357,32 +356,31 @@ def osm_graph_from_poly(
graph_crs = graphs.nx_remove_filler_nodes(graph_crs)
if simplify:
graph_crs = graphs.nx_remove_dangling_nodes(graph_crs, remove_disconnected=remove_disconnected)
graph_crs = graphs.nx_consolidate_nodes(
graph_crs,
buffer_dist=crawl_consolidate_dist,
crawl=True,
contains_buffer_dist=contains_buffer_dist,
)
graph_crs = graphs.nx_split_opposing_geoms(
graph_crs, buffer_dist=parallel_consolidate_dist, contains_buffer_dist=contains_buffer_dist
)
graph_crs = graphs.nx_consolidate_nodes(
graph_crs,
buffer_dist=parallel_consolidate_dist,
contains_buffer_dist=contains_buffer_dist,
)
graph_crs = graphs.nx_remove_filler_nodes(graph_crs)
if iron_edges:
graph_crs = graphs.nx_iron_edges(graph_crs)
graph_crs = graphs.nx_split_opposing_geoms(
graph_crs, buffer_dist=parallel_consolidate_dist, contains_buffer_dist=contains_buffer_dist
)
graph_crs = graphs.nx_consolidate_nodes(
graph_crs,
buffer_dist=parallel_consolidate_dist,
contains_buffer_dist=contains_buffer_dist,
)
graph_crs = graphs.nx_remove_filler_nodes(graph_crs)
for hwy_keys, split_dist, consol_dist, cent_by_itx in [
(["motorway"], 30, 15, False),
(["trunk"], parallel_consolidate_dist, crawl_consolidate_dist, True),
(["primary"], parallel_consolidate_dist, crawl_consolidate_dist, True),
(["secondary"], parallel_consolidate_dist, crawl_consolidate_dist, True),
(["tertiary"], parallel_consolidate_dist, crawl_consolidate_dist, True),
(["residential"], parallel_consolidate_dist, crawl_consolidate_dist, True),
(None, parallel_consolidate_dist, crawl_consolidate_dist, False),
]:
contains_buffer_dist = max(split_dist, 25)
graph_crs = graphs.nx_split_opposing_geoms(
graph_crs,
buffer_dist=split_dist,
osm_hwy_target_tags=hwy_keys,
contains_buffer_dist=contains_buffer_dist,
)
graph_crs = graphs.nx_consolidate_nodes(
graph_crs,
buffer_dist=consol_dist,
crawl=True,
osm_hwy_target_tags=hwy_keys,
centroid_by_itx=cent_by_itx,
contains_buffer_dist=contains_buffer_dist,
)
graph_crs = graphs.nx_remove_filler_nodes(graph_crs)
if iron_edges:
graph_crs = graphs.nx_iron_edges(graph_crs)

Expand Down Expand Up @@ -668,7 +666,7 @@ def nx_from_open_roads(
)
# create the geometry
geom = geometry.LineString(edge_data.geometry["coordinates"])
geom: geometry.LineString = geom.simplify(5)
geom: geometry.LineString = geom.simplify(5) # type: ignore
# do not add edges to clipped extents
if start_nd not in g_multi or end_nd not in g_multi:
n_dropped += 1
Expand Down
2 changes: 1 addition & 1 deletion pysrc/cityseer/tools/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def mock_data_gdf(nx_multigraph: MultiGraph, length: int = 50, random_seed: int
# last 5 datapoints are a cluster of nodes where the nodes share the same data_id for deduplication checks
for idx, loc_idx in enumerate(range(length - 5, length)):
data_gpd.loc[str(loc_idx), "data_id"] = length - 5
data_gpd.loc[str(loc_idx), "geometry"] = geometry.Point(700100 + idx * 10, 5719100 + idx * 10)
data_gpd.loc[str(loc_idx), "geometry"] = geometry.Point(700100 + idx * 10, 5719100 + idx * 10) # type: ignore
data_gpd = cast(gpd.GeoDataFrame, data_gpd)
return data_gpd

Expand Down
5 changes: 3 additions & 2 deletions pysrc/cityseer/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
NodeData = dict[str, Any]
EdgeType = Union[tuple[NodeKey, NodeKey], tuple[NodeKey, NodeKey, int]]
EdgeData = dict[str, Any]
EdgeMapping = tuple[NodeKey, NodeKey, int, geometry.LineString]
EdgeMapping = tuple[NodeKey, NodeKey, int, dict[Any, Any]]
CoordsType = Union[tuple[float, float], tuple[float, float, float], npt.NDArray[np.float_]]
ListCoordsType = Union[list[CoordsType], coords.CoordinateSequence]

Expand Down Expand Up @@ -410,7 +410,8 @@ def add_node(
"""
# suggest a name based on the given names
if len(nodes_names) == 1:
new_nd_name = str(nodes_names[0])
# catch sets
new_nd_name = str(list(nodes_names)[0])
# if concatenating existing nodes, suggest a name based on a combination of existing names
else:
names = []
Expand Down
19 changes: 5 additions & 14 deletions tests/tools/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_nx_consolidate_nodes(parallel_segments_graph):
""" """
# behaviour confirmed visually
# from cityseer.tools import plot
# plot.plot_nx(G, labels=True, node_size=80, plot_geoms=True)
# plot.plot_nx(parallel_segments_graph, labels=True, node_size=80, plot_geoms=True)
# set centroid_by_itx to False
G_merged_spatial = graphs.nx_consolidate_nodes(
parallel_segments_graph, buffer_dist=25, crawl=True, centroid_by_itx=False, merge_edges_by_midline=True
Expand All @@ -367,29 +367,20 @@ def test_nx_consolidate_nodes(parallel_segments_graph):
node_coords.append((d["x"], d["y"]))
assert node_coords == [
(660, 660),
(620.0, 710.0),
(660.0, 710.0),
(780.0, 710.0),
(620.0, 710.0),
(710.0, 800.0),
(706.6666666666666, 713.3333333333334),
(710.0, 710.0),
(710.0, 620.0),
(780.0, 710.0),
(840.0, 710.0),
]
edge_lens = []
for s, e, d in G_merged_spatial.edges(data=True):
edge_lens.append(d["geom"].length)
assert np.allclose(
edge_lens,
[
50.0,
40.0,
46.78556282539396,
86.73074554171788,
93.39283817414604,
73.40905181848417,
60.0,
147.70329614269008,
],
[50.0, 40.0, 50.0, 70.0, 60.0, 147.70329614269008, 90.0, 90.0],
)


Expand Down

0 comments on commit 7690392

Please sign in to comment.