I have DataFrame contain two columns (latitude, longitude ) for 30000 points as follows:
I need to obtain the start node and end node of the nearest edge to each point.
I used the following code for a sample (contain 5 points only) using a method from osmnx library (https://osmnx.readthedocs.io/en/stable/search.html?q=get_nearest_edge&check_keywords=yes&area=default#) :
def find_nearest_edges(row):
near_edge=ox.get_nearest_edge(G,(row['LATITUDE'],row['LONGITUDE']))
start=intr_stp_nodes[1]
end=intr_stp_nodes[2]
return pd.Series([start, end])
sample_df[['start','end']]=sample_df.apply(find_nearest_edges,axis=1)
Although I got the Resulting data frame, it took a lot of time to compute 5 points:
The resulting data frame :
I tried to use the @gboeing recommendation and create the next function:
def find_nearest_edges(row):
shp,start,end=ox.get_nearest_edges(G,row['LONGITUDE'],row['LATITUDE'],method='kdtree',dist=0.0001)
return pd.Series([start, end])
sample_df[['start','end']]=sample_df.apply(find_nearest_edges,axis=1)
I applied the previous function but it takes a lot of time without any result.