I have a dataframe with multiple columns including Lon and Lat columns (as shown below: buildingID, Lon, Lat) (almost 20k rows). I have taken the school coordinates (around 150 schools) and street networks from the open street map.
I would like to find the shortest driving distance (in meters) to the closest school from each of my buildings.
>>> my_dataframe
buildingID Lon Lat
0 1 32.623021 39.890776
1 2 32.622998 39.890777
2 3 32.628109 39.892771
3 4 32.822124 39.876407
4 5 32.821548 39.879368
... ... ... ...
19500 19501 32.891779 39.925762
19501 19502 32.827799 39.984431
19502 19503 32.592832 39.966494
19503 19504 32.837584 39.883185
19504 19505 32.594223 39.936489
If there were only one origin point and one destination point, distance between the two would be calculated with the code below (from @Joery's answer).
However, I don't know how I can calculate distances from m origins to n destinations? And how to filter only the distances from my each point to the nearest destination?
import networkx as nx
import osmnx as ox
# get the nearest network node to each point
orig_node = ox.get_nearest_node(G, (37.828903, -122.245846))
dest_node = ox.get_nearest_node(G, (37.812303, -122.215006))
# how long is our route in meters?
nx.shortest_path_length(G, orig_node, dest_node, weight='length')