问题
Thanks at first for actually taking the time to help me :-) I want to create a undirected graph from waterways for example from the canals of Venice or Amsterdam.
OpenStreetMaps has such a graph of a waterway network of these cities, but the OSMnx package does not have such a filter to filter the waterways (or maybe I don't know it yet ;-) ).
import osmnx as ox
G = ox.graph_from_bbox(52.36309012572587,4.890326718121118,52.36590601699889,4.898316757037793, network_type='all')
G_projected = ox.project_graph(G)
ox.plot_graph(G_projected)
I thought I was possible to just download the whole map, and then filter on just the waterway network. But I don't know how to go further about this. OSMnx would be the best as I then immediately have a graph which I can use for functions of networksx such as Dijkstra's shortest path.
Another way I was thinking of was overpass package:
import overpass
import networkx as nx
import matplotlib.pyplot as plt
api= overpass.API()
data = api.get('way(52.36309012572587,4.890326718121118,52.36590601699889,4.898316757037793);(._;>;)', verbosity='geom')
[f for f in data.features if f.geometry['type'] == "LineString"]
But this still doesn't work, because I haven't figured out how to filter the data and transform it to a graph for so that networkx can use it.
Hope you guys (and girls :-) ) can help me, because I have no clue how to go further.
Kind regards,
Jeroen
回答1:
You can use OSMnx to get other types of infrastructure as described in this example. I'm not sure how OSM tags waterways, but here's an example for the NY subway that you can adapt:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
point = (40.73120,-73.98672)
dist = 10000
north, south, east, west = ox.bbox_from_point(point, distance=dist)
G = ox.graph_from_bbox(north=north, south=south, east=east, west=west,
retain_all=True, truncate_by_edge=True, simplify=True,
network_type='none', infrastructure='way["railway"~"subway"]')
fig, ax = ox.plot_graph(ox.project_graph(G))
来源:https://stackoverflow.com/questions/52311549/python-how-can-i-import-waterways-from-openstreetmaps-as-a-graph-so-i-can-do-gr