From 605a5ef0a075ae2b8dcc7f1be165941b6725adef Mon Sep 17 00:00:00 2001 From: StevePem Date: Wed, 14 Aug 2024 09:15:19 +1000 Subject: [PATCH] correct iteration over OSM layers --- functions/getOsmExtract.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/functions/getOsmExtract.R b/functions/getOsmExtract.R index ddbac0d..e9e2613 100644 --- a/functions/getOsmExtract.R +++ b/functions/getOsmExtract.R @@ -30,13 +30,17 @@ getOsmExtract <- function(region, # convert to gpkg, including all layers ('boundary' will clip to bounding box) echo(paste("Converting downloaded OSM extract to .gpkg for selected region\n")) - region.gpkg <- - oe_vectortranslate(full.extract, - layer = st_layers(full.extract)$name, - vectortranslate_options = c("-t_srs", - paste0("EPSG:", outputCrs)), - boundary = region.buffer, - boundary_type = "spat") # 'spat' should intersect rather than clip, but still seems to clip + layers <- st_layers(full.extract)$name + for(i in 1:length(layers)) { + layer <- layers[i] + region.gpkg <- + oe_vectortranslate(full.extract, + layer = layer, + vectortranslate_options = c("-t_srs", + paste0("EPSG:", outputCrs)), + boundary = region.buffer, + boundary_type = "spat") # 'spat' should intersect rather than clip, but still seems to clip + } # intersect with region buffer, eliminating errors and save to permanent location for (i in 1:length(st_layers(region.gpkg)$name)) {