python - OSMnx: 最好在 "gdf_from_place"中指定位置

标签 python osmnx

我在 Python 中使用 OSMnx 来获取州的几何形状(例如奥地利)。但是,OSMnx 有时会选择错误的 OSM 对象作为位置。我可以使用其 ID 指定 OSM 对象吗?

示例:

我使用 OverpassAPI 获取奥地利各州的名称:

(area["ISO3166-1"="{country}"];rel(area)[admin_level="{adminLevel}"];);
out center meta;

这给了我状态列表:

@id @lat    @lon    name
35183   47.2199394  14.8675619  Steiermark
52343   47.1971981  11.5319171  Tirol
52345   46.7517868  13.8605291  Kärnten
74942   47.2184818  9.8839555   Vorarlberg
76909   47.4746574  16.5785134  Burgenland
77189   48.2213684  15.7607387  Niederösterreich
86539   47.4926636  13.0361103  Salzburg
102303  48.1168383  13.8707061  Oberösterreich
109166  48.2202874  16.3796721  Wien

但是当我使用 OSMnx 获取“Salzburg”的几何图形时,我得到的是一个点而不是一个多边形。

>>> outline = osmnx.gdf_from_place("Salzburg")

geometry    place_name
POINT (13.0464806 7.7981346)    Salzburg, 5020, Austria

由于“Salzburg”既是一个城市又是一个州,我想将 OSM ID 放入查询中以使其明确无误。有办法做到这一点吗?

最佳答案

OSMnx 不接受 OSM ID,但您可以指定您是否需要城市或州(甚至 which_result):

import osmnx as ox
outline_city = ox.gdf_from_place({'city':'Salzburg'})
outline_state = ox.gdf_from_place({'state':'Salzburg'})

编辑:请注意,从 OSMnx v0.15.0 开始,gdf_from_placegdf_from_places 函数已被弃用并由 geocode_to_gdf 函数取代。参见 the docs了解详情。

关于python - OSMnx: 最好在 "gdf_from_place"中指定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54789530/

相关文章:

python - 你如何在 Python 中子类化文件类型?

python - 为什么我不能安装 ImageTk

OSMnx : how to provide more complex feature into the custom_filter parameter

python-3.x - AttributeError : dlsym(RTLD_DEFAULT, Error_GetLastErrorNum:找不到符号

gis - 查找某个点最近的道路及其距离

python - 在多处理 pool.starmap 中传递字符串列表时出错

python - 如何在 Pandas 中汇总一列

python - 使用 %matplotlib 笔记本时图形被省略并缩进

python - 如何根据osmnx上的一些 "manually chosen"节点绘制路径?

python - Networkx如何获取多向图中特定边的长度