使用 OSMNX 打开街道地图:如何检索汉诺威地铁网络?

Open Street Map using OSMNX: how to retrieve the Hannover subway network?

import osmnx as ox
ox.__version__ # '0.13.0'

我想显示 subway in Hannover as known in the German subway OSM data on a map using the great OSMNX module. But unlike the New York example 没有返回结果:

G = ox.graph_from_place('Hannover, Germany',
                        retain_all=False, truncate_by_edge=True, simplify=True,
                        network_type='none', custom_filter='["railway"~"subway"]')

# EmptyOverpassResponse: There are no data elements in the response JSON

我确实获得了使用 'Hannover, Germany' 作为区域的其他类似查询的结果。我也没有得到巴黎或伦敦的地铁结果。而且我没有得到类似查询的结果,例如 custom_filter='["railway"~"tram"]' 或 '["railway"~"s-bahn"]' 或 '[ "network"~"metro"]'。

此外,如果我将基础结构关键字参数用于 select "railway",则会返回一个扩展的 gdf:

G = ox.graph_from_place('Hannover, Germany', retain_all=False, truncate_by_edge=True, simplify=True,
                        network_type='none', infrastructure='way["railway"]')
gdfox = ox.graph_to_gdfs(G, nodes=False, edges=True, node_geometry=True, fill_edge_geometry=True)
gdfox.shape # (4422, 14)

但是我无法使用返回的列来识别地铁?:

['u', 'v', 'key', 'osmid', 'service', 'oneway', 'length',
   'geometry', 'name', 'maxspeed', 'ref', 'bridge', 'tunnel',
   'access']

我还觉得奇怪的是,如果我(尝试)使用 custom_filter:

检索所有铁路,则只返回 2 个 LINESTRINGS
G = ox.graph_from_place('Hannover, Germany', retain_all=False, truncate_by_edge=True,
                        simplify=True, network_type=None, custom_filter='["railway"~""]')
gdfox = ox.graph_to_gdfs(G, nodes=False, edges=True, node_geometry=True, fill_edge_geometry=True)
gdfox.shape # (2, 10) # returns only 2 LINESTRINGS: Altenbekener Damm

我正在删除 infrastructure 参数以支持更一致的 custom_filter 参数。将在几天内完成:https://github.com/gboeing/osmnx/pull/477(编辑:在 v0.14.0 中完成并发布;相应地编辑了下面的代码片段。)

同时,我对汉诺威并不熟悉,但它的客运铁路系统似乎被标记为 "tram" 和 "rail" 而不是 "subway"。像这样的东西似乎抓住了它:

import osmnx as ox
ox.config(use_cache=False,
          log_console=True,
          useful_tags_way=ox.settings.useful_tags_way + ['railway'])

G = ox.graph_from_place('Hannover, Germany',
                        retain_all=False, truncate_by_edge=True, simplify=True,
                        custom_filter='["railway"~"tram|rail"]')
len(G) #1776