Description Usage Arguments Value Author(s) Examples
View source: R/nearest_point_geo.R
Function to select nearest community to a given sampling point (usually the centroid of a square grid for CSAS or of a hexagonal grid for S3M) using geodesic calculations based on a specified reference ellipsoid
1 2 3 4 5 6 7 8 9 10 | get_nearest_point(
data,
data.x,
data.y,
query,
n = 1,
ellipsoid = c("AA", "AN", "??", "BR", "BN", "CC", "CD", "EB", "EA", "EC", "EF", "EE",
"ED", "RF", "HE", "HO", "ID", "IN", "KA", "AM", "FA", "SA", "WD", "WE"),
duplicate = FALSE
)
|
data |
An input data frame or matrix containing longitude and latitude coordinates of village locations from which to find nearest neighbour |
data.x |
A character value specifying the variable name in |
data.y |
A character value specifying the variable name in |
query |
an object of class 'SpatialPoints' containing sampling point locations. This is usually the output from applying 'spsample()' function from package 'gstat' to create an even spatial sample across the entire sampling area |
n |
Number of nearest villages to select |
ellipsoid |
Two letter character value specifying the reference ellipsoid to use for distance calculations |
duplicate |
Logical. Specify if duplicate selected villages are to be kept or discarded. Default is FALSE (discard). |
A subset data frame of data
of selected villages/communities
nearest to the sampling points with a new variable d
indicating
the distance of the village/community to the sampling point (in kms). If
duplicate
is TRUE, the result has number of rows equal to
nrow(query)
Ernest Guevarra <ernest@guevarra.io>
1 2 3 4 5 6 | # Use get_nearest_point() with test sampling points in Sennar to find 3 nearest
#communities from the sampling points
sennar <- subset(sudan01, STATE == "Sennar")
samp.points <- sp::spsample(sennar, type = "hexagonal", n = 10)
get_nearest_point(data = sennar_villages, data.x = "x", data.y = "y",
query = samp.points, n = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.