Extracts depth from basemap bathymetry raster dataset for coordinates in a data frame
Usage
get_depth(
data,
bathy.style = "raster_continuous",
lon = NULL,
lat = NULL,
shapefile = "DecimalDegree",
proj.in = 4326,
bind = TRUE,
depth.col = "depth",
verbose = FALSE
)Arguments
- data
Data frame or sf object containing geographic coordinates.
- bathy.style
Character defining the basemap bathymetry raster which should be used for the depth extraction. Valid alternatives:
"raster_binned"(or"rb"),"raster_continuous"(or"rc"; default), or"raster_user"(or"ru").- lon, lat
Either the names of the longitude and latitude columns in
dataorNULLto guess the longitude and/or latitude columns indata.- shapefile
Land shape to which distances should be calculated. Either a character argument referring to a name of pre-made shapefiles in
shapefile_list, a single sf orsppolygons object object orNULLto enable automatic definition of the land shapes based ondata. Set to"DecimalDegree"by default which enables great circle distances using s2 features assuming a spherical Earth (as a contrast to earlier versions of the function which used flat Earth).- proj.in
coordinate reference systemofdata.- bind
Logical indicating whether
xshould be returned with the distances (TRUE, default) or should the distances be returned as vector (FALSE).- depth.col
The name of the depth column, if
bind = TRUE. Defaults to "depth".- verbose
Logical indicating whether information about the process should be returned as messages. Set to
FALSEto make the function silent.
Value
Returns a vector if bind = FALSE, otherwise a data frame. The depths are given in a new column defined by the dist.col argument. The distances are kilometers. NA distance means that the position is on land.
Details
Uses the st_extract function to extract values from basemap bathymetry raster grids. Does not work for vector bathymetries.
Examples
if (FALSE) {
dt <- data.frame(lon = seq(-20, 80, length.out = 41), lat = 50:90)
dt <- get_depth(dt)
qmap(dt, color = depth) + scale_color_viridis_c()
}