Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBOX fix #137

Merged
merged 7 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ VignetteBuilder:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
RoxygenNote: 7.0.0
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# bcdata (development version)

# bcdata 0.1.1.9999
* Fixed a bug where `BBOX()` used in a `filter()` statement combined with `bcdc_query_geodata()` did not work (#135, #137)
* Add `mutate` method for bcdc_promise that only fails and suggest an alternative approach. (PR#134)
* Add back in querying vignette

Expand Down
17 changes: 4 additions & 13 deletions R/cql-geom-predicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#' bcbdc_cql_string accepts the following geometric predicates: EQUALS,
#' DISJOINT, INTERSECTS, TOUCHES, CROSSES, WITHIN, CONTAINS, OVERLAPS, RELATE,
#' DWITHIN, BEYOND, BBOX.
#' @inheritParams RELATE
#' @inheritParams BBOX
#' @inheritParams DWITHIN
#'
#' @seealso sql_geom_predicates
#'
Expand All @@ -51,13 +48,8 @@ bcdc_cql_string <- function(x, geometry_predicates, pattern = NULL,
call. = FALSE)
}


geom_col <- attr(x, "geom_col")
if(is.null(geom_col)) geom_col <- "GEOMETRY"

match.arg(geometry_predicates, cql_geom_predicate_list())


# Only convert x to bbox if not using BBOX CQL function
# because it doesn't take a geom
if (!geometry_predicates == "BBOX") {
Expand Down Expand Up @@ -97,8 +89,6 @@ sf_text <- function(x) {
call. = FALSE)
}



## If too big here, drawing bounding
if(utils::object.size(x) > getOption("bcdata.max_geom_pred_size", 5E5)){
warning("The object is too large to perform exact spatial operations using bcdata.
Expand Down Expand Up @@ -127,7 +117,7 @@ sf_text <- function(x) {
#'
#' @param geom an sf/sfc/sfg object
#' @name cql_geom_predicates
#' @return a CQL expression using the bounding box of the geom
#' @return a CQL expression to be passed on to the WFS call
NULL

#' @rdname cql_geom_predicates
Expand Down Expand Up @@ -194,7 +184,9 @@ RELATE <- function(geom, pattern) {
}

#' @rdname cql_geom_predicates
#' @param coords the coordinates of the bounding box.
#' @param coords the coordinates of the bounding box as four-element numeric
#' vector `c(xmin, ymin, xmax, ymax)`, or a `bbox` object from the `sf`
#' package (the result of running `sf::st_bbox()` on an `sf` object).
#' @param crs (Optional) A string containing an SRS code
#' (For example, 'EPSG:1234'. The default is to use the CRS of the queried layer)
#' @export
Expand Down Expand Up @@ -224,7 +216,6 @@ DWITHIN <- function(geom, distance,
}

#' @rdname cql_geom_predicates
#' @inheritParams DWITHIN
#' @export
BEYOND <- function(geom, distance,
units = c("meters", "feet", "statute miles", "nautical miles", "kilometers")) {
Expand Down
26 changes: 13 additions & 13 deletions R/cql-translator.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ cql_scalar <- dbplyr::sql_translator(
`[` = `[`,
`[[` = `[[`,
`$` = `$`,
DWITHIN = function(x) DWITHIN(x),
EQUALS = function(x) EQUALS(x),
DISJOINT = function(x) DISJOINT(x),
INTERSECTS = function(x) INTERSECTS(x),
TOUCHES = function(x) TOUCHES(x),
CROSSES = function(x) CROSSES(x),
WITHIN = function(x) WITHIN(x),
CONTAINS = function(x) CONTAINS(x),
OVERLAPS = function(x) OVERLAPS(x),
RELATE = function(x) RELATE(x),
DWITHIN = function(x) DWITHIN(x),
BEYOND = function(x) BEYOND(x),
CQL = function(x) CQL(x)
EQUALS = function(geom) EQUALS(geom),
DISJOINT = function(geom) DISJOINT(geom),
INTERSECTS = function(geom) INTERSECTS(geom),
TOUCHES = function(geom) TOUCHES(geom),
CROSSES = function(geom) CROSSES(geom),
WITHIN = function(geom) WITHIN(geom),
CONTAINS = function(geom) CONTAINS(geom),
OVERLAPS = function(geom) OVERLAPS(geom),
RELATE = function(geom, pattern) RELATE(geom, pattern),
DWITHIN = function(geom, distance, units) DWITHIN(geom, distance, units),
BEYOND = function(geom, distance, units) BEYOND(geom, distance, units),
BBOX = function(coords, crs) BBOX(coords, crs),
CQL = function(...) CQL(...)
)

# No aggregation functions available in CQL
Expand Down
2 changes: 1 addition & 1 deletion man/bcdata-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/bcdc_browse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bcdc_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/bcdc_query_geodata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/bcdc_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/bcdc_search_facets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/collect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions man/cql_geom_predicates.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/filter.bcdc_promise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mutate.bcdc_promise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/select.bcdc_promise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/show_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-query-geodata-filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,12 @@ test_that("a BCGW name works with filter", {
collect())
expect_equal(nrow(ret), 367)
})

test_that("Using BBOX works", {
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()
expect_equal(query$query_list$CQL_FILTER,
structure("(BBOX(GEOMETRY, 1639473, 528785.2, 1665979.9, 541201, 'EPSG:3005'))",
class = c("sql", "character")))
})