This repository holds a package with several (yet to be tested) functions to retrieve data from online repositories, and to create species range maps. This repo is inspired by GSoC 2018 proposal, and it serves as a proof of concept for how to solve the given problem:
- Easy: write a script to download occurrence data from GBIF for a species and display them on a map.
- Medium: Draw a convex hull polygon around the points in the earlier test.
- Hard: Clip the polygon you generated in medium test to world map (Keep only part of the polygon which is on land).
- Bonus: Get extent of suitable habitat within the range.
To install the package run:
devtools::install_github("mirzacengic/speciesrangeR")
Use at your own responsibility.
Let's load the necessary packages using p_load
function from pacman
package.
library(speciesrangeR)
pacman::p_load(spocc, sf, mapview, dplyr, raster, sf, scrubr, stringr, sp, rgeos)
We will load here speciesrangeR package. Use get_species_data()
to query data from the Global Biodiversity Information Facility - GBIF. Function is a wrapper around occ()
function from spocc package.
# Get gbif data for Salamandra atra for Italy, with cleaned output coordinates.
sal_atra_ita <- get_species_data("Salamandra atra", return_clean = TRUE,
return = "sp", country = "ITA")
Here we will retrieve species occurence data for species Salamandra atra Laurenti, 1768. Function get_species_data()
can take country argument to return only the data for given country (use raster::getData("ISO3")
for list of countries), so we will query for data for Italy. Default limit of spocc::occ()
function is 500 points, however you can pass a numeric value to the limit
argument. Country data is filtered after the GBIF query, therefore the number of points does not have to correspond to limit. Additional arguments can be passed to the spocc::occ()
function by using ...
. Use ?get_species_data
and ?spocc::occ
to see the documentation of both functions for more details.
We will preview the retrieved species data.
# Plot data
mapview(sal_atra_ita)
One point is in Torino and on closer inspection it seems like an erroneous datapoint. Most likely the point is assigned to an instution where the specimen is storaged.
# Plot the most easterly point
mapview(sal_atra_ita[which.min(sal_atra_ita@coords), ])
Function get_species_data()
has argument return_clean
which uses scrubr
package to clean wrong data. Currently, return_clean = TRUE
will clean the coordinates that are missing, unlikely or impossible. According to the documentation of scrubr package, removing of these cases is on a feature list to be implemented, but now we will remove the erroneous point manually.
# Remove the most easterly point.
sal_atra_ita_clean <- sal_atra_ita[-which.min(sal_atra_ita@coords), ]
Let's plot the cleaned dataset.
mapview(sal_atra_ita_clean)
On the first look it looks better. Now we will calculate the extent of occurence (EOO).
Extent of occurence is calculated using minimum convex hull from the rgeos
package. Function can return simple feature or spatial points dataframe. In the future more methods of calculating bounding polygons should be added (eg. concave hull).
- TODO: Incorporate buffer argument where EOO would include buffers around occurence points specified to user's distance (as proposed by Graham & Hijmans 2006).
# Get EOO
sal_atra_eoo <- get_eoo(sal_atra_ita_clean, return = "sp")
Plotting the extent of occurence.
mapview(sal_atra_eoo)
In this part, we will extract extent of suitable habitat by filtering extent of occurence (EOO) within min-max values of a raster variable. In the future multiple rasters + categorical variables should be added as filtering variable. Add later custom cutoff values and function passing instead of min/max. In the future, calculating the extent of suitable habitat should be also optionally implemented by calculating presence-only envelope model, which would be used to filter the extent of occurence (as suggested by Graham & Hijmans 2006).
# Load SRTM raster for North Italy (resampled to ~2 kilometer resolution for faster code execution)
srtm_italy <- raster("Y:/Mirza_Cengic/Projects/Other/GSoC/srtm_39_03_1.tif")
# Might take time with fine cell rasters
sal_atra_esh <- get_esh(species_data = sal_atra_ita_clean,
species_eoo = sal_atra_eoo,
habitat_variable = srtm_italy)
Let's plot the extent of suitable habitat with the overlaid points used for creating ESH.
mapview(sal_atra_esh)
Extent of suitable habitat with filtered elevation values. NOTE - there are some errors in the overlap of point due to raster aggregation, use better example.
Right now this repository serves only as a proof of concept and it has not been properly tested yet. All suggestions for improvements, feature requests and bug reports are more than welcomed!