-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interpolation.Rmd
executable file
·91 lines (73 loc) · 2.25 KB
/
Interpolation.Rmd
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: Interpolation
author:
- ESR 512 - GIS in Geostatistics
- Postgraduate Institute of Science
- University of Peradeniya
- Thusitha Wagalawatta & Daniel Knitter
date: 10/2015
email: [email protected]
bibliography: Course_Statistics_SriLanka.bib
csl: harvard1.csl
output:
html_document:
toc: false
theme: united
pandoc_args: [
"+RTS", "-K64m",
"-RTS"
]
pdf_document:
toc: false
toc_depth: 2
number_sections: true
pandoc_args: [
"+RTS", "-K64m",
"-RTS"
]
highlight: pygments
---
```{r setup, eval=TRUE, echo=FALSE}
setwd("/media/daniel/homebay/Teachings/WS_2015-2016/Statistics_SriLanka/")
```
## Interpolation ##
As an example we will interpolate the altitude of the peak shapefile.
```{r eval=TRUE, echo=TRUE}
library(rgdal)
srtm <- readGDAL("./results/srtm.tif")
str(srtm@proj4string)
peaks <- readOGR(dsn = "./data/DSL250-Shp/", layer = "Peaks")
str(peaks)
peaks <- spTransform(x = peaks, CRSobj = srtm@proj4string)
```
We will start with a determinstic interpolation approach that you should be familiar with: Inverse Distance Weighting (IDW).
```{r idw}
library(gstat)
peak_idw <- idw(peaks@data$ALTITUDE ~ 1, peaks, srtm, maxdist = 200000, idp = 2)
#spplot(peak_idw)
plot(raster(peak_idw))
#contour(peak_idw, add=TRUE)
points(peaks,pch=20,cex=.4)
```
Now, let us try a statistical interpolation approach, i.e. simple Kriging.
```{r kriging}
library(gstat)
plot(variogram(peaks@data$ALTITUDE ~ 1, peaks, cloud = TRUE))
plot(variogram(peaks@data$ALTITUDE ~ 1, peaks))
plot(variogram(peaks@data$ALTITUDE ~ 1, peaks, alpha = c(0,45,90,135)))
vt <- variogram(peaks@data$ALTITUDE ~ 1, peaks)
show.vgms()
v.fit <- fit.variogram(vt,
vgm(nugget = 0, model = "Gau", psill = 800000, range = 40000))
v.fit2 <- fit.variogram(vt,
vgm(nugget = 0, model = "Sph", psill = 800000, range = 40000))
plot(vt,v.fit)
plot(vt,v.fit2)
peak_k <- krige(peaks@data$ALTITUDE ~ 1, peaks, srtm, v.fit,nmin = 3, maxdist = 300000, nmax = 7)
peak_k2 <- krige(peaks@data$ALTITUDE ~ 1, peaks, srtm, v.fit2,nmin = 3, maxdist = 300000, nmax = 7)
par(mfrow = c(1,2))
plot(raster(peak_k),main="Kriging using Gaussian fit")
points(peaks,pch=20,cex=.4)
plot(raster(peak_k2),main="Kriging using Spherical fit")
points(peaks,pch=20,cex=.4)
```