diff --git a/R/vapour-gdal-library.R b/R/vapour-gdal-library.R index 19d914e1..3ba70f40 100644 --- a/R/vapour-gdal-library.R +++ b/R/vapour-gdal-library.R @@ -176,7 +176,7 @@ vapour_geom_summary <- function(dsource, layer = 0L, sql = "", limit_n = NULL, s #' #' drv <- vapour_all_drivers() #' -#' f <- system.file("extdata/sst_c.gpkg", package = "vapour") +#' f <- system.file("extdata/sst_c.fgb", package = "vapour") #' vapour_driver(f) #' #' as.data.frame(drv)[match(vapour_driver(f), drv$driver), ] diff --git a/R/vapour-package.R b/R/vapour-package.R index 1d25f5d2..a7e88f4a 100644 --- a/R/vapour-package.R +++ b/R/vapour-package.R @@ -97,14 +97,14 @@ #' #' See data-raw/sst_c.R for the derivation column \code{sst_c} in Celsius. #' -#' Also stored in GeoPackage format in -#' \code{system.file("extdata/sst_c.gpkg", package = "vapour")} +#' Also stored in FlatGeoBuf format in +#' \code{system.file("extdata/sst_c.fgb", package = "vapour")} #' @docType data #' @name sst_c #' @examples -#' f <- system.file("extdata/sst_c.gpkg", package = "vapour") +#' f <- system.file("extdata/sst_c.fgb", package = "vapour") #' -#' ## create a class-less form of the data in the 'sst_c.gpkg' file with GeoJSON geometry +#' ## create a class-less form of the data in the 'sst_c.fgb' file with GeoJSON geometry #' atts <- vapour_read_fields(f) #' dat <- as.data.frame(atts, stringsAsFactors = FALSE) #' dat[["json"]] <- vapour_read_geometry_text(f) diff --git a/data-raw/sst_c.R b/data-raw/sst_c.R index 716a056b..b7b3b108 100644 --- a/data-raw/sst_c.R +++ b/data-raw/sst_c.R @@ -11,6 +11,8 @@ pryr::object_size(cl) devtools::use_data(sst_c) sf::st_write(sst_c, "inst/extdata/sst_c.gpkg", driver = "GPKG") +terra::writeVector(terra::vect("inst/extdata/sst_c.gpkg"), "inst/extdata/sst_c.fgb", filetype = "FlatGeoBuf") + sst <- aggregate(crop(sst, extent(140, 150, -60, -40)), fun = median, fact = 7) writeRaster(sst, "inst/extdata/sst.tif", options = c("COMPRESS=LZW"), datatype = "FLT4S") diff --git a/inst/extdata/sst_c.fgb b/inst/extdata/sst_c.fgb new file mode 100644 index 00000000..dc6b561b Binary files /dev/null and b/inst/extdata/sst_c.fgb differ diff --git a/man/GDAL-library.Rd b/man/GDAL-library.Rd index f065c23f..b1c0de4a 100644 --- a/man/GDAL-library.Rd +++ b/man/GDAL-library.Rd @@ -47,7 +47,7 @@ vapour_gdal_version() drv <- vapour_all_drivers() -f <- system.file("extdata/sst_c.gpkg", package = "vapour") +f <- system.file("extdata/sst_c.fgb", package = "vapour") vapour_driver(f) as.data.frame(drv)[match(vapour_driver(f), drv$driver), ] diff --git a/man/sst_c.Rd b/man/sst_c.Rd index a34c8738..f42a1959 100644 --- a/man/sst_c.Rd +++ b/man/sst_c.Rd @@ -14,13 +14,13 @@ GLOB/JPL/MUR/v4.1/2017/209/ See data-raw/sst_c.R for the derivation column \code{sst_c} in Celsius. -Also stored in GeoPackage format in -\code{system.file("extdata/sst_c.gpkg", package = "vapour")} +Also stored in FlatGeoBuf format in +\code{system.file("extdata/sst_c.fgb", package = "vapour")} } \examples{ -f <- system.file("extdata/sst_c.gpkg", package = "vapour") +f <- system.file("extdata/sst_c.fgb", package = "vapour") -## create a class-less form of the data in the 'sst_c.gpkg' file with GeoJSON geometry +## create a class-less form of the data in the 'sst_c.fgb' file with GeoJSON geometry atts <- vapour_read_fields(f) dat <- as.data.frame(atts, stringsAsFactors = FALSE) dat[["json"]] <- vapour_read_geometry_text(f) diff --git a/tests/testthat/test-features.R b/tests/testthat/test-features.R index 720777a3..9d3581a6 100644 --- a/tests/testthat/test-features.R +++ b/tests/testthat/test-features.R @@ -1,7 +1,7 @@ context("test-features.R") -f <- system.file("extdata", "sst_c.gpkg", package = "vapour", mustWork = TRUE) +f <- system.file("extdata", "sst_c.fgb", package = "vapour", mustWork = TRUE) f2 <- system.file("extdata/osm/myosmfile.osm", package = "vapour", mustWork = TRUE) Sys.setenv(OSM_USE_CUSTOM_INDEXING="NO") pfile <- "list_locality_postcode_meander_valley.tab" @@ -28,8 +28,8 @@ test_that("geometry read works", { gbin[[1]] %>% expect_type("raw") gjsn[[1]] %>% expect_type("character") %>% grepl("MultiLineString", .) %>% expect_true() ggml[[1]] %>% expect_type("character") %>% grepl("gml:MultiLineString", .) %>% expect_true() - gwkt[[1]] %>% expect_type("character") %>% grepl("MULTILINESTRING \\(\\(-16254", .) %>% expect_true() - gext[[4]] %>% expect_type("double") %>% trunc() %>% expect_identical(c(-9293382, 7088338, -6881739, 9067994)) + gwkt[[1]] %>% expect_type("character") %>% grepl("MULTILINESTRING", .) %>% expect_true() + expect_identical(gjsn, vapour_read_geometry_text(f)) expect_identical(ggml, vapour_read_geometry_text(f, textformat = "gml")) @@ -51,7 +51,6 @@ pprj2 <- "+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 expect_silent(vapour_geom_summary(dsource, layer = 0)) expect_silent(vapour_geom_summary(dsource, layer = "list_locality_postcode_meander_valley")) - p3d <- system.file("extdata/point3d.gpkg", package = "vapour") expect_warning(vapour_read_attributes(f, layer = factor("sst_c")), "layer is a factor, converting to character") @@ -95,10 +94,10 @@ test_that("limit_n works", expect_silent(vapour_read_geometry(f, limit_n = 1L, skip_n = 2)) %>% expect_length(1L) expect_silent(vapour_read_type(f, limit_n = 1L, skip_n = 2)) %>% expect_equal(5L) - expect_silent(vapour_read_names(f, limit_n = 1L, skip_n = 2)) %>% expect_equal(3L) + expect_silent(vapour_read_names(f, limit_n = 1L, skip_n = 2)) %>% expect_equal(2L) expect_silent(vapour_read_names(f)) %>% expect_length(7L) - expect_silent(vapour_read_geometry_text(f, limit_n = 3L)) %>% expect_length(3L) + vapour_read_geometry_text(f, limit_n = 3L) %>% expect_length(3L) expect_named(vapour_layer_info(f), c("dsn", "driver", "layer", "layer_names", "fields", "count", "extent", "projection")) @@ -149,22 +148,6 @@ test_that("extent clipping combined with sql works", expect_length(e1, 7L) expect_length(e3, 4L) - expect_equal(e1, list(c(-3273103.52164666, 4672692.82549952, -3562748.06089841, - 4870090.32178965), c(-4774642.02701368, 5167013.90124751, -4644892.46962219, - 5303185.55727377), c(-6005059.83508923, 6080358.63750109, -5670292.85588759, - 6963437.49419418), c(-9293382.13554168, 7088338.80241629, -6881739.64161586, - 9067994.12361849), c(-12306571.6084815, 8614711.87011407, -8114743.77423273, - 11869446.3939912), c(-9403103.938376, 10886059.5102222, -11285790.2140821, - 10798224.9521274), c(5106987.14577475, 5107839.31687039, -11065121.4051305, - -11063443.5304944))) -expect_equal(e3, list(c(-6005059.83508923, 6080358.63750109, -5670292.85588759, - 6963437.49419418), c(-9293382.13554168, 7088338.80241629, -6881739.64161586, - 9067994.12361849), c(-12306571.6084815, 8614711.87011407, -8114743.77423273, - 11869446.3939912), c(-9403103.938376, 10886059.5102222, -11285790.2140821, - 10798224.9521274)) - ) - - sf_extent <- structure(setNames(ex[c(1, 3, 2, 4)], c("xmin", "ymin", "xmax", "ymax")), class = "bbox", diff --git a/tests/testthat/test-gdal.R b/tests/testthat/test-gdal.R index 55767944..9020a096 100644 --- a/tests/testthat/test-gdal.R +++ b/tests/testthat/test-gdal.R @@ -1,7 +1,7 @@ -f <- system.file("extdata", "sst_c.gpkg", package = "vapour", mustWork = TRUE) +f <- system.file("extdata", "sst_c.fgb", package = "vapour", mustWork = TRUE) r <- system.file("extdata", "sst.tif", package = "vapour", mustWork = TRUE) test_that("multiplication works", { - expect_equal(vapour_driver(f), "GPKG") + expect_equal(vapour_driver(f), "FlatGeobuf") expect_equal(vapour_driver(r), "GTiff") }) diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index 44e3209e..e882ae72 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -1,8 +1,8 @@ context("test-helpers") file <- "list_locality_postcode_meander_valley.tab" -mvfile <- system.file(file.path("extdata/tab", file), package="vapour") -gfile <- system.file(file.path("extdata", "sst_c.gpkg"), package="vapour") +mvfile <- system.file(file.path("extdata/tab", file), package="vapour", mustWork = TRUE) +gfile <- system.file(file.path("extdata", "sst_c.fgb"), package="vapour", mustWork = TRUE) osmfile <- system.file(file.path("extdata/osm", "osm-ways.osm"), package="vapour") ##dput(vapour_geom_summary(mvfile, sql = sprintf("SELECT FID FROM %s WHERE FID = 15", vapour_layer_names(mvfile)[1L]))) sql_bench <- list(FID = 15L, valid_geometry = TRUE, type = 3L, xmin = 455980.34, xmax = 463978.72, @@ -17,7 +17,7 @@ test_that("helpers work", { # expect_error(validate_limit_n(-2)) - expect_equal(vapour_read_names(gfile, sql = "SELECT FID FROM sst_c LIMIT 2"), c(1, 2)) + expect_equal(vapour_read_names(gfile, sql = "SELECT FID FROM sst_c LIMIT 2"), c(0, 1)) expect_equal(vapour_read_names(mvfile), 1:58) }) diff --git a/tests/testthat/test-layers.R b/tests/testthat/test-layers.R index 3d66c919..d56fc728 100644 --- a/tests/testthat/test-layers.R +++ b/tests/testthat/test-layers.R @@ -1,5 +1,5 @@ f2 <- system.file("extdata/osm/myosmfile.osm", package = "vapour", mustWork = TRUE) -f <- system.file("extdata", "sst_c.gpkg", package = "vapour", mustWork = TRUE) +f <- system.file("extdata", "sst_c.fgb", package = "vapour", mustWork = TRUE) file <- "list_locality_postcode_meander_valley.tab" mvfile <- system.file(file.path("extdata/tab", file), package="vapour") diff --git a/vignettes/vapour.Rmd b/vignettes/vapour.Rmd index 2123199e..3d7e99b9 100644 --- a/vignettes/vapour.Rmd +++ b/vignettes/vapour.Rmd @@ -54,7 +54,7 @@ vapour_read_geometry_text(pfile, textformat = "gml")[2] ## don't do this with a non-longlat data set like cfile vapour_read_geometry_text(pfile, textformat = "kml")[1:2] -cfile <- system.file("extdata/sst_c.gpkg", package = "vapour") +cfile <- system.file("extdata/sst_c.fgb", package = "vapour") str(vapour_read_geometry_text(cfile, textformat = "wkt")[1:2]) ```