From 95827a73f7848b83ed3949f9b52ae59d7743b515 Mon Sep 17 00:00:00 2001 From: Bruno Tremblay Date: Fri, 10 May 2024 13:11:02 -0400 Subject: [PATCH] wrap filter in local to avoid dbplyr issue (see https://github.com/tidyverse/dbplyr/issues/1480) --- R/read_layers.R | 22 ++++++++++------------ scripts/geodata.R | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/R/read_layers.R b/R/read_layers.R index bb3363c..0d98b13 100644 --- a/R/read_layers.R +++ b/R/read_layers.R @@ -34,7 +34,7 @@ read_vri <- function(dsn = NULL, layer = "VEG_R1_PLY_polygon", wkt_filter = NULL ) if(length(wkt_filter) > 0 ){ - vri_query <- vri_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + vri_query <- vri_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } vri <- bcdata::collect(vri_query) @@ -99,14 +99,14 @@ read_bem <- function(dsn, layer = "BEM", wkt_filter = NULL) { dsn = dsn, layer = layer, quiet = TRUE, - wkt_filter = if (is.null(wkt_filter)) { + wkt_filter = if (is.null(wkt_filter)) { character(0) } else { - sf::st_as_text(sf::st_as_sfc(wkt_filter)) + sf::st_as_text(sf::st_as_sfc(wkt_filter, crs = sf::st_crs(albers))) } ) if(length(wkt_filter) > 0 ){ - bem <- sf::st_intersection(bem,wkt_filter) + bem <- sf::st_intersection(bem, sf::st_as_sfc(wkt_filter, crs = sf::st_crs(albers))) } #Restructure bem while waiting for real info bem <- rename_geometry(bem, "Shape") @@ -140,7 +140,7 @@ read_wetlands <- function(dsn = NULL, layer = "FWA_WETLANDS_POLY", wkt_filter = bcdata::select(GEOMETRY) if(length(wkt_filter) > 0 ){ - wl_query <- wl_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + wl_query <- wl_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } wetlands <- bcdata::collect(wl_query) @@ -177,7 +177,7 @@ read_rivers <- function(dsn = NULL, layer = "FWA_RIVERS_POLY", wkt_filter = cha bcdata::select(GEOMETRY) if(length(wkt_filter) > 0 ){ - rivers_query <- rivers_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + rivers_query <- rivers_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } rivers <- bcdata::collect(rivers_query) @@ -213,7 +213,7 @@ read_lakes <- function(dsn = NULL, layer = "FWA_LAKES_POLY", wkt_filter = chara bcdata::select(GEOMETRY) if(length(wkt_filter) > 0 ){ - lakes_query <- lakes_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + lakes_query <- lakes_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } lakes <- bcdata::collect(lakes_query) @@ -251,7 +251,7 @@ read_glaciers <- function(dsn = NULL, layer = "BTM_PLU_V1", wkt_filter = charac bcdata::select(GEOMETRY) if(length(wkt_filter) > 0 ){ - glaciers_query <- glaciers_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + glaciers_query <- glaciers_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } glaciers <- bcdata::collect(glaciers_query) @@ -287,7 +287,7 @@ read_ccb <- function(dsn = NULL, layer = "CNS_CUT_BL_polygon", wkt_filter = cha bcdata::select(HARVEST_YEAR) if(length(wkt_filter) > 0 ){ - ccb_query <- ccb_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + ccb_query <- ccb_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } ccb <- bcdata::collect(ccb_query) @@ -323,7 +323,7 @@ read_fire <- function(dsn = NULL, layer = "WHSE_FOREST_VEGETATION_VEG_BURN_SEVER bcdata::select(SHAPE) if(length(wkt_filter) > 0 ){ - wl_query <- wl_query |> bcdata::filter(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter))) + wl_query <- wl_query |> bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sfc(wkt_filter)))) } fire <- bcdata::collect(wl_query) @@ -385,5 +385,3 @@ read_tsa <- function(tsa_name, Skeena_boundary=TRUE){ return(aoi) } - - diff --git a/scripts/geodata.R b/scripts/geodata.R index 710cd86..ebb2f06 100644 --- a/scripts/geodata.R +++ b/scripts/geodata.R @@ -54,6 +54,6 @@ ifelse( "Wetlands id found in search does not match the one in the package" ) wetlands <- bcdata::bcdc_query_geodata(record = wetlands_id) |> - bcdata::filter(bcdata::INTERSECTS(sf::st_as_sf(testing_aoi))) + bcdata::filter(local(bcdata::INTERSECTS(sf::st_as_sf(testing_aoi)))) #