Skip to content

Commit

Permalink
test with FlatGeobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Jun 14, 2024
1 parent 9a3bb12 commit 8346468
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 39 deletions.
2 changes: 1 addition & 1 deletion R/vapour-gdal-library.R
Original file line number Diff line number Diff line change
Expand Up @@ -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), ]
Expand Down
8 changes: 4 additions & 4 deletions R/vapour-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions data-raw/sst_c.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Binary file added inst/extdata/sst_c.fgb
Binary file not shown.
2 changes: 1 addition & 1 deletion man/GDAL-library.Rd

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

8 changes: 4 additions & 4 deletions man/sst_c.Rd

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

27 changes: 5 additions & 22 deletions tests/testthat/test-features.R
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"))
Expand All @@ -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")

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-gdal.R
Original file line number Diff line number Diff line change
@@ -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")

})
6 changes: 3 additions & 3 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-layers.R
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 1 addition & 1 deletion vignettes/vapour.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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])
```
Expand Down

0 comments on commit 8346468

Please sign in to comment.