Skip to contents

Calculates the total range size (in square kilometers) for each species from a list of range polygons. Can be used with polygons that have been clipped to land boundaries or with raw convex hull polygons.

Usage

range_sizes(clipped_polygons_list, species_col = "species_name")

Arguments

clipped_polygons_list

A named list where each element is a list of sf polygon objects representing the range of a species.

species_col

Character string specifying the name of the species column in the output. Default is "species_name".

Value

A tibble with two columns:

  • species_col — species name.

  • range_size — total range size in square kilometers.

Details

For each species, the function sums the areas of all polygons in clipped_polygons_list using sf::st_area(). Areas are returned in square kilometers by dividing the default square meters result by 1e6.

Polygons that are invalid (!st_is_valid()) are skipped, and any errors during area calculation are caught and reported as warnings.

Examples

# Create a dataframe with a 'species_name' column
test_data <- data.frame(species_name = c("Acer_campestre", "Acer_platanoides"))
# Generate range polygons for the speceis in the dataframe
polygon_list <- get_range_convex_hulls(test_data)
#> Processing species: Acer_campestre
#> Processing species: Acer_platanoides
# Get continent boundaries
continent_sf <- get_continent_sf()
#> Error in get_continent_sf(): Default continent GeoJSON file not found. Ensure the file is in the 'extdata' directory of the package.
# Clip these range polygons to the continent bounds
clipped_polygon_list <- clip_polygons_to_land(polygon_list, continent_sf)
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
#> Warning: restarting interrupted promise evaluation
# Generate range sizes for each speices using the clipped range polygons
sizes <- range_sizes(clipped_polygons_list = clipped_polygon_list)