尝试使用OSMnx标签”element_type”来检索多边形内包含的所有”way”对象。

huangapple go评论56阅读模式
英文:

Trying to use the OSMnx tag "element_type" to retrieve all the "way" objects contained within a polygon

问题

我尝试通过调用标签"element_type":"way"来获取包含在一个多边形中的所有结构(多边形),但似乎无法使其工作。

我尝试了下面的代码来尝试获取多边形内的所有element_type:way,但它返回一个空的gdf。

polygon = disolved_ellipses_gpd.iloc[0]["geometry"]
tags = {"element_type":"way"}
new_gdf = ox.geometries_from_polygon(polygon, tags)
new_gdf.shape

我还尝试了这段代码,试图仅筛选掉非element_type:way,但我收到了一个KeyError:"element_type"。

polygon = disolved_ellipses_gpd.iloc[0]["geometry"]
tags = {"building":True}
new_gdf = ox.geometries_from_polygon(polygon, tags)
new_gdf.shape
new_gdf[new_gdf["element_type"] == "way"].dropna(axis=1, how="any")

我不确定是我在某个地方搞砸了,还是你只是无法基于"element_type"来调用。我尝试搜索文档,但找不到任何信息。

英文:

I'm trying to get all the structures (polygons) contained within a set polygon by calling for the tag "element_type":"way" but I can't seem to get it to work.

I've tried the code below to try to get all the element_type:way inside the polygon but it returns an empty gdf.

polygon = disolved_ellipses_gpd.iloc[0]["geometry"]
tags = {"element_type":"way"}
new_gdf = ox.geometries_from_polygon(polygon, tags)
new_gdf.shape

I also tried this code in an attempt to just filter out the non element_type:way but I get a KeyError: "element_type".

polygon = disolved_ellipses_gpd.iloc[0]["geometry"]
tags = {"building":True}
new_gdf = ox.geometries_from_polygon(polygon, tags)
new_gdf.shape
new_gdf[new_gdf["element_type"] == "way"].dropna(axis=1, how="any")

I'm not sure if I'm screwed up somewhere or if you just can't call based on the "element_type". I tried searching through the documentation but couldn't find anything.

答案1

得分: 1

There is almost certainly a better way, but I blundered into this solution:

gdf = ox.geometries_from_point((lat, lon), dist=distance, tags=tags)
print(len(gdf))   # 返回行数?

# 尝试提取OSM ID - 令人惊讶地困难
element_type = gdf.axes[0].values[0][0]
osmid = gdf.axes[0].values[0][1]

For some reason, this syntax simply fails:

gdf['element_type']

Perhaps @gboeing may offer a better solution.

英文:

There is almost certainly a better way, but I blundered into this solution:

gdf = ox.geometries_from_point( (lat, lon), dist=distance, tags=tags)
print ( len ( gdf ) )   # Returns the number of rows?

# Try to extract the OSM ID - surprisingly diffculty
element_type = gdf.axes[0].values[0][0] 
osmid = gdf.axes[0].values[0][1]

For some reason, this syntax simply fails:

gdf [ 'element_type' ]

Perhaps @gboeing may offer a better solution.

huangapple
  • 本文由 发表于 2023年3月4日 02:42:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定