From 4b64a26516f0c97ea48473aff66a40d5f07d658a Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Mon, 9 Dec 2019 17:45:21 -0800 Subject: [PATCH 01/13] DWITHIN and BEYOND like unquoted unit names --- R/cql-geom-predicates.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cql-geom-predicates.R b/R/cql-geom-predicates.R index c223899e..b96e4d2a 100644 --- a/R/cql-geom-predicates.R +++ b/R/cql-geom-predicates.R @@ -63,7 +63,7 @@ bcdc_cql_string <- function(x, geometry_predicates, pattern = NULL, if (!is.null(crs)) paste0(", '", crs, "'") ) } else if (geometry_predicates %in% c("DWITHIN", "BEYOND")) { - paste0(x, ", ", distance, ", '", units, "'") + paste0(x, ", ", distance, ", ", units, "") } else if (geometry_predicates == "RELATE") { paste0(x, ", '", pattern, "'") } else { From 9cc2c7ad229aa4699f81373d6acbcfa275724d5c Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Mon, 9 Dec 2019 17:48:57 -0800 Subject: [PATCH 02/13] eval nested functions --- R/cql-translator.R | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/R/cql-translator.R b/R/cql-translator.R index 421f5369..4bc58fea 100644 --- a/R/cql-translator.R +++ b/R/cql-translator.R @@ -22,10 +22,27 @@ cql_translate <- function(...) { ## predicates and CQL() expressions are evaluated into valid CQL code ## so they can be combined with the rest of the query dots <- lapply(dots, function(x) { + + # make sure all arguments are named in the call so can be modified + x <- rlang::call_standardise(x, env = rlang::get_env(x)) + + # if an argument to a predicate is a call itself, need to evaluate it + # locally, as by default all functions are treated as remote and thus + # not evaluated. + # See ?rlang::partial_eval and https://github.com/bcgov/bcdata/issues/146 + for (call_arg in rlang::call_args_names(x)) { + if (is.call(rlang::call_args(x)[[call_arg]])) { + arg_eval <- rlang::eval_tidy(rlang::call_args(x)[[call_arg]], + env = rlang::get_env(x)) + x <- rlang::call_modify(x, !!call_arg := arg_eval) + } + } + rlang::new_quosure( dbplyr::partial_eval(rlang::get_expr(x), env = rlang::get_env(x)), - rlang::get_env(x)) + rlang::get_env(x)) }) + sql_where <- dbplyr::translate_sql_(dots, con = cql_dummy_con, window = FALSE) build_where(sql_where) } From 2242424c41826aa05dc9def4a6c6a314aa682ef0 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Mon, 9 Dec 2019 17:49:25 -0800 Subject: [PATCH 03/13] tests for CQL predicates with nested functions --- tests/testthat/test-query-geodata-filter.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-query-geodata-filter.R b/tests/testthat/test-query-geodata-filter.R index 7f4227e6..52645eb0 100644 --- a/tests/testthat/test-query-geodata-filter.R +++ b/tests/testthat/test-query-geodata-filter.R @@ -237,3 +237,20 @@ test_that("Using BBOX works", { structure("(BBOX(GEOMETRY, 1639473, 528785.2, 1665979.9, 541201, 'EPSG:3005'))", class = c("sql", "character"))) }) + +test_that("Nesting functions inside a CQL geometry predicate works (#146)", { + the_geom <- st_sfc(st_point(c(1164434.444, 368738.74)), + st_point(c(1203023.699, 412959.018)), + crs = 3005) + + qry <- bcdc_query_geodata("local-and-regional-greenspaces") %>% + filter(BBOX(st_bbox(the_geom), crs = paste0("EPSG:", st_crs(the_geom)$epsg))) %>% + show_query() + + expect_equal(qry$query_list$CQL_FILTER, + "(BBOX(SHAPE, 1164434.444, 368738.74, 1203023.699, 412959.018, 'EPSG:3005'))") + + bcdc_query_geodata("local-and-regional-greenspaces") %>% + filter(DWITHIN(the_geom, 100, "meters")) %>% + show_query() +}) From 56f19159df3747cd9ab5cbecdaae227cff5c3d53 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Mon, 9 Dec 2019 17:49:43 -0800 Subject: [PATCH 04/13] scratch --- scratch/multipoint.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 scratch/multipoint.R diff --git a/scratch/multipoint.R b/scratch/multipoint.R new file mode 100644 index 00000000..58431bbf --- /dev/null +++ b/scratch/multipoint.R @@ -0,0 +1,13 @@ + +format_multipoint <- function(x) { + x <- gsub("(\\(\\d+(\\.)?\\d*)", "(\\1", x) + x <- gsub("(\\d+),\\s*", "\\1), (", x) + gsub("(\\))$", "\\1)", x) +} + +format_wkt("MULTIPOINT (1164434 368738.7, 1203024 412959)") +format_wkt("POINT (1164434 368738.7)") +format_wkt("MULTIPOINT (1164434 368738.7, 1203024 412959, 1203025 412960)") +format_wkt("MULTIPOINT (1164434 368738.7 20, 1203024 412959 50, 1203025 412960 100)") + +st_as_text(st_as_sfc("MULTIPOINT ((10 10), (20 20))")) From 9ec168a67ffa4258a2aa4f66e758b36e7b70b17f Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Tue, 10 Dec 2019 16:55:05 -0800 Subject: [PATCH 05/13] fix tests for DWITHIN & BEYOND (unquoted units) --- tests/testthat/test-cql-string.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-cql-string.R b/tests/testthat/test-cql-string.R index 80c8fef9..ff9fbd2e 100644 --- a/tests/testthat/test-cql-string.R +++ b/tests/testthat/test-cql-string.R @@ -41,15 +41,15 @@ test_that("All cql geom predicate functions work", { } expect_equal( DWITHIN(the_geom, 1), #default units meters - CQL("DWITHIN({geom_name}, POINT (1 1), 1, 'meters')") + CQL("DWITHIN({geom_name}, POINT (1 1), 1, meters)") ) expect_equal( DWITHIN(the_geom, 1, "meters"), - CQL("DWITHIN({geom_name}, POINT (1 1), 1, 'meters')") + CQL("DWITHIN({geom_name}, POINT (1 1), 1, meters)") ) expect_equal( BEYOND(the_geom, 1, "feet"), - CQL("BEYOND({geom_name}, POINT (1 1), 1, 'feet')") + CQL("BEYOND({geom_name}, POINT (1 1), 1, feet)") ) expect_equal( RELATE(the_geom, "*********"), From c15a1322ad59466c51930d2bb6809d3e93e9d270 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Tue, 10 Dec 2019 17:07:45 -0800 Subject: [PATCH 06/13] More tests for #146 --- tests/testthat/test-query-geodata-filter.R | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-query-geodata-filter.R b/tests/testthat/test-query-geodata-filter.R index 52645eb0..e221ce9b 100644 --- a/tests/testthat/test-query-geodata-filter.R +++ b/tests/testthat/test-query-geodata-filter.R @@ -230,6 +230,8 @@ test_that("a BCGW name works with filter", { }) test_that("Using BBOX works", { + skip_on_cran() + skip_if_net_down() query <- bcdc_query_geodata("WHSE_FOREST_VEGETATION.BEC_BIOGEOCLIMATIC_POLY", crs = 4326) %>% filter(BBOX(c(1639473.0,528785.2,1665979.9,541201.0), crs = "EPSG:3005")) %>% show_query() @@ -239,18 +241,23 @@ test_that("Using BBOX works", { }) test_that("Nesting functions inside a CQL geometry predicate works (#146)", { - the_geom <- st_sfc(st_point(c(1164434.444, 368738.74)), - st_point(c(1203023.699, 412959.018)), + skip_on_cran() + skip_if_net_down() + the_geom <- st_sfc(st_point(c(1164434, 368738)), + st_point(c(1203023, 412959)), crs = 3005) qry <- bcdc_query_geodata("local-and-regional-greenspaces") %>% filter(BBOX(st_bbox(the_geom), crs = paste0("EPSG:", st_crs(the_geom)$epsg))) %>% show_query() - expect_equal(qry$query_list$CQL_FILTER, - "(BBOX(SHAPE, 1164434.444, 368738.74, 1203023.699, 412959.018, 'EPSG:3005'))") + expect_equal(as.character(qry$query_list$CQL_FILTER), + "(BBOX(SHAPE, 1164434, 368738, 1203023, 412959, 'EPSG:3005'))") - bcdc_query_geodata("local-and-regional-greenspaces") %>% - filter(DWITHIN(the_geom, 100, "meters")) %>% + qry2 <- bcdc_query_geodata("local-and-regional-greenspaces") %>% + filter(DWITHIN(st_buffer(the_geom, 10, nQuadSegs = 2), 100, "meters")) %>% show_query() + + expect_equal(as.character(qry2$query_list$CQL_FILTER), + "(DWITHIN(SHAPE, MULTIPOLYGON (((1164444 368738, 1164441 368730.9, 1164434 368728, 1164427 368730.9, 1164424 368738, 1164427 368745.1, 1164434 368748, 1164441 368745.1, 1164444 368738)), ((1203033 412959, 1203030 412951.9, 1203023 412949, 1203016 412951.9, 1203013 412959, 1203016 412966.1, 1203023 412969, 1203030 412966.1, 1203033 412959))), 100, meters))") }) From 7b1a93ccc1d56914191812e538f13fbe7de1d9a0 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Thu, 12 Dec 2019 12:59:57 -0800 Subject: [PATCH 07/13] Use call2 to wrap function calls in local() Instead of early evaluation of nested calls as previously attempted, modify the call to wrap nested calls in local() so that dbplyr::partial_eval knows to evaluate them. #146 --- R/cql-translator.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/cql-translator.R b/R/cql-translator.R index 4bc58fea..6a68859e 100644 --- a/R/cql-translator.R +++ b/R/cql-translator.R @@ -26,24 +26,24 @@ cql_translate <- function(...) { # make sure all arguments are named in the call so can be modified x <- rlang::call_standardise(x, env = rlang::get_env(x)) - # if an argument to a predicate is a call itself, need to evaluate it + # if an argument to a predicate is a function call, need to tell it to evaluate # locally, as by default all functions are treated as remote and thus - # not evaluated. + # not evaluated. Do this by using `rlang::call2` to wrap the function call in + # local() # See ?rlang::partial_eval and https://github.com/bcgov/bcdata/issues/146 for (call_arg in rlang::call_args_names(x)) { if (is.call(rlang::call_args(x)[[call_arg]])) { - arg_eval <- rlang::eval_tidy(rlang::call_args(x)[[call_arg]], - env = rlang::get_env(x)) - x <- rlang::call_modify(x, !!call_arg := arg_eval) + x <- rlang::call_modify( + x, !!call_arg := rlang::call2("local", rlang::call_args(x)[[call_arg]]) + ) } } - rlang::new_quosure( - dbplyr::partial_eval(rlang::get_expr(x), env = rlang::get_env(x)), - rlang::get_env(x)) + rlang::new_quosure(dbplyr::partial_eval(x), rlang::get_env(x)) }) sql_where <- dbplyr::translate_sql_(dots, con = cql_dummy_con, window = FALSE) + build_where(sql_where) } From 8fe02ec9d40c0c75a7ccda899399cb50946bb21d Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Thu, 12 Dec 2019 13:09:35 -0800 Subject: [PATCH 08/13] Import := from rlang, document and fix test --- NAMESPACE | 1 + R/cql-translator.R | 2 ++ tests/testthat/test-query-geodata-filter.R | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3abe9115..60413ef8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -79,4 +79,5 @@ importFrom(readr,read_csv) importFrom(readr,read_tsv) importFrom(readxl,read_xls) importFrom(readxl,read_xlsx) +importFrom(rlang,":=") importFrom(sf,read_sf) diff --git a/R/cql-translator.R b/R/cql-translator.R index 6a68859e..cd515b97 100644 --- a/R/cql-translator.R +++ b/R/cql-translator.R @@ -10,6 +10,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. +#' @importFrom rlang := + # Function to translate R code to CQL cql_translate <- function(...) { ## convert dots to list of quosures diff --git a/tests/testthat/test-query-geodata-filter.R b/tests/testthat/test-query-geodata-filter.R index e221ce9b..0962e02c 100644 --- a/tests/testthat/test-query-geodata-filter.R +++ b/tests/testthat/test-query-geodata-filter.R @@ -255,9 +255,9 @@ test_that("Nesting functions inside a CQL geometry predicate works (#146)", { "(BBOX(SHAPE, 1164434, 368738, 1203023, 412959, 'EPSG:3005'))") qry2 <- bcdc_query_geodata("local-and-regional-greenspaces") %>% - filter(DWITHIN(st_buffer(the_geom, 10, nQuadSegs = 2), 100, "meters")) %>% + filter(DWITHIN(st_buffer(the_geom, 10000, nQuadSegs = 2), 100, "meters")) %>% show_query() expect_equal(as.character(qry2$query_list$CQL_FILTER), - "(DWITHIN(SHAPE, MULTIPOLYGON (((1164444 368738, 1164441 368730.9, 1164434 368728, 1164427 368730.9, 1164424 368738, 1164427 368745.1, 1164434 368748, 1164441 368745.1, 1164444 368738)), ((1203033 412959, 1203030 412951.9, 1203023 412949, 1203016 412951.9, 1203013 412959, 1203016 412966.1, 1203023 412969, 1203030 412966.1, 1203033 412959))), 100, meters))") + "(DWITHIN(SHAPE, MULTIPOLYGON (((1174434 368738, 1171505 361666.9, 1164434 358738, 1157363 361666.9, 1154434 368738, 1157363 375809.1, 1164434 378738, 1171505 375809.1, 1174434 368738)), ((1213023 412959, 1210094 405887.9, 1203023 402959, 1195952 405887.9, 1193023 412959, 1195952 420030.1, 1203023 422959, 1210094 420030.1, 1213023 412959))), 100, meters))") }) From 711b385ead3a7428d82587572d6c79a9c7f6eb13 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Thu, 12 Dec 2019 13:48:19 -0800 Subject: [PATCH 09/13] RELATE string should also be unquoted --- R/cql-geom-predicates.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cql-geom-predicates.R b/R/cql-geom-predicates.R index b96e4d2a..a44bd8ea 100644 --- a/R/cql-geom-predicates.R +++ b/R/cql-geom-predicates.R @@ -65,7 +65,7 @@ bcdc_cql_string <- function(x, geometry_predicates, pattern = NULL, } else if (geometry_predicates %in% c("DWITHIN", "BEYOND")) { paste0(x, ", ", distance, ", ", units, "") } else if (geometry_predicates == "RELATE") { - paste0(x, ", '", pattern, "'") + paste0(x, ", ", pattern) } else { x } From e4063f5f914c8f9141216e6e5cce8909a939b977 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Thu, 12 Dec 2019 13:51:44 -0800 Subject: [PATCH 10/13] Test for RELATE --- tests/testthat/test-geom-operators.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-geom-operators.R b/tests/testthat/test-geom-operators.R index 0c55e6a3..a3e199a6 100644 --- a/tests/testthat/test-geom-operators.R +++ b/tests/testthat/test-geom-operators.R @@ -49,4 +49,20 @@ test_that("INTERSECT works",{ }) +test_that("RELATE works", { + skip_on_cran() + skip_if_net_down() + local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>% + filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>% + collect() + + remote <- suppressWarnings( + bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>% + filter(RELATE(local, "*********")) %>% + collect() + ) + + expect_is(remote, "sf") + expect_equal(attr(remote, "sf_column"), "geometry") +}) From 8bb8d7e5ff6b90654803ef0b66bd8d14d06d95f4 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Fri, 13 Dec 2019 09:09:56 -0800 Subject: [PATCH 11/13] Don't export or test RELATE. #154 --- NAMESPACE | 1 - R/cql-geom-predicates.R | 4 ++-- man/cql_geom_predicates.Rd | 7 ------- tests/testthat/test-cql-string.R | 2 +- tests/testthat/test-geom-operators.R | 1 + 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 60413ef8..070eb7fd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,7 +39,6 @@ export(DWITHIN) export(EQUALS) export(INTERSECTS) export(OVERLAPS) -export(RELATE) export(TOUCHES) export(WITHIN) export(bcdc_browse) diff --git a/R/cql-geom-predicates.R b/R/cql-geom-predicates.R index a44bd8ea..c7f7dcb4 100644 --- a/R/cql-geom-predicates.R +++ b/R/cql-geom-predicates.R @@ -22,7 +22,7 @@ #' @param x object of class sf, sfc or sfg #' @param geometry_predicates Geometry predicates that allow for spatial filtering. #' bcbdc_cql_string accepts the following geometric predicates: EQUALS, -#' DISJOINT, INTERSECTS, TOUCHES, CROSSES, WITHIN, CONTAINS, OVERLAPS, RELATE, +#' DISJOINT, INTERSECTS, TOUCHES, CROSSES, WITHIN, CONTAINS, OVERLAPS, #' DWITHIN, BEYOND, BBOX. #' #' @seealso sql_geom_predicates @@ -172,7 +172,7 @@ OVERLAPS <- function(geom) { #' @param pattern spatial relationship specified by a DE-9IM matrix pattern. #' A DE-9IM pattern is a string of length 9 specified using the characters #' `*TF012`. Example: `'1*T***T**'` -#' @export +#' @noRd RELATE <- function(geom, pattern) { if (!is.character(pattern) || length(pattern) != 1L || diff --git a/man/cql_geom_predicates.Rd b/man/cql_geom_predicates.Rd index 6872e9e5..005f7ce1 100644 --- a/man/cql_geom_predicates.Rd +++ b/man/cql_geom_predicates.Rd @@ -10,7 +10,6 @@ \alias{WITHIN} \alias{CONTAINS} \alias{OVERLAPS} -\alias{RELATE} \alias{BBOX} \alias{DWITHIN} \alias{BEYOND} @@ -32,8 +31,6 @@ CONTAINS(geom) OVERLAPS(geom) -RELATE(geom, pattern) - BBOX(coords, crs = NULL) DWITHIN( @@ -51,10 +48,6 @@ BEYOND( \arguments{ \item{geom}{an sf/sfc/sfg object} -\item{pattern}{spatial relationship specified by a DE-9IM matrix pattern. -A DE-9IM pattern is a string of length 9 specified using the characters -\verb{*TF012}. Example: \code{'1*T***T**'}} - \item{coords}{the coordinates of the bounding box as four-element numeric vector \code{c(xmin, ymin, xmax, ymax)}, or a \code{bbox} object from the \code{sf} package (the result of running \code{sf::st_bbox()} on an \code{sf} object).} diff --git a/tests/testthat/test-cql-string.R b/tests/testthat/test-cql-string.R index ff9fbd2e..ea366232 100644 --- a/tests/testthat/test-cql-string.R +++ b/tests/testthat/test-cql-string.R @@ -53,7 +53,7 @@ test_that("All cql geom predicate functions work", { ) expect_equal( RELATE(the_geom, "*********"), - CQL("RELATE({geom_name}, POINT (1 1), '*********')") + CQL("RELATE({geom_name}, POINT (1 1), *********)") ) expect_equal( BBOX(c(1,2,1,2)), diff --git a/tests/testthat/test-geom-operators.R b/tests/testthat/test-geom-operators.R index a3e199a6..111f3ee4 100644 --- a/tests/testthat/test-geom-operators.R +++ b/tests/testthat/test-geom-operators.R @@ -50,6 +50,7 @@ test_that("INTERSECT works",{ }) test_that("RELATE works", { + skip("RELATE not supported. https://github.com/bcgov/bcdata/pull/154") skip_on_cran() skip_if_net_down() local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>% From e00b5a6c60f9ae6c6d74e787ceca05e4adcaf0c0 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Fri, 13 Dec 2019 10:25:16 -0800 Subject: [PATCH 12/13] BEYOND not supported, don't export/test --- NAMESPACE | 1 - R/cql-geom-predicates.R | 5 ++-- man/cql_geom_predicates.Rd | 7 ----- tests/testthat/test-geom-operators.R | 45 +++++++++++++++++++++------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 070eb7fd..26cefa64 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,7 +30,6 @@ S3method(sql_escape_string,DummyCQL) S3method(sql_translate_env,DummyCQL) export("%>%") export(BBOX) -export(BEYOND) export(CONTAINS) export(CQL) export(CROSSES) diff --git a/R/cql-geom-predicates.R b/R/cql-geom-predicates.R index c7f7dcb4..e20dec94 100644 --- a/R/cql-geom-predicates.R +++ b/R/cql-geom-predicates.R @@ -23,7 +23,7 @@ #' @param geometry_predicates Geometry predicates that allow for spatial filtering. #' bcbdc_cql_string accepts the following geometric predicates: EQUALS, #' DISJOINT, INTERSECTS, TOUCHES, CROSSES, WITHIN, CONTAINS, OVERLAPS, -#' DWITHIN, BEYOND, BBOX. +#' DWITHIN, BBOX. #' #' @seealso sql_geom_predicates #' @@ -216,7 +216,8 @@ DWITHIN <- function(geom, distance, } #' @rdname cql_geom_predicates -#' @export +#' @noRd +# https://osgeo-org.atlassian.net/browse/GEOS-8922 BEYOND <- function(geom, distance, units = c("meters", "feet", "statute miles", "nautical miles", "kilometers")) { if (!is.numeric(distance)) { diff --git a/man/cql_geom_predicates.Rd b/man/cql_geom_predicates.Rd index 005f7ce1..011d4d5e 100644 --- a/man/cql_geom_predicates.Rd +++ b/man/cql_geom_predicates.Rd @@ -12,7 +12,6 @@ \alias{OVERLAPS} \alias{BBOX} \alias{DWITHIN} -\alias{BEYOND} \title{CQL Geometry Predicates} \usage{ EQUALS(geom) @@ -38,12 +37,6 @@ DWITHIN( distance, units = c("meters", "feet", "statute miles", "nautical miles", "kilometers") ) - -BEYOND( - geom, - distance, - units = c("meters", "feet", "statute miles", "nautical miles", "kilometers") -) } \arguments{ \item{geom}{an sf/sfc/sfg object} diff --git a/tests/testthat/test-geom-operators.R b/tests/testthat/test-geom-operators.R index 111f3ee4..ae9c3243 100644 --- a/tests/testthat/test-geom-operators.R +++ b/tests/testthat/test-geom-operators.R @@ -12,12 +12,15 @@ context("Geometric operators work with appropriate data") -test_that("WITHIN works",{ - skip_on_cran() - skip_if_net_down() +if (has_internet() && identical(Sys.getenv("NOT_CRAN"), "true")) { local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>% filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>% collect() +} + +test_that("WITHIN works",{ + skip_on_cran() + skip_if_net_down() remote <- suppressWarnings( bcdc_query_geodata("bc-airports") %>% @@ -27,16 +30,12 @@ test_that("WITHIN works",{ expect_is(remote, "sf") expect_equal(attr(remote, "sf_column"), "geometry") - }) test_that("INTERSECT works",{ skip_on_cran() skip_if_net_down() - local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>% - filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>% - collect() remote <- suppressWarnings( bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>% @@ -53,9 +52,6 @@ test_that("RELATE works", { skip("RELATE not supported. https://github.com/bcgov/bcdata/pull/154") skip_on_cran() skip_if_net_down() - local <- bcdc_query_geodata("regional-districts-legally-defined-administrative-areas-of-bc") %>% - filter(ADMIN_AREA_NAME == "Cariboo Regional District") %>% - collect() remote <- suppressWarnings( bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>% @@ -67,3 +63,32 @@ test_that("RELATE works", { expect_equal(attr(remote, "sf_column"), "geometry") }) +test_that("DWITHIN works", { + skip_on_cran() + skip_if_net_down() + + remote <- suppressWarnings( + bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>% + filter(DWITHIN(local, 100, "meters")) %>% + collect() + ) + + expect_is(remote, "sf") + expect_equal(attr(remote, "sf_column"), "geometry") +}) + +test_that("BEYOND works", { + skip("BEYOND currently not supported") + # https://osgeo-org.atlassian.net/browse/GEOS-8922 + skip_on_cran() + skip_if_net_down() + + remote <- suppressWarnings( + bcdc_query_geodata("bc-parks-ecological-reserves-and-protected-areas") %>% + filter(BEYOND(local, 100, "meters")) %>% + collect() + ) + + expect_is(remote, "sf") + expect_equal(attr(remote, "sf_column"), "geometry") +}) From 58bfe438a53327a48796af2e64a262e2abb2e5c3 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Fri, 13 Dec 2019 10:25:24 -0800 Subject: [PATCH 13/13] Update NEWS --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 04967acb..9226d985 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ * Add `bcdc_tidy_resources` for retrieving a data frame containing the metadata for all resources from a single B.C. Data Catalogue record (PR#149, #147) * Add a more decorative record print method (#73) +* Remove `BEYOND()` and `RELATE()` geometry predicates as they are currently +not fully supported by geoserver +* Fixed a bug where functions nested inside geometry predicates were not evaluated (#146, #154) +* Fixed a bug where `DWITHIN` wasn't working because `units` needed to be unqoted (#154) # bcdata 0.1.1.9999