knitr::opts_chunk$set(echo = TRUE)
Tools for working with Marine Protected Areas to compute species diversity metrics using OBIS data.
remotes::install_github("BigelowLab/mpatools")
We use the wdpar R package to fetch MPAs by country (or 'global' for the complete dataset.) By default, we store the files you download in the path returned by rappdirs::user_data_dir("wdpar") in GeoPackage format. Once you have downloaded a dataset you can simply read the file from disk using read_mpa("name"). Below, we use the list_mpa() function to determine if we already have the Cuba dataset.
library(rappdirs) library(sf) library(mpatools) country <- "Cuba" if (has_mpa(country)){ mpa <- read_mpa(name = country) } else { mpa <- fetch_mpa(name = country) } # plot(sf::st_geometry(mpa))
Once you have MPA polygons in hand, it is easy to request OBIS records that fall within the polygons.
We use the robis R package to fetch occurrence data. By default we store files you downlaod in the path returned by rappdirs::user_data_dir("robis") in GeoPackage. Once you have downloaded format you can simply read the file from disk using read_obis().
if (has_obis(country)){ obis <- read_obis(name = country, form = "sf") } else { obis <- fetch_obis_country(name = country) } head(obis)
We actually find occurrences that fall within the convex hull of a set of polygons, but you can enforce a stricter policy using the policy argument for fetch_obis(). See ?fetch_obis.
plot(sf::st_geometry(mpa)) plot(sf::st_geometry(obis), col = 'orange', pch = 16, add = TRUE)
We use rappsdir R package to manage the stirage location. We store data here rappdirs::user_data_dir("wdpar") and here rappdirs::user_data_dir("robis"). This is a very effective way to store data per user. But if you want to store data at a system-wide location you can do that using the ubiquitous path argument.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.