View source: R/near.obs.soil.R
near.obs.soil | R Documentation |
The function finds n nearest observations from given locations and at specific depth range from location min depth and creates an object of data.frame class. First n columns are Euclidean distances to n nearest locations and next n columns are observations at n nearest stations, and rows are given locations. It is based on knn function of package nabor.
near.obs.soil(locations,
locations.x.y.md = c(1,2,3),
observations,
observations.x.y.md = c(1,2,3),
obs.col = 4,
n.obs = 5,
depth.range = 0.1,
no.obs = 'increase',
parallel.processing = TRUE,
pp.type = "doParallel", # "snowfall"
cpus = detectCores()-1)
locations |
data.frame with x and y coordinates and mid depth columns, or sf-class, SpatVector-class or SpatRaster-class object; Locations (FROM) for which n nearest observations are found and distances are calculated. |
locations.x.y.md |
numeric or character vector; Positions or names of the x, y, and mid depth columns in |
observations |
data.frame with x, y, mid depth and observation columns, or sf-class or SpatVector-class object with mid depth and observation columns; Observations (TO). |
observations.x.y.md |
numeric or character vector; positions or names of the x, y, and mid depth columns in |
obs.col |
numeric or character; Column name or number showing position of the observation column in the |
n.obs |
numeric; Number of nearest observations to be found. Note that it cannot be larger than number of obsevrations. Default is 5. |
depth.range |
numeric; Depth range for location mid depth in which to search for nearest observations. It's in the mid depth units. Default is 0.1. |
no.obs |
character; Possible values are |
parallel.processing |
logical; If parallel processing is performed. Default is FALSE. |
pp.type |
character; Type (R package) used for parallel processing, "doParallel" (default) or "snowfall". |
cpus |
numeric; Number of processing units. Default is detectCores()-1. |
data.frame object. Rows represents specific locations. First n.obs
columns are Euclidean distances to n.obs
nearest observations. Next n.obs
columns are observations at n.obs
nearest stations.
The function is intended for soil mapping applications.
Aleksandar Sekulic asekulic@grf.bg.ac.rs, Anatol Helfenstein anatol.helfenstein@wur.nl
knn
near.obs
rfsi
pred.rfsi
tune.rfsi
cv.rfsi
library(sp)
library(sf)
library(meteo)
# prepare data
# load observation - data.frame of mean temperatures
demo(meuse, echo=FALSE)
meuse <- meuse[complete.cases(meuse@data),]
locations = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
locations = # terra::rast(meuse.grid)
observations = st_as_sf(meuse, coords = c("x", "y"), crs = 28992, agr = "constant")
# find 5 nearest observations and distances to them (remove duplicates)
nearest_obs <- near.obs.soil(locations = locations, # from
locations.x.y.md = c("x","y","dist"),
observations = observations, # to
observations.x.y.md= c("x","y","dist"),
obs.col = "zinc",
n.obs = 5) # number of nearest observations
str(nearest_obs)
summary(nearest_obs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.