今天实现了一个任务:
代码不复杂,但实际上步骤挺绕。
1)读取有CSV格式的points数据,对其重新采样,得到grid数据
2)读取带有zone属性的多边形矢量数据。
3)对grid数据和多边形数据进行spatial overlay,对每个grid得到多边形的zone特征
library(rgdal)
library(gstat) # Use gstat's idw routine
library(sp) # Used for the spsample function
library(raster) # Used to clip out thiessen polygons
imos=read.csv('D://research//GHM//imos.csv') ## 导入points的CSV文件
coordinates(imos) <- c("lon","lat")#定义坐标
vector <- readOGR('D:/research/3_GHM/Result/Zone/shp2.shp') ## 导入泰森三角形矢量文件
# Add P's projection information to the empty grid
proj4string(imos) <- proj4string(imos) # Temp fix until new proj env is adopted
proj4string(vector) <- proj4string(imos)
grd <- as.data.frame(spsample(imos, "regular", n=50))
names(grd) <- c("X", "Y")