When running a query with the Osmnx API to find the nearest nodes or nearest edges, Is there a way to search only a smaller subregion of the graph to speed things up?

I’ve loaded a large graph into memory for the state of New York (downloaded from the Geofabrik website). I’m running the following code to find the nearest road’s highway tag and max_speed tag.

with open(pickled_network_path, ‘rb’) as f:
network = pickle.load(f)
nearest_edge = osmnx.nearest_edges(network, long, lat, return_dist=False)[:2]

graph_edges_dictionary = network.edges.keys()._mapping.data()._adjdict
nearest_edge_info = graph_edges_dictionary[nearest_edge[0]][nearest_edge[1]][0]

highway = nearest_edge_info.get(‘highway’, None)
maxspeed = nearest_edge_info.get(‘maxspeed’, None)

I’ve noticed that the larger the graph is, the longer it takes for osmnx.nearest_edges to run. For New York’s graph, it takes about 5 minutes. For Delaware, it took 30 seconds. Eventually, I’ll have to run it for the whole US. I need to get through millions of points, which is impractical given the run time.
Is there a way to search only a small portion of the graph every time to speed up the run time? If I have the graph for the whole New York state, but I know my latitude,longitude point is in the city of Buffalo, can I limit my search to that city only? Does the search have to be through all the nodes in the graph or can I do something so that it only searches a small portion of it?

2 posts - 2 participants

Read full topic


Ce sujet de discussion accompagne la publication sur https://community.openstreetmap.org/t/when-running-a-query-with-the-osmnx-api-to-find-the-nearest-nodes-or-nearest-edges-is-there-a-way-to-search-only-a-smaller-subregion-of-the-graph-to-speed-things-up/103974