OSMnx:使用替代基础架构创建自定义查询

OSMnx: Creating Custom Queries with Alternative Infrastructures

我一般不熟悉 OSMnx 和立交桥查询。我试图了解在使用非街道基础设施类型时编写自定义查询的正确方法。

具体来说,我正在尝试了解此查询有效的原因

import osmnx as ox

my_custom_filter = '["railway"~"disused"]' 

G = ox.graph_from_point((51.5073509,-0.1277583), 
                      distance = 10000,
                      distance_type = 'bbox', 
                      infrastructure = 'way["railway]',
                      network_type = 'none',
                      custom_filter = my_custom_filter
                       )

但是这个请求错误:

import osmnx as ox

my_custom_filter = '["railway"~"disused"]' 

G = ox.graph_from_point((51.5073509,-0.1277583), 
                      distance = 10000,
                      distance_type = 'bbox', 
                      infrastructure = 'way["railway~"rail"]',
                      network_type = 'none',
                      custom_filter = my_custom_filter
                       )

请注意,区别只是我在后一个查询中将 rail 指定为铁路类型。

请参阅此处 OSM Railway Guide

如果有人能给我指出任何资源,以帮助我进一步了解如何构建自定义过滤器 - 特别是具有多个过滤器的自定义过滤器,那也很好。例如,添加额外的客户过滤器的正确语法是什么。

你只是在你的论点中遗漏了一个 "。这有效:

import osmnx as ox
ox.config(log_console=True, use_cache=True)
point = (51.5073509,-0.1277583)
dist = 10000
dt = 'bbox'
cf = '["railway"~"disused"]' 
G = ox.graph_from_point(point, dist=dist, dist_type=dt, custom_filter=cf)

但它会产生 EmptyOverpassResponse 错误,因为在该搜索区域中没有与您的查询匹配的内容。但是,如果您将其更改为此,您将得到一个图表,例如:

cf = '["railway"!~"disused"]' 
G = ox.graph_from_point(point, dist=dist, dist_type=dt, custom_filter=cf)