Skip to content

Commit

Permalink
wrap filter in local to avoid dbplyr issue (see tidyverse/dbplyr#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
meztez committed May 15, 2024
1 parent 556edad commit bef2265
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions R/read_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -100,14 +100,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")
Expand Down Expand Up @@ -141,7 +141,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)

Expand Down Expand Up @@ -178,7 +178,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)

Expand Down Expand Up @@ -214,7 +214,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)

Expand Down Expand Up @@ -252,7 +252,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)

Expand Down Expand Up @@ -288,7 +288,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)

Expand Down Expand Up @@ -362,7 +362,7 @@ read_fire <- function(dsn = NULL, layer = "WHSE_LAND_AND_NATURAL_RESOURCE.PROT_H
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)

Expand Down Expand Up @@ -424,5 +424,3 @@ read_tsa <- function(tsa_name, Skeena_boundary=TRUE){

return(aoi)
}


2 changes: 1 addition & 1 deletion scripts/geodata.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

#

0 comments on commit bef2265

Please sign in to comment.