Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #88

Merged
merged 2 commits into from
Oct 28, 2023
Merged

Dev #88

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.3'
version = '4.2.4'
description = "Computational tools for network-based pedestrian-scale urban analysis"
readme = "README.md"
requires-python = ">=3.10, <3.12"
Expand Down
17 changes: 6 additions & 11 deletions pysrc/cityseer/tools/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,9 +1352,7 @@ def prepare_dual_node_key(start_nd_key: NodeKey, end_nd_key: NodeKey, edge_idx:
return g_dual


def nx_weight_by_dissolved_edges(
nx_multigraph: MultiGraph, dissolve_distance: int = 20, max_ang_diff: int = 15
) -> MultiGraph:
def nx_weight_by_dissolved_edges(nx_multigraph: MultiGraph, dissolve_distance: int = 20) -> MultiGraph:
"""
Generates graph node weightings based on the ratio of directly adjacent edges to total nearby edges.

Expand All @@ -1369,9 +1367,6 @@ def nx_weight_by_dissolved_edges(
edge attributes containing `LineString` geoms.
dissolve_distance: int
A distance to use when buffering edges to calculate the weighting. 20m by default.
max_ang_diff: int
Only count a nearby adjacent edge as duplicitous if the angular difference between edges is less than
`max_ang_diff`. 15 degrees by default.

Returns
-------
Expand All @@ -1380,6 +1375,8 @@ def nx_weight_by_dissolved_edges(
locally 'dissolved' context.

"""
# note it is better to weight via edges than via nodes this is because offset / staggered nodes
# (intersections on one side of parallel road) might not otherwise trigger de-duplication via weights
if not isinstance(nx_multigraph, nx.MultiGraph):
raise TypeError("This method requires an undirected networkX MultiGraph.")
logger.info(f"Generating node weights based on locally dissolved edges using a buffer of {dissolve_distance}m.")
Expand All @@ -1394,23 +1391,21 @@ def nx_weight_by_dissolved_edges(
g_multi_copy[start_nd_key][end_nd_key][edge_idx]["nearby_itx_lens"] = 0
# find nearby edges
edge_geom = edge_data["geom"]
edge_geom_buff = edge_geom.buffer(dissolve_distance)
edge_geom_buff = edge_geom.buffer(dissolve_distance, cap_style=geometry.CAP_STYLE.square)
edges_hits: list[int] = edges_tree.query(edge_geom_buff)
for edge_hit_idx in edges_hits:
edge_lookup = edge_lookups[edge_hit_idx]
nearby_start_nd_key = edge_lookup["start_nd_key"]
nearby_end_nd_key = edge_lookup["end_nd_key"]
nearby_edge_idx = edge_lookup["edge_idx"]
# don't add edges which share common nodes (directly adjacent)
# this is an important line because otherwise the measure becomes indiscriminate i.e. would apply to regular
# intersections without duplicitous edges - working against intention of this method
if nearby_start_nd_key in [start_nd_key, end_nd_key] or nearby_end_nd_key in [start_nd_key, end_nd_key]:
continue
# get linestring
edge_data = g_multi_copy[nearby_start_nd_key][nearby_end_nd_key][nearby_edge_idx]
nearby_edge_geom: geometry.LineString = edge_data["geom"]
# get angular difference
ang_diff = util.measure_angle_diff_betw_linestrings(edge_geom.coords, nearby_edge_geom.coords)
if ang_diff > max_ang_diff:
continue
# find length of geom intersecting buff
edge_itx = nearby_edge_geom.intersection(edge_geom_buff)
if edge_itx and edge_itx.geom_type == "LineString":
Expand Down
4 changes: 2 additions & 2 deletions pysrc/cityseer/tools/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ def plot_nx(
Whether to plot the edge geometries. If set to `False`, straight lines will be drawn from node-to-node to
represent edges. Defaults to True.
x_lim: tuple[float, float]
A tuple or list with the minimum and maxium `x` extents to be plotted. Defaults to None.
A tuple or list with the minimum and maximum `x` extents to be plotted. Defaults to None.
y_lim: tuple[float, float]
A tuple or list with the minimum and maxium `y` extents to be plotted. Defaults to None.
A tuple or list with the minimum and maximum `y` extents to be plotted. Defaults to None.
ax: plt.Axes
An optional `matplotlib` `ax` to which to plot. If not provided, a figure and ax will be generated.
kwargs
Expand Down
4 changes: 2 additions & 2 deletions pysrc/cityseer/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,9 @@ def blend_metrics(
Parameters
----------
nodes_gdf: GeoDataFrame
A nodes `GeoDataFrame` as derived from [`network_structure_from_nx`](#network-structure-from-nx).
A nodes `GeoDataFrame` as derived from [`network_structure_from_nx`](tools/io#network-structure-from-nx).
edges_gdf: GeoDataFrame
An edges `GeoDataFrame` as derived from [`network_structure_from_nx`](#network-structure-from-nx).
An edges `GeoDataFrame` as derived from [`network_structure_from_nx`](tools/io#network-structure-from-nx).
method: str
The method used for determining the line value from the adjacent points. Must be one of "min", "max", or "avg".

Expand Down