Extracts depth from basemap bathymetry raster dataset for coordinates in a data frame
get_depth(
data,
bathy.style = "raster_continuous",
lon = NULL,
lat = NULL,
shapefile = "DecimalDegree",
proj.in = 4326,
bind = TRUE,
depth.col = "depth",
verbose = FALSE
)
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.
Data frame or sf object containing geographic coordinates.
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"
).
Either the names of the longitude and latitude columns in data
or NULL
to guess the longitude and/or latitude columns in data
.
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 or sp
polygons object object or NULL
to enable automatic definition of the land shapes based on data
. 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).
coordinate reference system
of data
.
Logical indicating whether x
should be returned with the distances (TRUE
, default) or should the distances be returned as vector (FALSE
).
The name of the depth column, if bind = TRUE
. Defaults to "depth".
Logical indicating whether information about the process should be returned as messages. Set to FALSE
to make the function silent.
Mikko Vihtakari
Uses the st_extract
function to extract values from basemap bathymetry raster grids. Does not work for vector bathymetries.
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()
}
Run the code above in your browser using DataLab