请参阅此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"]
...和输出:
> brasiliaObject[["osm_polygons"]]["addr.postcode"]
addr.postcode
681474840 71505-765
693119174 71515-030
696548754 71515-020
721414275 <NA>
>