First, we load the required data sets and packages:

load(url("https://userpage.fu-berlin.de/soga/300/30100_data_sets/East_Germany.RData"))
library(raster)
library(gstat)

In this section we apply the IDW approach to interpolate weather data on the basis of measurements taken at 66 DWD weather stations in East Germany. The data set we use (dwd.east.sp) contains the mean annual rainfall and the mean annual temperature for the period from 1981–2010.

plot(dwd.east.sp)
plot(east.germany.states.sp, add = TRUE, border = "red")


Meshgrid for interploation

In most real life use cases we do not interpolate one particular point in space, but we compute the values of our predictor variable on a regular grid. For our use case we build a regular grid with a cell size of 10 km covering the area of East Germany.

In order to set the geographical extend of our grid we take the bounding box of the east.germany.sp spatial data set.

extent.east.germany <- extent(east.germany.states.sp)
extent.east.germany
## class       : Extent 
## xmin        : 137852.8 
## xmax        : 502916.9 
## ymin        : 5561109 
## ymax        : 6060829

Based on the extent of the boundary box we use the expand.grid() function to generate a data frame with x and y coordinates.

grid.east.germany <- expand.grid(x = seq(from = round(extent.east.germany@xmin),
                                  to = round(extent.east.germany@xmax),
                                  by = 10000),
                                 y = seq(from = round(extent.east.germany@ymin),
                                         to = round(extent.east.germany@ymax),
                                         by = 10000))

head(grid.east.germany, 10)
##         x       y
## 1  137853 5561109
## 2  147853 5561109
## 3  157853 5561109
## 4  167853 5561109
## 5  177853 5561109
## 6  187853 5561109
## 7  197853 5561109
## 8  207853 5561109
## 9  217853 5561109
## 10 227853 5561109
tail(grid.east.germany, 10)
##           x       y
## 1841 407853 6051109
## 1842 417853 6051109
## 1843 427853 6051109
## 1844 437853 6051109
## 1845 447853 6051109
## 1846 457853 6051109
## 1847 467853 6051109
## 1848 477853 6051109
## 1849 487853 6051109
## 1850 497853 6051109

For a better understating we plot the generated grid points.

plot(grid.east.germany)