Learn R Programming

OpenRange (version 0.0.1)

OpenRange_api_species: Download range maps for given species using the API.

Description

OpenRange_api_species downloads range maps for the specified species.

Usage

OpenRange_api_species(species, directory, include_id = TRUE, ...)

Value

NULL. Called for its side effect of downloading range maps.

Arguments

species

A single species.

directory

Directory that range maps should be saved in.

include_id

Logical. Should the range_id be appended to the file name? Needed to save multiple maps per species.

...

Additional arguments passed to internal functions.

See Also

Other range functions: OpenRange_api_load_species(), OpenRange_get_license(), OpenRange_get_stats(), OpenRange_list_scenarios(), OpenRange_load_species(), OpenRange_sf(), OpenRange_species()

Examples

Run this code
# \donttest{

library(OpenRange)
library(maps) #a convenient source of maps
library(sf)
library(ggplot2)


# Create temp directory

temp_dir <- file.path(tempdir(), "BIEN_temp")

#Download ranges

OpenRange_api_species(species = "Abies_amabilis",
                      directory = temp_dir,
                      include_id = TRUE) # saves ranges to a temporary directory

#Reading files

Abies_poly <- st_read(dsn = temp_dir,
                      layer = "Abies_amabilis_117684")

# Get a map to plot on

world <- map("world", plot = FALSE, fill = TRUE)|>
  st_as_sf()

#Plotting files

ggplot(data = world)+
  geom_sf()+
  geom_sf(data = Abies_poly,
          fill="green")+
  coord_sf(xlim = st_bbox(Abies_poly)[c(1,3)],
           ylim = st_bbox(Abies_poly)[c(2,4)]) +
  theme_bw()

#Getting data from the files

Abies_poly |>
  st_drop_geometry()

# }

Run the code above in your browser using DataLab