使用上一个问题的答案(osmextract的结构查询),我想使用R包osmextract从Geofabrik获取整个Europe.osm.pbf的键/标签子集(例如shop=supermarket)。
我想知道是否可以避免 oe_get() 首先将图层的所有特征(例如点、线或多多边形)转换为 gpkg,相反,只需将特征的子集转换为 gpkg(例如仅便利设施=学校)。
之前的回复分两步完成:
这会导致第一步产生可能巨大的 gpkg,然后从中进行选择。如果这两个步骤可以同时完成,将节省处理时间和文件大小。我不习惯使用数据库或类似的工作,这就是为什么我不知道这种过程是否可以使用 pbf 文件,或者是否需要翻译成 gpkg 才能在第一名。
我尝试使用中等大小的 pbf 文件(奥地利)的一些示例代码:
## STEP 1: (Download and) convert data into gpkg. (NB skipping dl here because file already downloaded)
## Each layer (line, multipolygon, point) will be consecutively added to the gpkg 'geofabrik_austria-latest'
oe_get("Austria", layer = "lines", provider = "geofabrik", force_download = FALSE, extra_tags = c("maxspeed", "oneway"), download_only = TRUE)
# This took about 8 minutes with my laptop (pbf filesize 2.5% of Europe.osm.pbf)
oe_get("Austria", layer = "multipolygons", provider = "geofabrik", force_download = FALSE, download_only = TRUE)
# This took about 13 minutes with my laptop (pbf filesize 2.5% of Europe.osm.pbf)
oe_get("Austria", layer = "points", provider = "geofabrik", force_download = FALSE, extra_tags = c("amenity", "shop"), download_only = TRUE)
# This took about 2 minutes with my laptop (pbf filesize 2.5% of Europe.osm.pbf)
# Total processing time: about 23 mins (Europe.osm.pbf file is 40 times bigger and estimated to take 15.3 hrs)
# gpkg file size 5.9 times bigger than pbf filesize (geofabrik_europe-latest.gpkg filesize is estimated 158.4 GB)
## STEP 2: Manipulate gpkg: Select keys/features
austria_roads_lines_gpkg <- oe_get(
place = "Austria",
layer = "lines",
query = "SELECT * FROM lines WHERE highway IN ('motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'unclassified', 'residential', 'motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link', 'living_street', 'service')",
quiet = TRUE
)
austria_shops_multipoly_gpkg <- oe_get(
place = "Austria",
layer = "multipolygons",
query = "SELECT * FROM multipolygons WHERE shop IN ('convenience', 'greengrocer', 'supermarket')",
quiet = TRUE
)
austria_shops_points_gpkg <- oe_get(
place = "Austria",
layer = "points",
query = "SELECT * FROM points WHERE shop IN ('convenience', 'greengrocer', 'supermarket')",
quiet = TRUE
)
如果您仍然能够分享您的解决方案,我们将不胜感激。
谢谢!