Python:如何从OpenStreetMaps中将水路作为图形导入,以便可以使用networkx进行图形分析 [英] Python: How can I import waterways from OpenStreetMaps as a graph so I can do graph analysis with networkx

查看:322
本文介绍了Python:如何从OpenStreetMaps中将水路作为图形导入,以便可以使用networkx进行图形分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先感谢您花时间帮助我:-) 我想从水路创建一个无向图,例如从威尼斯或阿姆斯特丹的运河.

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具有这些城市的水路网络的图形,但是OSMnx软件包没有用于过滤水路的过滤器(或者也许我还不知道;-)).

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)

我认为我可以下载整个地图,然后仅对水路网络进行过滤.但是我不知道该怎么做. OSMnx将是最好的,因为我随即有了一个可以用于networkx功能(例如Dijkstra最短路径)的图形.

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"]

但是这仍然行不通,因为我还没有弄清楚如何过滤数据并将其转换为图形,以便networkx可以使用它.

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.

亲切的问候,

耶罗恩

推荐答案

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))

这篇关于Python:如何从OpenStreetMaps中将水路作为图形导入,以便可以使用networkx进行图形分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆