Search code examples
pythongisopenstreetmappyosmium

How can I load a map using pyrosm?


Well, what I'm trying to do is open a map and, with two georeferenced points, try to calculate the distance between them via a highway.

Using the ([https://pyrosm.readthedocs.io/en/latest/basics.html](pyrosm example)) I created the following code:

from pyrosm import OSM, get_data
import osmnx as ox
import time

osm = OSM(get_data("sudeste", directory="/home/brunob/mapas"))

buildings = osm.get_buildings()
buildings.plot()

drive_net = osm.get_network(network_type="driving")
drive_net.plot()

And I recieved this error:

 Traceback (most recent call last):
 File "/home/brunob/códigos/plotando_mapa.py", line 18, in <module>
 drive_net = osm.get_network(network_type="driving")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/brunob/.local/lib/python3.11/site-packages/pyrosm/pyrosm.py", line 249, in get_network
 edges, node_gdf = get_network_data(
                       ^^^^^^^^^^^^^^^^^
File "/home/brunob/.local/lib/python3.11/site-packages/pyrosm/networks.py", line 18, in get_network_data
nodes, ways, relation_ways, relations = get_osm_data(
                                            ^^^^^^^^^^^^^
File "pyrosm/data_manager.pyx", line 175, in pyrosm.data_manager.get_osm_data
File "pyrosm/data_manager.pyx", line 176, in pyrosm.data_manager.get_osm_data
File "pyrosm/data_manager.pyx", line 172, in pyrosm.data_manager._get_osm_data
File "pyrosm/data_manager.pyx", line 130, in pyrosm.data_manager.get_osm_ways_and_relations
File "pyrosm/data_manager.pyx", line 95, in pyrosm.data_manager.get_way_arrays
File "pyrosm/_arrays.pyx", line 93, in pyrosm._arrays.convert_to_arrays_and_drop_empty
File "pyrosm/_arrays.pyx", line 79, in pyrosm._arrays.convert_to_arrays_and_drop_empty
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

What is my error?

Thanks for any help


Solution

  • I solve the problem using osmnx only

    import osmnx as ox
    import networkx as nx
    import os
    import time
    
    def carregar_grafo(lugar, caminho_arquivo):
        if os.path.isfile(caminho_arquivo):
            return ox.load_graphml(caminho_arquivo)
        else:
            G = ox.graph_from_place(lugar, network_type="drive_service")
            ox.save_graphml(G, caminho_arquivo)
            return G
    
    tempo_inicial = time.time()
    
    localizacao = 'estado de São Paulo, Região Sudeste, Brasil'
    
    arquivo = !pwd
    arquivo = str(arquivo[0]) + '/mapas/estado_sp.graphml'
    G = carregar_grafo(localizacao, arquivo)
    
    tempo_final = time.time()
    
    print("--- %s segundos ---" % (tempo_final - tempo_inicial))
    
    
    # impute missing edge speeds and add travel times
    G = ox.add_edge_speeds(G)
    G = ox.add_edge_travel_times(G)
    

    for adresses I use the open street map site, look for right words to ox.graph_from_place function.

    That's it, the pyrosm bib is not updated (until now).