我尝试使用以下代码来检索给定sf对象的邮政编码:
library(osmdata)
library(tidyverse)
x <- getbb("Rio de Janeiro") %>%
opq() %>%
add_osm_feature(key = 'boundary', value = 'postal_code') %>%
osmdata_sf()但是,当我运行它时,我得到了以下结果:
Object of class 'osmdata' with:
$bbox : -23.0827051,-43.796252,-22.7460878,-43.0990811
$overpass_call : The call submitted to the overpass API
$meta : metadata including timestamp and version numbers
$osm_points : 'sf' Simple Features Collection with 0 points
$osm_lines : NULL
$osm_polygons : 'sf' Simple Features Collection with 0 polygons
$osm_multilines : NULL
$osm_multipolygons : NULL我希望收到一个带有多边形和相应邮政编码的sf对象,但它只返回这个空集。我做错了什么?
发布于 2020-07-01 06:33:07
有关更多上下文,请参阅此post和此link (来自该帖子)。基本上,您的代码可以正常工作,但是德国以外的几个映射器已经映射了boundary=postal_code。
在柏林进行测试表明,那里有很多结果。根据上面链接中的小地图,巴西利亚似乎是巴西唯一一个绘制了邮政编码边界的地方。我们在那里也得到了一些结果,但要少得多。
柏林
x <- getbb("Berlin") %>%
opq() %>%
add_osm_feature(key = 'boundary', value = 'postal_code',
value_exact = F, key_exact = F) %>%
osmdata_sf()
x
Object of class 'osmdata' with:
$bbox : 52.3382448,13.088345,52.6755087,13.7611609
$overpass_call : The call submitted to the overpass API
$meta : metadata including timestamp and version numbers
$osm_points : 'sf' Simple Features Collection with 36128 points
$osm_lines : 'sf' Simple Features Collection with 1677 linestrings
$osm_polygons : 'sf' Simple Features Collection with 1 polygons
$osm_multilines : NULL
$osm_multipolygons : 'sf' Simple Features Collection with 231 multipolygons巴西利亚
y <- getbb("Brasilia") %>%
opq() %>%
add_osm_feature(key = 'boundary', value = 'postal_code',
value_exact = F, key_exact = F) %>%
osmdata_sf()
y
Object of class 'osmdata' with:
$bbox : -15.8589663,-48.0895565,-15.5781078,-47.7828767
$overpass_call : The call submitted to the overpass API
$meta : metadata including timestamp and version numbers
$osm_points : 'sf' Simple Features Collection with 15 points
$osm_lines : NULL
$osm_polygons : 'sf' Simple Features Collection with 4 polygons
$osm_multilines : NULL
$osm_multipolygons : NULL如果将查询保存到对象,则可以按如下方式访问邮政编码数据:
y <- getbb("Brasilia") %>%
opq() %>%
add_osm_feature(key = 'boundary', value = 'postal_code',
value_exact = F, key_exact = F) %>%
osmdata_sf() -> brasiliaObject
brasiliaObject[["osm_polygons"]]["addr.postcode"]对输出执行...and操作:
> brasiliaObject[["osm_polygons"]]["addr.postcode"]
addr.postcode
681474840 71505-765
693119174 71515-030
696548754 71515-020
721414275 <NA>
>https://stackoverflow.com/questions/62666345
复制相似问题