From 681982ce59abdf997d758d6f287b550eee66132c Mon Sep 17 00:00:00 2001 From: Gareth Simons Date: Fri, 27 Oct 2023 17:06:36 +0100 Subject: [PATCH 1/2] fixes typos --- pysrc/cityseer/tools/plot.py | 4 ++-- pysrc/cityseer/tools/util.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pysrc/cityseer/tools/plot.py b/pysrc/cityseer/tools/plot.py index 22abb6b2..afec00fd 100644 --- a/pysrc/cityseer/tools/plot.py +++ b/pysrc/cityseer/tools/plot.py @@ -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 diff --git a/pysrc/cityseer/tools/util.py b/pysrc/cityseer/tools/util.py index c698a5d7..f5e02ba5 100644 --- a/pysrc/cityseer/tools/util.py +++ b/pysrc/cityseer/tools/util.py @@ -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". From e3f18ad45cc6b8d5bf494e4ebcbfd4164bbb3266 Mon Sep 17 00:00:00 2001 From: Gareth Simons Date: Fri, 27 Oct 2023 22:07:05 +0100 Subject: [PATCH 2/2] removes max angle param from weights dissolve --- pyproject.toml | 2 +- pysrc/cityseer/tools/graphs.py | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 14e3f806..454dbea4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/pysrc/cityseer/tools/graphs.py b/pysrc/cityseer/tools/graphs.py index 93a5835f..765c7b0f 100644 --- a/pysrc/cityseer/tools/graphs.py +++ b/pysrc/cityseer/tools/graphs.py @@ -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. @@ -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 ------- @@ -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.") @@ -1394,7 +1391,7 @@ 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] @@ -1402,15 +1399,13 @@ def nx_weight_by_dissolved_edges( 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":