2

I'm trying to download the map of Mexico to avoid querying using save_graphml and avoiding long response times in the graph_from_place, but I've already left this code running for almost six hours and absolutely nothing happens.

import osmnx as ox

ox.config(use_cache=True, log_console=True)

G = ox.graph_from_place('Mexico', network_type = 'drive', simplify=False)
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)

ox.save_graphml(G, '/var/www/html/repmexico.graphml')

print("Success!!!")

Today I am trying to run the code on a server with 74GB of RAM and (Intel xeon x5570) X2

(I know that due to the stipulated area the time is long, but what I wanted to know is if there is an alternative to this procedure or if there is a way to optimize so that the creation of the map is a little faster or if there is another way to load maps to route with osmnx and networkx without using queries to servers)

1 Answers1

3

I've already left this code running for almost six hours and absolutely nothing happens.

A lot has been happening! Don't believe me? You ran ox.config(log_console=True), so look at your terminal and watch what's happening while it runs. You'll see a line like "2021-10-14 13:05:39 Requesting data within polygon from API in 1827 request(s)"... so you are making 1,827 requests to the Overpass server and the server is asking you to pause for rate limiting between many of those requests.

I know that due to the stipulated area the time is long, but what I wanted to know is if there is an alternative to this procedure or if there is a way to optimize so that the creation of the map is a little faster or if there is another way to load maps to route with osmnx and networkx without using queries to servers

Yes. This answer provides more details. There are tradeoffs between 1) model precision vs 2) area size vs 3) memory/speed. For faster modeling, you can load the network data from a .osm XML file instead of having to make numerous calls to the Overpass API. I'd also recommend using a custom_filter as described in the linked answer. OSMnx by default divides your query area into 50km x 50km pieces, then queries Overpass for each piece one a time to not exceed the server's per-query memory limits. You can configure this max_query_area_size parameter, as well as the server memory allocation, if you prefer to use OSMnx's API querying functions rather than its from-file functionality.

gboeing
  • 5,691
  • 2
  • 15
  • 41
  • 1
    Hello, thank you very much for responding to my comment. Try loading an .osm map from http://download.geofabrik.de/north-america/mexico.html Specifically the map "mexico-latest.osm.bz2" I unzipped it and got the .osm file and tried to load it from the server that I mentioned in the main question, and I couldn't get it to show the test routes, in fact it was doing processes and it lasted hours until I stopped the procedure. For that procedure I used the following tags: G = graph_from_xml (/var/www/html/mexico-latest.osm) – Juan Martin Gonzalez Razo Oct 14 '21 at 21:56
  • 1
    My goal is really to avoid making queries to decrease the response time of my script that I am running on my server so far the only way I found to speed up the procedure a bit was using save_graphml and then load it and work with it to do the routings, that worked with a city and I was trying to scale it to a country – Juan Martin Gonzalez Razo Oct 14 '21 at 22:00
  • 1
    That should be a separate question. Open a new question, provide full reproducing details, and someone may be able to troubleshoot. – gboeing Oct 15 '21 at 02:13
  • Still, it takes an extremely long time to load and build a graph from a local `XML` file, not to mention that the `max_query_area_size` is deprecated. – Yahya Mar 27 '23 at 22:20
  • No the `max_query_area_size` setting is not deprecated. You can find its documentation here: https://osmnx.readthedocs.io/en/stable/osmnx.html#module-osmnx.settings – gboeing Mar 28 '23 at 04:15