diff --git a/R/check.R b/R/check.R index e941d8ad..fd557455 100644 --- a/R/check.R +++ b/R/check.R @@ -137,14 +137,23 @@ check_bbox <- function( query_crs <- check_crs(data_query) ref_crs <- check_crs(reference) + if (is.null(reference_crs)) { + reference <- + sf::st_as_sfc( + sf::st_bbox(reference), + crs = ref_crs + ) + } if (is.na(query_crs) || is.null(query_crs)) { stop("The dataset you queried has no CRS. Please make sure your dataset has the correct CRS.\n") } - data_query_bb <- sf::st_bbox(data_query) + data_query_bb <- + sf::st_as_sfc(sf::st_bbox(data_query), + crs = sf::st_crs(data_query)) query_matched <- sf::st_transform(data_query_bb, sf::st_crs(ref_crs)) - check_result <- sf::st_within(query_matched, reference) + check_result <- as.logical(unlist(sf::st_within(query_matched, reference))) return(check_result) } diff --git a/scomps_rmarkdown_litr.rmd b/scomps_rmarkdown_litr.rmd index af9c433b..1f3dd9c8 100644 --- a/scomps_rmarkdown_litr.rmd +++ b/scomps_rmarkdown_litr.rmd @@ -943,14 +943,23 @@ check_bbox <- function( query_crs <- check_crs(data_query) ref_crs <- check_crs(reference) + if (is.null(reference_crs)) { + reference <- + sf::st_as_sfc( + sf::st_bbox(reference), + crs = ref_crs + ) + } if (is.na(query_crs) || is.null(query_crs)) { stop("The dataset you queried has no CRS. Please make sure your dataset has the correct CRS.\n") } - data_query_bb <- sf::st_bbox(data_query) + data_query_bb <- + sf::st_as_sfc(sf::st_bbox(data_query), + crs = sf::st_crs(data_query)) query_matched <- sf::st_transform(data_query_bb, sf::st_crs(ref_crs)) - check_result <- sf::st_within(query_matched, reference) + check_result <- as.logical(unlist(sf::st_within(query_matched, reference))) return(check_result) } @@ -968,7 +977,7 @@ testthat::test_that("Check bbox abides.", { nc <- system.file(package = "sf", "shape/nc.shp") nc <- sf::read_sf(nc) nc <- sf::st_transform(nc, "EPSG:5070") - ncp <- sf::read_sf("../testdata/nc_random_point.rds") + ncp <- readRDS(testthat::test_path("..", "testdata", "nc_random_point.rds")) ncp <- sf::st_transform(ncp, "EPSG:5070") testthat::expect_no_error(check_bbox(ncp, nc)) diff --git a/tests/testthat/tests.R b/tests/testthat/tests.R index a00069d2..571e2307 100644 --- a/tests/testthat/tests.R +++ b/tests/testthat/tests.R @@ -204,7 +204,7 @@ testthat::test_that("Check bbox abides.", { nc <- system.file(package = "sf", "shape/nc.shp") nc <- sf::read_sf(nc) nc <- sf::st_transform(nc, "EPSG:5070") - ncp <- sf::read_sf("../testdata/nc_random_point.rds") + ncp <- readRDS(testthat::test_path("..", "testdata", "nc_random_point.rds")) ncp <- sf::st_transform(ncp, "EPSG:5070") testthat::expect_no_error(check_bbox(ncp, nc)) diff --git a/tools/tarballs/scomps_0.0.5.11172023.tar.gz b/tools/tarballs/scomps_0.0.5.11172023.tar.gz index 554978d6..82afbf7a 100644 Binary files a/tools/tarballs/scomps_0.0.5.11172023.tar.gz and b/tools/tarballs/scomps_0.0.5.11172023.tar.gz differ