Reputation: 55
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
Upvotes: 1
Views: 889
Reputation: 6442
You can use OSMnx to get other types of infrastructure such as canals, railways, powerlines, etc, as described in this example, using the custom_filter
parameter:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_place('Amsterdam', retain_all=False, truncate_by_edge=False,
simplify=True, custom_filter='["waterway"~"canal"]')
fig, ax = ox.plot_graph(G)
Upvotes: 1