Skip to contents

Extracts the ID value of the basin and/or sub-catchment raster layer at given point locations. Can also be used for point-based extraction of any .tif layer by specifying the layer in the "basin" parameter.

Usage

extract_ids(
  data,
  lon,
  lat,
  id = NULL,
  basin_layer = NULL,
  subc_layer = NULL,
  quiet = TRUE
)

Arguments

data

a data.frame or data.table that contains the columns regarding the longitude / latitude coordinates in WGS84.

lon

character. The name of the column with the longitude coordinates.

lat

character. The name of the column with the latitude coordinates.

id

character. The name of a column containing unique IDs for each row of "data" (e.g., occurrence or site IDs).

basin_layer

character. Full path to the .tif layer with the basin ID.

subc_layer

character. Full path to the .tif layer with the sub-catchment ID.

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. The function can also be used to extract any value from a given raster layer in a WGS84 projection, such as environmental information that is stored in the input raster file.

Note

Duplicated rows will be removed.

Author

Afroditi Grigoropoulou, Marlene Schürz

Examples

# Download test data into the temporary R folder
# or define a different directory
my_directory <- tempdir()
download_test_data(my_directory)

# Load occurrence data
species_occurrence <- read.table(paste0(my_directory,
                                        "/hydrography90m_test_data",
                                        "/spdata_1264942.txt"),
                                 header = TRUE)

# Define full path to the basin and sub-catchments raster layer
basin_raster <- paste0(my_directory,
                     "/hydrography90m_test_data/basin_1264942.tif")
subc_raster <- paste0(my_directory,
                    "/hydrography90m_test_data/basin_1264942.tif")

# Extract basin and sub-catchment IDs from the Hydrography90m layers
hydrography90m_ids <- extract_ids(data = species_occurrence,
                                  lon = "longitude",
                                  lat = "latitude",
                                  id = "occurrence_id",
                                  subc_layer = subc_raster,
                                  basin_layer = basin_raster)

# Show the output table
hydrography90m_ids