Skip to content

Commit

Permalink
naming fix
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime committed Mar 5, 2024
1 parent 90bcd72 commit c47bb46
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions geosnap/analyze/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def _geom_to_hull(geom, ratio, allow_holes):


def _geom_to_alpha(geom):
if isinstance(geom, list):
return alpha_shape_auto(gpd.GeoSeries(geom).get_coordinates()[["x", "y"]].values)

return alpha_shape_auto(geom.get_coordinates()[["x", "y"]].values)


Expand Down Expand Up @@ -67,7 +70,7 @@ def pdna_to_adj(origins, network, threshold, reindex=True, drop_nonorigins=True)
# map node ids in the network to index in the gdf
mapper = dict(zip(node_ids, origins.index.values))

namer = {"source": "origin", "distance": "cost"}
namer = {"source": "origin", network.impedance_names[0]: "cost"}

adj = network.nodes_in_range(node_ids, threshold)
adj = adj.rename(columns=namer)
Expand Down Expand Up @@ -248,15 +251,16 @@ def isochrones_from_gdf(
for origin in matrix.origin.unique():
do = matrix[matrix.origin == origin]
dest_pts = gpd.GeoDataFrame(destinations.loc[do["destination"]])
if use_edges is False:
dest_pts = dest_pts.geometry.tolist()
else:
edges = network.edges_df.copy()
roads = edges[
(edges["to"].isin(dest_pts.index.values))
& (edges["from"].isin(dest_pts.index.values))
]
dest_pts = roads
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(dest_pts.index.values))
& (edges["from"].isin(dest_pts.index.values))
]
dest_pts = roads

if hull == "libpysal":
alpha = _geom_to_alpha(dest_pts)
Expand All @@ -271,8 +275,8 @@ def isochrones_from_gdf(
alpha["distance"] = threshold
alpha["origin"] = origin
alphas.append(alpha)
df = pd.concat(alphas, ignore_index=True)
df = df.set_index("origin")
if reindex:
df = df.rename(index=mapper)
df = pd.concat(alphas, ignore_index=True)
df = df.set_index("origin")
if reindex:
df = df.rename(index=mapper, errors='raise')
return gpd.GeoDataFrame(df, crs=network_crs)

0 comments on commit c47bb46

Please sign in to comment.