From 8d08bfa589a91be0c0903c87d2c279b972f32bd3 Mon Sep 17 00:00:00 2001 From: Jeff Hanson Date: Sat, 11 May 2024 12:21:33 +1200 Subject: [PATCH] update docs + minor patches (#82) - Update DESCRIPTION with _prepr_ package information. - Update README with Chromium dependencies. - Update global example global processing script with increased precision. - Update vignette to be compatible with changes to GADM website. - Fix issue with tests leaving left-over junk in temporary directories. --- DESCRIPTION | 9 +- Makefile | 2 +- NAMESPACE | 1 + NEWS.md | 12 +- R/package.R | 1 + README.Rmd | 11 +- README.md | 38 ++-- docs/404.html | 2 +- docs/CONTRIBUTING.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/articles/wdpar.html | 55 +++--- docs/authors.html | 2 +- docs/index.html | 25 +-- docs/news/index.html | 13 +- docs/pkgdown.yml | 2 +- docs/reference/index.html | 2 +- docs/reference/st_erase_overlaps.html | 2 +- docs/reference/st_repair_geometry.html | 2 +- docs/reference/wdpa_clean.html | 2 +- docs/reference/wdpa_dissolve.html | 2 +- docs/reference/wdpa_fetch.html | 10 +- docs/reference/wdpa_latest_version.html | 4 +- docs/reference/wdpa_read.html | 2 +- docs/reference/wdpa_url.html | 6 +- docs/reference/wdpar.html | 2 +- inst/doc/wdpar.Rmd | 6 +- inst/doc/wdpar.html | 242 ++++++++++++------------ inst/scripts/global-example-script.R | 7 +- tests/testthat/setup-chromote.R | 21 ++ vignettes/wdpar.Rmd | 6 +- 31 files changed, 273 insertions(+), 222 deletions(-) create mode 100644 tests/testthat/setup-chromote.R diff --git a/DESCRIPTION b/DESCRIPTION index 1ba6f1f..8e75cb1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,14 @@ Package: wdpar Type: Package -Version: 1.3.7.2 +Version: 1.3.7.3 Title: Interface to the World Database on Protected Areas Description: Fetch and clean data from the World Database on Protected Areas (WDPA) and the World Database on Other Effective Area-Based Conservation Measures (WDOECM). Data is obtained from Protected Planet . To augment data cleaning procedures, users can install the 'prepr' R package (available at - ). For more information on this package, - see Hanson (2022) . + ). For more information on this + package, see Hanson (2022) . Authors@R: c(person(c('Jeffrey', 'O'), 'Hanson', email='jeffrey.hanson@uqconnect.edu.au', role = c('aut', 'cre'))) Imports: @@ -24,7 +24,8 @@ Imports: lwgeom (>= 0.2-1), tibble (>= 2.1.3), pingr (>= 1.1.2), - rappdirs (>= 0.3.1) + rappdirs (>= 0.3.1), + withr (>= 3.0.0) Suggests: testthat (>= 2.0.1), knitr (>= 1.2.0), diff --git a/Makefile b/Makefile index b42253c..5ab5be3 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ paper_case_study: mv case-study.Rout paper/case-study.Rout rm -f Rplots.pdf -wdpa_global: install +wdpa_global: R CMD BATCH --no-restore --no-save inst/scripts/global-example-script.R .PHONY: initc vigns clean data docs readme site test check checkwb build install man spellcheck examples wdpa_global paper purl_vigns paper_case_study diff --git a/NAMESPACE b/NAMESPACE index de9257e..01a3904 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,3 +10,4 @@ export(wdpa_read) export(wdpa_url) import(sf) importFrom(rappdirs,user_data_dir) +importFrom(withr,defer) diff --git a/NEWS.md b/NEWS.md index 5b464a1..2e52ad1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,17 @@ +# wdpar 1.3.7.3 + +- Fix issues with `wdpa_fetch()` and `wdpa_read()` on MacOS. + Thanks to Jason Everett (@jaseeverett) for code contribution. +- Update DESCRIPTION with _prepr_ package information. +- Update README with Chromium dependencies. +- Update global example global processing script with increased precision. +- Update vignette to be compatible with changes to GADM website. +- Fix issue with tests leaving left-over junk in temporary directories. + # wdpar 1.3.7.2 - Update `wdpa_fetch()` to use the _chromote_ package to handle web scrapping - (instead of _webdriver_). + (instead of the _webdriver_ package). - Update `wdpa_fetch()` so that it can download country-level data in either shapefile or file geodatabase format (using the new `datatype` parameter). Since file geodatabase data appears to be more robust, `wdpa_fetch()` diff --git a/R/package.R b/R/package.R index 95f727f..51e49b7 100644 --- a/R/package.R +++ b/R/package.R @@ -38,4 +38,5 @@ NULL # avoid false positive NOTEs during CRAN checks #' @importFrom rappdirs user_data_dir +#' @importFrom withr defer NULL diff --git a/README.Rmd b/README.Rmd index 472555c..d866db0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -61,30 +61,31 @@ Note that the _prepr R_ package has system dependencies that need to be installe ##### _Windows_ -The [Rtools](https://cran.r-project.org/bin/windows/Rtools/) software needs to be installed to install the _prepr R_ package package from source. This software provides system requirements from [rwinlib](https://github.com/rwinlib/). +A Chromium-based web browser to be installed (e.g., Google Chrome, Chromium, Brave). Also, the [Rtools](https://cran.r-project.org/bin/windows/Rtools/) software needs to be installed to install the _prepr R_ package package from source. This software provides system requirements from [rwinlib](https://github.com/rwinlib/). ##### _Ubuntu_ -The `gmp`, `mpfr`, and several spatial libraries need to be installed. For recent versions of Ubuntu (18.04 and later), these libraries are available through official repositories. They can be installed using the following system commands: +A Chromium-based web browser to be installed (e.g., Google Chrome, Chromium, Brave). Also, the `gmp`, `mpfr`, and several spatial libraries need to be installed. For recent versions of Ubuntu (18.04 and later), these libraries are available through official repositories. They can be installed using the following system commands: ``` apt-get -y update -apt-get install -y libgmp3-dev libmpfr-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev +apt-get install -y libgmp3-dev libmpfr-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev chromium-browser ``` ##### _Linux_ -For Unix-alikes, `gmp` (>= 4.2.3), `mpfr` (>= 3.0.0), and `gdal` (>= 3.2.2) are required. +For Unix-alikes, a Chromium-based web browser (e.g., Google Chrome, Chromium, Brave), `gmp` (>= 4.2.3), `mpfr` (>= 3.0.0), and `gdal` (>= 3.2.2) are required. ##### _macOS_ -The `gmp`, `mpfr`, and `gdal` libraries are required. The easiest way to install these libraries is using [HomeBrew](https://brew.sh/). After installing HomeBrew, these libraries can be installed using the following commands in the system terminal: +A Chromium-based web browser to be installed (e.g., Google Chrome, Chromium, Brave). Also, the `gmp`, `mpfr`, and `gdal` libraries are required. The easiest way to install these libraries is using [HomeBrew](https://brew.sh/). After installing HomeBrew, these libraries can be installed using the following commands in the system terminal: ``` brew install pkg-config brew install gmp brew install mpfr brew install gdal +brew install --cask chromium ``` ### Usage diff --git a/README.md b/README.md index 87e33ec..f5e7750 100644 --- a/README.md +++ b/README.md @@ -93,37 +93,43 @@ platform-specific instructions). ##### *Windows* -The [Rtools](https://cran.r-project.org/bin/windows/Rtools/) software -needs to be installed to install the *prepr R* package package from -source. This software provides system requirements from +A Chromium-based web browser to be installed (e.g., Google Chrome, +Chromium, Brave). Also, the +[Rtools](https://cran.r-project.org/bin/windows/Rtools/) software needs +to be installed to install the *prepr R* package package from source. +This software provides system requirements from [rwinlib](https://github.com/rwinlib/). ##### *Ubuntu* -The `gmp`, `mpfr`, and several spatial libraries need to be installed. -For recent versions of Ubuntu (18.04 and later), these libraries are -available through official repositories. They can be installed using the -following system commands: +A Chromium-based web browser to be installed (e.g., Google Chrome, +Chromium, Brave). Also, the `gmp`, `mpfr`, and several spatial libraries +need to be installed. For recent versions of Ubuntu (18.04 and later), +these libraries are available through official repositories. They can be +installed using the following system commands: apt-get -y update - apt-get install -y libgmp3-dev libmpfr-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev + apt-get install -y libgmp3-dev libmpfr-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev chromium-browser ##### *Linux* -For Unix-alikes, `gmp` (>= 4.2.3), `mpfr` (>= 3.0.0), and `gdal` +For Unix-alikes, a Chromium-based web browser (e.g., Google Chrome, +Chromium, Brave), `gmp` (>= 4.2.3), `mpfr` (>= 3.0.0), and `gdal` (>= 3.2.2) are required. ##### *macOS* -The `gmp`, `mpfr`, and `gdal` libraries are required. The easiest way to -install these libraries is using [HomeBrew](https://brew.sh/). After -installing HomeBrew, these libraries can be installed using the -following commands in the system terminal: +A Chromium-based web browser to be installed (e.g., Google Chrome, +Chromium, Brave). Also, the `gmp`, `mpfr`, and `gdal` libraries are +required. The easiest way to install these libraries is using +[HomeBrew](https://brew.sh/). After installing HomeBrew, these libraries +can be installed using the following commands in the system terminal: brew install pkg-config brew install gmp brew install mpfr brew install gdal + brew install --cask chromium ### Usage @@ -178,7 +184,7 @@ head(mlt_pa_data) ## Simple feature collection with 6 features and 32 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY - ## Bounding box: xmin: 1382584 ymin: 4280853 xmax: 1394227 ymax: 4299615 + ## Bounding box: xmin: 1382584 ymin: 4280853 xmax: 1390560 ymax: 4299615 ## Projected CRS: +proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +ellps=WGS84 +units=m +no_defs ## Precision: 1500 ## # A tibble: 6 × 33 @@ -188,8 +194,8 @@ head(mlt_pa_data) ## 2 194420 194420 PA Filf… Filfla Rise… Nature R… National Ia ## 3 555588631 555588631 PA Il-M… Il-Majji… Park… National… National II ## 4 174758 174758 PA Bidn… Bidnija,… List… List of … National III - ## 5 194415 194415 PA 'Il-… 'Il-Ġonn… List… List of … National III - ## 6 194418 194418 PA Il-B… Il-Ballu… List… List of … National III + ## 5 194418 194418 PA Il-B… Il-Ballu… List… List of … National III + ## 6 194417 194417 PA 'Il-… 'Il-Wied… List… List of … National III ## # ℹ 24 more variables: INT_CRIT , MARINE , REP_M_AREA , ## # GIS_M_AREA , REP_AREA , GIS_AREA , NO_TAKE , ## # NO_TK_AREA , STATUS , STATUS_YR , GOV_TYPE , diff --git a/docs/404.html b/docs/404.html index 06f9c14..26317f7 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ wdpar - 1.3.7.2 + 1.3.7.3 diff --git a/docs/CONTRIBUTING.html b/docs/CONTRIBUTING.html index abe8a20..f1d1c60 100644 --- a/docs/CONTRIBUTING.html +++ b/docs/CONTRIBUTING.html @@ -17,7 +17,7 @@ wdpar - 1.3.7.2 + 1.3.7.3 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 48e0def..6f69561 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -17,7 +17,7 @@ wdpar - 1.3.7.2 + 1.3.7.3 diff --git a/docs/articles/index.html b/docs/articles/index.html index 7d36c7c..5b1096d 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ wdpar - 1.3.7.2 + 1.3.7.3 diff --git a/docs/articles/wdpar.html b/docs/articles/wdpar.html index 5c8230c..ca710a6 100644 --- a/docs/articles/wdpar.html +++ b/docs/articles/wdpar.html @@ -33,7 +33,7 @@ wdpar - 1.3.7.2 + 1.3.7.3 @@ -72,7 +72,7 @@

wdpar: Interface to the World Database on Protected Areas

Jeffrey O. Hanson

-

2024-04-25

+

2024-05-11

Source: vignettes/wdpar.Rmd @@ -110,14 +110,14 @@

TutorialAfter cleaning the data set, we will perform an additional step that involves clipping the terrestrial protected areas to Malta’s coastline. Ideally, we would also clip the marine protected areas to Malta’s Exclusive Economic Zone (EEZ) but such data are not as easy to obtain on a per country basis (but see https://www.marineregions.org/eez.php)).

 # download Malta boundary from Global Administrative Areas dataset
-file_path <- tempfile(fileext = "rds")
+file_path <- tempfile(fileext = ".gpkg")
 download.file(
-  "https://biogeo.ucdavis.edu/data/gadm3.6/Rsf/gadm36_MLT_0_sf.rds",
+  "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg/gadm41_MLT.gpkg",
   file_path
 )
 
 # import Malta's boundary
-mlt_boundary_data <- readRDS(file_path)
+mlt_boundary_data <- sf::read_sf(file_path, "ADM_ADM_0")
 
 # repair any geometry issues, dissolve the border, reproject to same
 # coordinate system as the protected area data, and repair the geometry again
@@ -131,12 +131,9 @@ 

Tutorial st_set_precision(1000) %>% sf::st_make_valid() %>% st_transform(st_crs(mlt_pa_data)) %>% - sf::st_make_valid()

-
## old-style crs object detected; please recreate object with a recent sf::st_crs()
-## old-style crs object detected; please recreate object with a recent sf::st_crs()
-## old-style crs object detected; please recreate object with a recent sf::st_crs()
-
-# clip Malta's protected areas to the coastline
+  sf::st_make_valid()
+
+# clip Malta's protected areas to the coastline
 mlt_pa_data <-
   mlt_pa_data %>%
   filter(MARINE == "terrestrial") %>%
@@ -150,13 +147,13 @@ 

Tutorial ## Warning: attribute variables are assumed to be spatially constant throughout ## all geometries

-
+
 

Now that we have finished cleaning the data, let’s preview the data. For more information on what these columns mean, please refer to the official manual (available in English, French, Spanish, and Russian).

-
+
 # print first six rows of the data
 head(mlt_pa_data)
## Simple feature collection with 6 features and 32 fields
@@ -181,11 +178,11 @@ 

Tutorial## # SUPP_INFO <chr>, CONS_OBJ <chr>, GEOMETRY_TYPE <chr>, AREA_KM2 <dbl>, ## # geometry <GEOMETRY [m]>

We will now reproject the data to longitude/latitude coordinates (EPSG:4326) for visualization purposes.

-
+
 # reproject data
 mlt_pa_data <- st_transform(mlt_pa_data, 4326)

Next, we can plot a map showing the boundaries of Malta’s protected area system.

-
+
 # download basemap for making the map
 bg <- get_stadiamap(
   unname(st_bbox(mlt_pa_data)), zoom = 8,
@@ -198,7 +195,7 @@ 

Tutorialtheme(axis.title = element_blank())

We can also create a histogram showing the year when each protected area was established.

-
+
 hist(
   mlt_pa_data$STATUS_YR,
   main = "Malta's protected areas",
@@ -206,7 +203,7 @@ 

Tutorial)

Now let’s calculate some statistics. We can calculate the total amount of land and ocean inside Malta’s protected area system (km2).

-
+
 # calculate total amount of area inside protected areas (km^2)
 statistic <-
   mlt_pa_data %>%
@@ -226,7 +223,7 @@ 

Tutorial## 2 terrestrial 84.9 ## 3 partial 13.1

We can also calculate the percentage of land inside its protected area system that are managed under different categories (i.e. using the protected area management categories defined by The International Union for Conservation of Nature).

-
+
 # calculate percentage of land inside protected areas (km^2)
 statistic <-
   mlt_pa_data %>%
@@ -250,7 +247,7 @@ 

Tutorial## 5 III 0.191 0.00451 ## 6 Ia 0.145 0.00343

We can also plot a map showing Malta’s protected areas and color each area according to it’s management category.

-
+
 ggmap(bg) +
 geom_sf(aes(fill = IUCN_CAT), data = mlt_pa_data, inherit.aes = FALSE) +
 theme(axis.title = element_blank(), legend.position = "bottom")
@@ -260,7 +257,7 @@

TutorialRecommended practices for large datasets

The wdpar R package can be used to clean large datasets assuming that sufficient computational resources and time are available. Indeed, it can clean data spanning large countries, multiple countries, and even the full global dataset. When processing the full global dataset, it is recommended to use a computer system with at least 32 GB RAM available and to allow for at least one full day for the data cleaning procedures to complete. It is also recommended to avoid using the computer system for any other tasks while the data cleaning procedures are being completed, because they are very computationally intensive. Additionally, when processing large datasets – and especially for the global dataset – it is strongly recommended to disable the procedure for erasing overlapping areas. This is because the built-in procedure for erasing overlaps is very time consuming when processing many protected areas, so that information on each protected area can be output (e.g. IUCN category, year established). Instead, when cleaning large datasets, it is recommended to run the data cleaning procedures with the procedure for erasing overlapping areas disabled (i.e. with erase_overlaps = FALSE). After the data cleaning procedures have completed, the protected area data can be manually dissolved to remove overlapping areas (e.g. using wdpa_dissolve()). For an example of these procedures, please see below.

-
+
 # download protected area data for multiple of countries
 ## (i.e. Portugal, Spain, France)
 raw_pa_data <-
@@ -268,7 +265,7 @@ 
-
+
 # clean protected area data (with procedure for erasing overlaps disabled)
 full_pa_data <- wdpa_clean(raw_pa_data, erase_overlaps = FALSE)
 
@@ -292,7 +289,7 @@ 
-
+
 # calculate total area
 print(st_area(pa_data))
## 8040807030 [m^2]
@@ -302,7 +299,7 @@

The default parameters for the data cleaning procedures are well suited for national-scale analyses. Although these parameters reduce memory requirements and the time needed to complete the data cleaning procedures, they can produce protected area boundaries that appear overly “blocky” – lacking smooth edges – when viewed at finer scales. As such, it is strongly recommended to increase the level of spatial precision when cleaning data for local scale analyses (via the geometry_precision parameter of the wdpa_clean() function).

Here we will explore the consequences of using the default parameters for the data cleaning procedures when working at a local scale. This will help illustrate why it can be important to adjust the spatial precision of the data cleaning procedures. To begin with, we will obtain data for a small protected area. Specifically, we will extract a protected area from the Malta dataset we downloaded earlier.

-
+
 # find id for smallest reserve in cleaned dataset
 mlt_reserve_id <- mlt_pa_data$WDPAID[which.min(mlt_pa_data$AREA_KM2)]
 
@@ -328,12 +325,12 @@ 
-
+
 # visualize data
 plot(mlt_raw_reserve_data[, 1])

We can see that the boundary for this protected area has a high level of detail. This suggests that the protected area data is available at a resolution that is sufficient to permit local scale analyses. To help understand the consequences of cleaning data with the default parameters, we will clean this dataset using the default parameters.

-
+
 # clean the data with default parameters
 mlt_default_cleaned_reserve_data <- wdpa_clean(mlt_raw_reserve_data)
 
@@ -355,12 +352,12 @@ 
-
+
 # visualize data
 plot(mlt_default_cleaned_reserve_data[, 1])

After cleaning the data with the default parameters, we can see that the boundary of the protected area is no longer highly detailed. For example, the smooth edges of the raw protected area data have been replaced with sharp, blocky edges. As such, subsequent analysis performed at the local scale – such as calculating the spatial extent of land cover types within this single protected area – might not be sufficiently precise. Now, let’s clean the data using parameters that are well suited for local scale analysis.

-
+
 # clean the data with default parameters
 mlt_fixed_cleaned_reserve_data <- wdpa_clean(
   mlt_raw_reserve_data, geometry_precision = 10000
@@ -384,7 +381,7 @@ 
-
+
 # visualize data
 plot(mlt_fixed_cleaned_reserve_data[, 1])

@@ -417,7 +414,7 @@

Additional datasetsCitation

Please cite the wdpar R package and the relevant databases in publications. To see citation details, use the code:

-
+
 citation("wdpar")
diff --git a/docs/authors.html b/docs/authors.html index efbb56b..680faaf 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ wdpar - 1.3.7.2 + 1.3.7.3
diff --git a/docs/index.html b/docs/index.html index 2ec029e..cbd355e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -17,8 +17,8 @@ Conservation Measures (WDOECM). Data is obtained from Protected Planet <https://www.protectedplanet.net/en>. To augment data cleaning procedures, users can install the prepr R package (available at - <https://github.com/dickoa/prepr>). For more information on this package, - see Hanson (2022) <doi:10.21105/joss.04594>."> + <https://github.com/prioritizr/prepr>). For more information on this + package, see Hanson (2022) <doi:10.21105/joss.04594>.">