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 fromlocations
which will be used as the origin. Sameorigin
fromfind_dists
must be used to ensure consistancy between outputs fromfind_dists
andfind_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()
.
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.
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.
Examples
lon <- c(110, 120, 130)
lat <- c(50, 55, 60)
locations <- cbind(lon, lat)
rownames(locations) <- paste("Site", 1:3)
find_dists(locations)
#> $h
#> Site 1 Site 2 Site 3
#> Site 1 0.0000 847.5798 1692.986
#> Site 2 847.5798 0.0000 845.408
#> Site 3 1692.9859 845.4080 0.000
#>
#> $h1
#> Site 1 Site 2 Site 3
#> Site 1 0.0000 -639.3934 -1275.5045
#> Site 2 639.3934 0.0000 -636.1111
#> Site 3 1275.5045 636.1111 0.0000
#>
#> $h2
#> Site 1 Site 2 Site 3
#> Site 1 0.000 -556.3880 -1113.2338
#> Site 2 556.388 0.0000 -556.8459
#> Site 3 1113.234 556.8459 0.0000
#>
locations_new <- c(115, 55)
find_dists_new(locations, locations_new)
#> $h
#> Site 1 Site 2 Site 3 New_1
#> Site 1 0.0000 847.5798 1692.986 641.7978
#> Site 2 847.5798 0.0000 845.408 319.4921
#> Site 3 1692.9859 845.4080 0.000 1106.0085
#> New_1 641.7978 319.4921 1106.009 0.0000
#>
#> $h1
#> Site 1 Site 2 Site 3 New_1
#> Site 1 0.0000 -639.3934 -1275.5045 -319.9013
#> Site 2 639.3934 0.0000 -636.1111 319.4921
#> Site 3 1275.5045 636.1111 0.0000 955.6032
#> New_1 319.9013 -319.4921 -955.6032 0.0000
#>
#> $h2
#> Site 1 Site 2 Site 3 New_1
#> Site 1 0.000 -556.3880 -1113.2338 -556.3880
#> Site 2 556.388 0.0000 -556.8459 0.0000
#> Site 3 1113.234 556.8459 0.0000 556.8459
#> New_1 556.388 0.0000 -556.8459 0.0000
#>