Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for key, value in nodes_temp.items():
nodes[key] = value
for key, value in paths_temp.items():
paths[key] = value
# add each osm node to the graph
for node, data in nodes.items():
G.add_node(node, **data)
# add each osm way (aka, path) to the graph
G = add_paths(G, paths, bidirectional=bidirectional)
# retain only the largest connected component, if caller did not
# set retain_all=True
if not retain_all:
G = get_largest_component(G)
log('Created graph with {:,} nodes and {:,} edges in {:,.2f} seconds'.format(len(list(G.nodes())), len(list(G.edges())), time.time()-start_time))
# add length (great circle distance between nodes) attribute to each edge to
# use as weight
if len(G.edges) > 0:
G = add_edge_lengths(G)
return G
"""
# get the shortest distance between the node and every other node, then
# remove every node further than max_distance away
start_time = time.time()
G = G.copy()
distances = nx.shortest_path_length(G, source=source_node, weight=weight)
distant_nodes = {key:value for key, value in dict(distances).items() if value > max_distance}
G.remove_nodes_from(distant_nodes.keys())
log('Truncated graph by weighted network distance in {:,.2f} seconds'.format(time.time()-start_time))
# remove any isolated nodes and retain only the largest component (if
# retain_all is True)
if not retain_all:
G = remove_isolated_nodes(G)
G = get_largest_component(G)
return G
gdf_nodes.crs = G.graph['crs']
# find all the nodes in the graph that lie outside the polygon
points_within_geometry = intersect_index_quadrats(gdf_nodes, polygon, quadrat_width=quadrat_width, min_num=min_num, buffer_amount=buffer_amount)
nodes_outside_polygon = gdf_nodes[~gdf_nodes.index.isin(points_within_geometry.index)]
# now remove from the graph all those nodes that lie outside the place
# polygon
start_time = time.time()
G.remove_nodes_from(nodes_outside_polygon['node'])
log('Removed {:,} nodes outside polygon in {:,.2f} seconds'.format(len(nodes_outside_polygon), time.time()-start_time))
# remove any isolated nodes and retain only the largest component (if retain_all is False)
if not retain_all:
G = remove_isolated_nodes(G)
G = get_largest_component(G)
return G
any_neighbors_in_bbox = True
break
# if none of its neighbors are within the bounding box, add node
# to list of nodes outside the bounding box
if not any_neighbors_in_bbox:
nodes_outside_bbox.append(node)
G.remove_nodes_from(nodes_outside_bbox)
log('Truncated graph by bounding box in {:,.2f} seconds'.format(time.time()-start_time))
# remove any isolated nodes and retain only the largest component (if
# retain_all is True)
if not retain_all:
G = remove_isolated_nodes(G)
G = get_largest_component(G)
return G