From 6d80a19d20464dfa7a3b2cf816e6016f64620818 Mon Sep 17 00:00:00 2001 From: eli knaap Date: Mon, 4 Mar 2024 18:49:01 -0800 Subject: [PATCH] edges in from_id --- geosnap/analyze/network.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/geosnap/analyze/network.py b/geosnap/analyze/network.py index f7a4e20b..f7474862 100644 --- a/geosnap/analyze/network.py +++ b/geosnap/analyze/network.py @@ -85,7 +85,7 @@ def pdna_to_adj(origins, network, threshold, reindex=True, drop_nonorigins=True) def isochrones_from_id( - origin, network, threshold, hull="shapely", ratio=0.2, allow_holes=False + origin, network, threshold, hull="shapely", ratio=0.2, allow_holes=False, use_edges=True ): """Create travel isochrone(s) from a single origin using a pandana network. @@ -147,10 +147,20 @@ def isochrones_from_id( # select the nodes within each threshold distance and take their alpha shape df = matrix[matrix.cost <= distance] nodes = node_df[node_df.index.isin(df.destination.tolist())] + if use_edges is True: + if "geometry" not in network.edges_df.columns: + pass + else: + edges = network.edges_df.copy() + roads = edges[ + (edges["to"].isin(nodes.index.values)) + & (edges["from"].isin(nodes.index.values)) + ] + nodes = roads if hull == "libpysal": - alpha = _geom_to_alpha(nodes.geometry.tolist()) + alpha = _geom_to_alpha(nodes) elif hull == "shapely": - alpha = _geom_to_hull(nodes.geometry.tolist(), ratio=ratio, allow_holes=allow_holes) + alpha = _geom_to_hull(nodes, ratio=ratio, allow_holes=allow_holes) else: raise ValueError( f"`algorithm must be either 'alpha' or 'hull' but {hull} was passed"