Description Usage Arguments Value Author(s) Examples
View source: R/nearest_point_nn.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) based on a nearest neighbour algorithm using Euclidean calculations
1 |
data |
An input data frame or matrix containing longitude and latitude coordinates of village locations from which to find nearest neighbour |
x1 |
A character value specifying the variable name in |
y1 |
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 |
x2 |
A character value specifying the variable name in |
y2 |
A character value specifying the variable name in |
n |
A numeric value speciyfing the maximum number of nearest neighbours to search for |
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 coordinate
units). 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 7 | # Use get_nn() 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_nn(data = sennar_villages, x1 = "x", y1 = "y",
query = samp.points, x2 = "x", y2 = "y",
n = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.