Learn R Programming

Tivy (version 0.1.1)

coast_distance: Vectorized distance to coast

Description

Estimates the distance between a set of points (lon, lat) and a coastline defined by coordinates. Can be executed sequentially or in parallel, and also return the indices of the nearest coastal points.

Usage

coast_distance(
  lon,
  lat,
  coastline = NULL,
  return_indices = FALSE,
  distance_type = "haversine",
  unit = "nm",
  window = 1,
  parallel = FALSE,
  cores = 4
)

Value

If return_indices = FALSE, returns a numeric vector with distances to the coast for each point. If return_indices = TRUE, returns a list with distance and index components.

Arguments

lon

Numeric vector with the longitudes of the points of interest.

lat

Numeric vector with the latitudes of the points of interest.

coastline

Data frame with coastline coordinates. Must have columns named Long and Lat. If NULL, uses internal dataset peru_coastline.

return_indices

Logical. If TRUE, also returns the indices of the nearest coastline points.

distance_type

Type of geographic distance to use: "haversine", "euclidean", "grid".

unit

Unit of measurement for distance: "nm" (nautical miles), "km", etc.

window

Search window in degrees around the point to limit calculations and improve efficiency.

parallel

Logical. If TRUE, performs the calculation in parallel using multiple cores.

cores

Number of cores to use for parallel processing.

Examples

Run this code
if (FALSE) {
data_hauls <- process_hauls(data_hauls = calas_bitacora)
distances <- coast_distance(
  lon = data_hauls$lon_final,
  lat = data_hauls$lat_final,
  distance_type = "haversine",
  unit = "nm",
  parallel = TRUE,
  cores = 2
)
}

Run the code above in your browser using DataLab