You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggested function to add (or at least a first version for a new one):
def nearest_not_intersecting(node, gdf, condition,threshold=0.01):
"""Find the element of a GeoDataFrame nearest a shapely geometry
"""
geom = node.geometry
n = 10
step = 10
while True:
matches_idx = gdf.sindex.nearest(geom.bounds, n)
candidate_idxs = []
k = 0
for match_idx in matches_idx:
edge = gdf.iloc[match_idx]
distance = geom.distance(edge.geometry)
if (edge.infra_type == node.infra_type) & (distance == 0):
k += 1
if not condition(node, edge):
continue
if 0 < distance <= threshold:
candidate_idxs.append(match_idx)
if k > 2:
break
if candidate_idxs:
nearest_geom = min(
[gdf.iloc[match_idx] for match_idx in candidate_idxs],
key=lambda match: geom.distance(match.geometry)
)
return nearest_geom
n = n + step
if n > 10:
break
For example, given a set of edges, add endpoints, then connect those endpoints to other edges (maybe given some condition).
Notes:
nearest_edge
returns nearest single edgeedges_within
can return set of incident edges, which can then be excluded from the edges passed tonearest_edge
d_outside
ordisjoint
to complementd_within
orintersects
The text was updated successfully, but these errors were encountered: