find_dists_new: Calculate (signed) distances between coordinates

View source: R/find_dists_new.R

find_dists_newR Documentation

Calculate (signed) distances between coordinates

Description

Calculate (signed) distances between coordinates

Usage

find_dists_new(
  locations,
  locations_new,
  longlat = TRUE,
  origin = 1L,
  return_grid = FALSE,
  ...
)

Arguments

locations

A matrix or data.frame of 2D points, the first column is x/longitude, and the second column is y/latitude.

locations_new

A matrix or data.frame of 2D points, the first column is x/longitude, and the second column is y/latitude.

longlat

Logical, if TURE Great Circle (WGS84 ellipsoid) distance; if FALSE, Euclidean distance.

origin

Optional; used when longlat is TRUE. An integer index indicating the reference location from locations which will be used as the origin. Same origin from find_dists must be used to ensure consistancy between outputs from find_dists and find_dists_new.

return_grid

Logical; used when longlat is TRUE. If TRUE the mapped coordinates on a 2D plane for all locations is returned.

...

Optional arguments passed to .find_dists_new().

Details

locations and locations_new must be matrices or data.frames containing 2 columns, first column x/longitude, and second column y/latitude. The row names of locations and locations_new are used as the names of the locations.

If longlat is TRUE, the original coordinates are mapped to a 2D Euclidean plane given the reference location from locations. First, the Great Circle (WGS84 ellipsoid) signed distance matrices are calculated, where the original latitudes are replaced by the the mean of latitudes in locations to find the signed longitudinal distances and the original longitudes are replaced by the the mean of longitudes in locations to find the signed latitudinal distances. Then given the index of a reference location origin, a new set of coordinates in a 2D plane is generated where the coordinates are determined by the signed distances between the locations and the reference location. Finally distance matrices of the new coordinates for all stations are outputted.

Value

A list of distance matrices for all locations. If return_grid is TRUE, a list consists of a list of distance matrices for all locations, the mapped 2D grid for all locations, and the origin is returned.

Examples

lon <- c(110, 120, 130)
lat <- c(50, 55, 60)
locations <- cbind(lon, lat)
rownames(locations) <- paste("Site", 1:3)
find_dists(locations)

locations_new <- c(115, 55)
find_dists_new(locations, locations_new)

mcgf documentation built on June 29, 2024, 9:09 a.m.