File size: 1,766 Bytes
4f1aa78 3c6880b 4f1aa78 40521b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 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
""" |