Skip to content

Commit 6ece99f

Browse files
authored
Merge pull request #454 from mapme-initiative/develop
Develop
2 parents 3a0594b + 2864e97 commit 6ece99f

File tree

9 files changed

+57
-19
lines changed

9 files changed

+57
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mapme.biodiversity
22
Title: Efficient Monitoring of Global Biodiversity Portfolios
3-
Version: 0.9.4.9007
3+
Version: 0.9.5
44
Authors@R: c(person(given = "Darius A.",
55
family = "G\u00F6rgen",
66
role = "aut",

NEWS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# mapme.biodiversity 0.9.4.9007
1+
# mapme.biodiversity 0.9.5
22

33
## General
44

55
- `get_gfw_treecover()` and `get_gfw_lossyear()` updated to version "GFC-2024-v1.12" ([416](https://github.com/mapme-initiative/mapme.biodiversity/issues/416))
66
- `calc_treecover_area()`, `calc_treecover_area_and_emissions()` and `calc_treecoverloss_emissions()` updated to include the year 2024 ([416](https://github.com/mapme-initiative/mapme.biodiversity/issues/416))
77
- `get_esalandcover()` has been adapted to download data from a new source in a format compatible with the previous version ([430](https://github.com/mapme-initiative/mapme.biodiversity/issues/430))
88
- modified `calc_treecover_area()` to return zero area and not NULL when tree cover \< `min_cover` ([413](https://github.com/mapme-initiative/mapme.biodiversity/issues/413))
9+
- `get_teow()` now requires users to manually download the file ([450](https://github.com/mapme-initiative/mapme.biodiversity/issues/450))
910

1011
## Internal
1112

1213
- internal function `.has_internet()` now delegates to `curl::has_internet()`
13-
- added function `.check_system_requirements()` that checks on package load if system requirements (GDAL and PROJ versions) are met and warns if not
14+
- added function `.check_system_requirements()` that checks on package load if system requirements (GDAL and PROJ versions) are met, and warns if not
15+
- use `utils::compareVersion()` instead of simple '\<' to check the GDAL system library version
1416

1517
## Bug fixes
1618

R/get_teow.R

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,55 @@
1010
#'
1111
#' @name teow
1212
#' @keywords resource
13+
#' @param path A character vector to the Terrestrial Ecoregions of the World (TEOW)
14+
#' zip file. Note, that the file has to be downloaded manually.
1315
#' @returns A function that returns an `sf` footprint object.
1416
#' @references Olson, D. M., Dinerstein, E., Wikramanayake, E. D., Burgess, N. D.,
1517
#' Powell, G. V. N., Underwood, E. C., D’Amico, J. A., Itoua, I., Strand, H. E.,
1618
#' Morrison, J. C., Loucks, C. J., Allnutt, T. F., Ricketts, T. H., Kura, Y., Lamoreux,
1719
#' J. F., Wettengel, W. W., Hedao, P., Kassem, K. R. 2001. Terrestrial ecoregions of
1820
#' the world: a new map of life on Earth. Bioscience 51(11):933-938.
1921
#' \doi{https://doi.org/10.1641/0006-3568(2001)051[0933:TEOTWA]2.0.CO;2}
20-
#' @importFrom utils unzip
22+
#' @source \url{https://files.worldwildlife.org/wwfcmsprod/files/Publication/file/6kcchn7e3u_official_teow.zip}
2123
#' @include register.R
2224
#' @export
23-
get_teow <- function() {
25+
# get_teow <- function() {
26+
# function(x,
27+
# name = "teow",
28+
# type = "vector",
29+
# outdir = mapme_options()[["outdir"]],
30+
# verbose = mapme_options()[["verbose"]]) {
31+
# url <- paste(
32+
# "/vsizip//vsicurl/",
33+
# "https://files.worldwildlife.org/wwfcmsprod/files/",
34+
# "Publication/file/6kcchn7e3u_official_teow.zip/",
35+
# "official/wwf_terr_ecos.shp",
36+
# sep = ""
37+
# )
38+
# bbox <- c(xmin = -180.0, ymin = -90.0, xmax = 180.0, ymax = 84.0)
39+
# tile <- st_as_sf(st_as_sfc(st_bbox(bbox, crs = "EPSG:4326")))
40+
# tile[["source"]] <- url
41+
# make_footprints(tile, filenames = "wwf_terr_ecos.gpkg", what = "vector")
42+
# }
43+
# }
44+
45+
get_teow <- function(path = NULL) {
46+
if (is.null(path) || !endsWith(tolower(path), ".zip")) {
47+
stop("Expecting path to point towards an existing '.zip' file.")
48+
}
49+
2450
function(x,
2551
name = "teow",
2652
type = "vector",
2753
outdir = mapme_options()[["outdir"]],
2854
verbose = mapme_options()[["verbose"]]) {
29-
url <- paste(
30-
"/vsizip//vsicurl/",
31-
"https://files.worldwildlife.org/wwfcmsprod/files/",
32-
"Publication/file/6kcchn7e3u_official_teow.zip/",
33-
"official/wwf_terr_ecos.shp",
34-
sep = ""
55+
url <- paste0(
56+
"/vsizip/",
57+
path,
58+
"/official/wwf_terr_ecos.shp"
3559
)
3660
bbox <- c(xmin = -180.0, ymin = -90.0, xmax = 180.0, ymax = 84.0)
37-
tile <- st_as_sf(st_as_sfc(st_bbox(bbox, crs = "EPSG:4326")))
61+
tile <- sf::st_as_sf(sf::st_as_sfc(sf::st_bbox(bbox, crs = "EPSG:4326")))
3862
tile[["source"]] <- url
3963
make_footprints(tile, filenames = "wwf_terr_ecos.gpkg", what = "vector")
4064
}

R/spatial-utils.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ spds_exists <- function(path, oo = character(0), what = c("vector", "raster")) {
4747
),
4848
raster = c("-json", "-nomd", "-norat", "-noct", oo)
4949
)
50-
if (what == "vector" && sf::sf_extSoftVersion()[["GDAL"]] < "3.7.0") {
50+
if (what == "vector" &&
51+
(utils::compareVersion(sf::sf_extSoftVersion()[["GDAL"]], "3.7.0") < 0)) {
5152
util <- "gdalinfo"
5253
opts <- oo
5354
}

man/teow.Rd

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-calc_biome.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_that("biome computation works", {
88
outdir <- file.path(tempdir(), "mapme.data")
99
.copy_resource_dir(outdir)
1010
mapme_options(outdir = outdir, verbose = FALSE)
11-
get_resources(x, get_teow())
11+
get_resources(x, get_teow("test.zip"))
1212
teow <- prep_resources(x)[["teow"]]
1313

1414
cb <- calc_biome()

tests/testthat/test-calc_ecoregion.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_that("ecoregion computation works", {
99
outdir <- file.path(tempdir(), "mapme.data")
1010
.copy_resource_dir(outdir)
1111
mapme_options(outdir = outdir, verbose = FALSE)
12-
get_resources(x, get_teow())
12+
get_resources(x, get_teow("test.zip"))
1313
teow <- prep_resources(x)[["teow"]]
1414

1515
ce <- calc_ecoregion()

tests/testthat/test-get_teow.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test_that(".get_teow works", {
22
skip_on_cran()
33

4-
gteow <- get_teow()
4+
gteow <- get_teow("test.zip")
55
expect_silent(.check_resource_fun(gteow))
66
fps <- gteow()
77
expect_silent(.check_footprints(fps))

tests/testthat/test-spatial-utils.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ test_that(".read_raster works correctly", {
112112
})
113113

114114
test_that(".read_vector works", {
115-
if (sf::sf_extSoftVersion()[["GDAL"]] < "3.7.0") skip()
115+
if (utils::compareVersion(sf::sf_extSoftVersion()[["GDAL"]], "3.7.0") < 0) {
116+
skip("GDAL < 3.7.0")
117+
}
116118

117119
# copy to directory with w permissions, as ogrinfo otherwise fails on CRAN
118120
org <- system.file("extdata", "burundi.gpkg", package = "mapme.biodiversity")
@@ -133,7 +135,9 @@ test_that(".read_vector works", {
133135
})
134136

135137
test_that("can get info from zipped vector resource", {
136-
if (sf::sf_extSoftVersion()[["GDAL"]] < "3.7.0") skip("GDAL < 3.7.0")
138+
if (utils::compareVersion(sf::sf_extSoftVersion()[["GDAL"]], "3.7.0") < 0) {
139+
skip("GDAL < 3.7.0")
140+
}
137141
if (packageVersion("sf") == "1.0.18") skip("sf == '1.0.18'")
138142
f <- system.file("extdata", "gfw_sample.gpkg",
139143
package = "mapme.biodiversity"

0 commit comments

Comments
 (0)