Download utils/graphs.py from amanr24/SafeMaps: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/amanr24/SafeMaps/resolve/main/utils/graphs.py
- Command line
-
hf download hf://spaces/amanr24/SafeMaps/utils/graphs.py
-
curl -L -o graphs.py https://huggingface.co/spaces/amanr24/SafeMaps/resolve/main/utils/graphs.py
1.77 kB
| import osmnx as ox | |
| import networkx as nx | |
| import geopandas as gpd | |
| import pandas as pd | |
| import os | |
| #download the graph as a geopackage layer on the local disk | |
| #G=ox.graph_from_place("Mumbai,India",network_type="drive") | |
| #ox.save_graphml(graph,"C:\\Users\\vicky\\Downloads\\Major Project\\OSM Data\\mumbai.graphml") | |
| #nodes,streets=ox.graph_to_gdfs(graph) | |
| #print(nodes) | |
| #nodes.to_csv('C:\\Users\\vicky\\Downloads\\Major Project\\OSM Data\\nodes.csv') | |
| #load the graph the geopackage "file" | |
| graph=ox.load_graphml("data/mumbai_updated.graphml") | |
| #nodes,streets=ox.graph_to_gdfs(G) | |
| #print(nodes) | |
| #print(streets) | |
| #nodes.to_csv('C:\\Users\\vicky\\Downloads\\Major Project\\OSM Data\\nodes.csv') | |
| #print(graph.get_edge_data(245653028, 459529385, 0)) | |
| #print(nx.is_weighted(graph)) | |
| def getNodeFromAddress(address): | |
| geocode=ox.geocode(address) | |
| node=ox.nearest_nodes(graph,geocode[1],geocode[0]) | |
| return node; | |
| def getOutEdges(node_id): | |
| edges=graph.out_edges(node_id) | |
| return edges | |
| def getOutEdgesNodes(node_id): | |
| node_list=[] | |
| edges=getOutEdges(node_id) | |
| for e in edges: | |
| node_list.append(e[1]) | |
| return node_list | |
| def addAttribute(graph,data,attribute,attr): | |
| for i in range(len(data)): | |
| row=data.iloc[[i],attr] | |
| print(row) | |
| u=tuple(row['u'])[0] | |
| v=tuple(row['v'])[0] | |
| key=tuple(row['key'])[0] | |
| print(v,'\n') | |
| graph[u][v][key][attribute]=tuple(row[attribute])[0] | |
| #use the above getOutEdges funtion or the below in-built function | |
| #q=G.successors(getNodeFromAddress("Linking Road, Bandra")) | |
| """q=get_out_edges_nodes(get_node_from_address("Linking Road,Bandra")) | |
| print(q)""" | |
| """coord=get_geocode("Linking Road,Bandra,Mumbai,India") | |
| node_id=get_node(coord) | |
| edges=get_out_edges(node_id)s | |
| """ |