def test_to_graph_api(test_pbf): from pyrosm import OSM import networkx as nx import igraph import pandana osm = OSM(test_pbf) nodes, edges = osm.get_network(nodes=True) # igraph is the default ig = osm.to_graph(nodes, edges) nxg = osm.to_graph(nodes, edges, graph_type="networkx") pdg = osm.to_graph(nodes, edges, graph_type="pandana") assert isinstance(nxg, nx.MultiDiGraph) assert isinstance(ig, igraph.Graph) assert isinstance(pdg, pandana.Network)
def test_graph_exports_correct_number_of_nodes(test_pbf): """ Check issue: #97 """ from pyrosm import OSM osm = OSM(test_pbf) # NetworkX nodes, edges = osm.get_network(nodes=True) node_cnt = len(nodes) nxg = osm.to_graph(nodes, edges, graph_type="networkx", osmnx_compatible=False, retain_all=True) assert node_cnt == nxg.number_of_nodes()
import osmnx as ox from pyrosm import OSM # get real map in PBF fromat from https://extract.bbbike.org/ # install pyrosm and all dependencies via pip install pyrosm osmnx networkx # Initialize the reader osm = OSM("cpii.osm.pbf") # Get all walkable roads and the nodes nodes, edges = osm.get_network(nodes=True, network_type="driving") # Create NetworkX graph G = osm.to_graph(nodes, edges, graph_type="networkx") ccc = edges.head(40) print(ccc.geometry) ox.plot_graph(G)