0

I was trying to route two co-ordinates using osmnx. I found that osmnx takes nearest node w.r.to our given co-ordinates. So, I was thinking if it is possible to create custom node from our given co-ordinates and then route it.

import geopandas as gpd 
import networkx as nx 
import osmnx as ox 
import numpy as np
import matplotlib.pyplot as plt

G = ox.graph.graph_from_xml('map_3.osm', bidirectional=False, simplify=True, retain_all=False)
nodes_proj, edges_proj = ox.graph_to_gdfs(G, nodes=True, edges=True) 

origin_node = ox.distance.nearest_nodes(G,8.390278350417713,48.98250179896953)
destination_node = ox.distance.nearest_nodes(G, 8.390791842821093, 48.98715746773447)
route = ox.distance.shortest_path(G, origin_node,destination_node, weight='length')
bbox = ox.utils_geo.bbox_from_point(point=(48.985338, 8.393094), dist=700)
fig, ax = ox.plot_graph_route(G, route, route_color='r',bbox = bbox, route_linewidth=6,route_alpha=0.5,orig_dest_size=100, ax=None, node_size=0, bgcolor='k')

I also found this, which helps in converting lat, long to x,y.

I tried adding node like this,

test = 10000001
G.add_node(test,x=l1,y=l2)
nearest_nodes1 = ox.distance.nearest_nodes(G, 8.3906217,48.9829172)

I was able to create node successfully (checked also in plot), but when I try to route now,

route = ox.distance.shortest_path(G, origin_node1,destination_node, weight='length')

it returns None. Where am I going wrong?

Sanketh J
  • 1
  • 1

0 Answers0