Description Usage Arguments Value Author(s) Examples
View source: R/interpolate_points.R
This function tries to interpolate points based on given parameters
1 2 3 4 5 6 7 | interpolate_points(
sp_points,
aim_variable,
outputfile,
co_variables = FALSE,
procedure = c("ked", "rfk", "ok", "idw")
)
|
sp_points |
SpatialPointsDataframe containing the aim variable and if "ked" should be applied the covariables |
aim_variable |
Character string with the name of the aim variable |
outputfile |
SpatialPointsDataframe, SpatialGridDataFrame or raster which should be filled with predictions; requires covariables for "ked" (if two values are given in a vector a raster is created with the resolution given by the values) |
co_variables |
default = FALSE, vector of covariables if needed |
procedure |
default = c("ked","rfk,"ok","idw"); vector containing the interpolation technic to be used; the first method is used and if this does not work out, the second, and so on; KED = Kriging With external Drift; RFK = Random Forest Kriging; OK = Ordinary Kriging; IDW = Inverse distance Weighting |
interpolated point values as sp or raster file depending on outputfile
Wolfgang Hamer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | library(magrittr)
library(dplyr)
library(sp)
library(raster)
# Download example data
shdat <- download_statewide_hourly_station_data(state = "Schleswig-Holstein", coord = TRUE)
# Select data of specific Time / Date
da_sel <- shdat %>% dplyr::filter(DateTime == sort(unique(shdat$DateTime))[5])
# Create spatial dataset
da_sel_sp <- SpatialPointsDataFrame(da_sel[,c("lon", "lat")],
da_sel,
proj4string = CRS("+init=epsg:4326"))
# Transform to projected (m based!) system
da_sel_sp <- spTransform(da_sel_sp, CRS("+init=epsg:25832"))
# Manually creating points of interest
preds <- SpatialPointsDataFrame(data.frame(x=c(9.5,9.0,10.4,10.5,9.9,10.5),
y=c(53.5, 54.69,54.44,53.93,53.65, 54.55)),
data.frame(lat=c(9.5,9.0,10.4,10.5,9.9,10.5),
lon=c(53.5, 54.69,54.44,53.93,53.65, 54.55)),
proj4string = CRS("+init=epsg:4326"))
outputpoints <- spTransform(preds, CRS("+init=epsg:25832"))
# Application of function for point data result
myintpoints <- interpolate_points(sp_points = da_sel_sp,
aim_variable = "Temperature",
outputfile = outputpoints,
co_variables = c("lat","lon"),
procedure = c("ked","ok","idw"))
# Create raster of interest
outputraster <- raster(ncol=100, nrow=100)
extent(outputraster) <- extent(outputpoints)
crs(outputraster) <- CRS("+init=epsg:25832")
outputraster[]<- rep(1,length(outputraster$layer[]))
# Application of function for raster data result
myintraster <- interpolate_points(sp_points = da_sel_sp,
aim_variable = "Temperature",
outputfile = outputraster,
co_variables = c("lat","lon"),
procedure = c("ked","ok","idw"))
# Application of function for raster data result
myintraster2 <- interpolate_points(sp_points = da_sel_sp,
aim_variable = "Temperature",
outputfile = c(500,500),
co_variables = c("lat","lon"),
procedure = c("ked","ok","idw"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.