# 大样地海拔数据的克里格插值与地形图绘制

setwd("C:/Users/jlzhang/Desktop/bubeng plot")

library(gstat)

library(sp)

library(raster)

library(openxlsx)

library(lattice)

#### 边长为20m米的点阵

bubeng.grid <- expand.grid(x = seq(0, 400, 20), y = seq(0, 500, 20))

coordinates(bubeng.grid) <- ~ x + y

gridded(bubeng.grid) <- TRUE

## 数据来源 https://doi.org/10.1371/journal.pone.0108450.s008

bubeng.topo20160318 <- read.xlsx("bubeng_topo.xlsx")

## 指定横纵坐标

coordinates(bubeng.topo20160318) = ~ x + y

## 变异函数

bubeng_variogram <- variogram(alt ~ 1, data = bubeng.topo20160318)

plot(bubeng_variogram)

### 拟合高斯模型， 初始值选择参见 How Kriging works—Help

bubeng_variogram.fit = fit.variogram(bubeng_variogram, model = vgm(psill = 10, "Gau", range = 200, nugget = .1))

plot(bubeng_variogram, bubeng_variogram.fit)

### 进行克里格插值

bubeng.krig <- krige(alt ~ 1, bubeng.topo20160318, bubeng.grid, model = bubeng_variogram.fit)

### 绘图

levelplot(bubeng.krig$var1.pred ~ bubeng.krig$x+bubeng.krig$y, cuts = 50, main="Ordinary kriging predictions",contour = TRUE, labels = TRUE, col.regions = terrain.colors(255)pretty = TRUE) ## 三维图 wireframe(bubeng.krig$var1.pred ~ bubeng.krig$x+bubeng.krig$y,

main="Ordinary kriging predictions",

labels = TRUE, col.regions = terrain.colors(255)pretty = TRUE, drape = TRUE)

## 转换为raster

dat <- data.frame(bubeng.krig$var1.pred, bubeng.krig$x, bubeng.krig\$y)

### Convert the object x to a raster object.

rdat <- raster(bubeng.krig)

### plot the raster

plot(rdat, col = terrain.colors(255))

contour(rdat, add = TRUE, nlevel = 15)

### 获得每个20m样方的中心点

x10 <- seq(10, 400-10, by = 20)

y10 <- seq(10, 500-10, by = 20)

grids10 <- expand.grid(x10, y10)

plot(Var2 ~ Var1, data = grids10)

coordinates(grids10) <- c(1, 2)

###raster图层中提取海拔

alt_center <- extract(x = rdat, y = grids10)

### 20m样方的中心点海拔数据

res_alt_center <- data.frame(grids10, alt_center)

• How Kriging works—Help | ArcGIS for Desktop. (2018). Available at: http://desktop.arcgis.com/en/arcmap/10.3/tools/3d-analyst-toolbox/how-kriging-works.htm. Last accessed 24 April 2018.

• Hu, Y.-H., Kitching, R.L., Lan, G.-Y., Zhang, J.-L., Sha, L.-Q. & Cao, M. (2014). Size-Class Effect Contributes to Tree Species Assembly through Influencing Dispersal in Tropical Forests. PLoS ONE, 9, e108450.

https://m.sciencenet.cn/blog-255662-1110708.html

## 全部精选博文导读

GMT+8, 2022-11-29 15:42

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社