Extract lake ids either at the location of point occurrences or falling within a bounding box
Usage
extract_lake_ids(
data,
lon,
lat,
lake_shape,
var_name = "Hylak_id",
xmin = NULL,
ymin = NULL,
xmax = NULL,
ymax = NULL,
bbox = FALSE,
lake_id_table,
quiet = TRUE
)Arguments
- data
a data.frame or data.table that contains the columns the longitude / latitude coordinates in WGS84, i.e. of species point occurrences
- lon
character. The name of the column with the longitude coordinates.
- lat
character. The name of the column with the latitude coordinates.
- lake_shape
Full path to lake shape files; i.e. HydroLAKES shapefiles; when NULL a lake raster file needs to be provided
- var_name
character. Name of the shape file ID column, i.e. "Hylak_id" for HydroLAKES; default is "Hylak_id"
- xmin
integer. bounding box coordinate check what is lower left corner in WGS84; if NULL see parameter bbox
- ymin
integer. bounding box coordinate check what is lower right corner in WGS84; if NULL see parameter bbox
- xmax
integer. bounding box coordinate upper right corner in WGS84; if NULL see parameter bbox
- ymax
integer. bounding box coordinate upper left corner in WGS84; if NULL see parameter bbox
- bbox
logical. if TRUE, then all lake ids within the bounding box are returned, note that either bounding box values can be supplied thorugh xmin, ymin, xmax and ymax values or when left empty (NULL) bounding box is calculated from min max values of the longitude and latitude values provided in the occurrence table; if FALSE lake ids in which point occurrences are located are returned, default is FALSE
- lake_id_table
character. Full path of the output lake id table
- quiet
logical. If FALSE, the standard output will be printed. Default is TRUE.
Details
For the extraction of a value at a given point location from the basin and/or sub-catchment raster layer of the Hydrography90m dataset, the GDAL function 'gdallocationinfo' is used. The point locations have to be defined by coordinates in the WGS84 reference system.
References
https://grass.osgeo.org/grass82/manuals/ https://gdal.org/programs/gdallocationinfo.html
Examples
# Download test data into the temporary R folder
# or define a different directory
my_directory <- tempdir()
download_test_data(my_directory)
# Example 1: Extracts lake IDs for points located within a lake
# Load occurrence data
species_occurrence <- read.table(paste0(my_directory,
"/hydrography90m_test_data",
"/spdata_1264942.txt"),
header = TRUE)
# extract lake IDs which intersect with species point occurrences
extract_lake_ids(data = species_occurrence,
lon = "longitude",
lat = "latitude",
var_name = "lake_id",
lake_shape = paste0(my_directory, "/hydrography90m_test_data",
"/hydrography90m_test_lakes.gpkg"),
lake_id_table = output_folder,
quiet = FALSE)
# extract lake IDs from bounding box taken from species point occurrences
extract_lake_ids(data = species_occurrence,
lon = "longitude",
lat = "latitude",
var_name = "lake_id",
lake_shape = paste0(my_directory, "/hydrography90m_test_data",
"/hydrography90m_test_lakes.gpkg"),
bbox = TRUE,
lake_id_table = output_folder,
quiet = FALSE)
# extract lake IDs from provided bounding box
extract_lake_ids(data = species_occurrence,
lon = "longitude",
lat = "latitude",
xmin = 9.498263,
ymin = 44.21651,
xmax = 29.71806,
ymax = 50.25584,
var_name = "lake_id",
lake_shape = paste0(my_directory, "/hydrography90m_test_data",
"/hydrography90m_test_lakes.gpkg"),
bbox = TRUE,
lake_id_table = output_folder,
quiet = FALSE)