我最近研究了R,必须制作1km x 1km的网格。因此,我已经在代码下面做了。但是shapefile(korea, seoul and WGS84)
不能准确地添加(或覆盖)到网格中。
因此,我需要您的帮助来解决此问题。
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84+towgs84=0,0,0
seoullayer_t <- spTransform(seoullayer, CRS("+init=epsg:3857"))
x <- min(coordinates(seoullyaer_t)[,1]) ; x
y <- min(coordinates(seoullyaer_t)[,2]) ; y
但是,shpaefile和gird(raster)并不完全匹配。
如何解决这个问题... seoullayer <- rgdal :: readOGR(dsn = 'd:/seoullayer',
layer = 'test_4326',
encoding = 'CP949')
seoullayer_t <- spTransform(seoullayer, CRS("+init=epsg:3857"))
# Define number of cells of Grid
x <- min(coordinates(seoullyaer_t)[,1]) ; x
y <- min(coordinates(seoullyaer_t)[,2]) ; y
x_cell <- 46
y_cell <- 37
cell_size <- 1000
ext <- extent(x, x + (x_cell * cell_size), y, y + (y_cell * cell_size))
ras <- raster(ext)
#Set the resolution to be
res(ras) <- c(cell_size, cell_size)
ras[] <- rnorm(ncell(ras))
projection(ras) <- CRS("+init=epsg:3857")
plot(ras)
plot(seoullayer_t, add = T)
我希望将网格分辨率设为1km x 1km,并将值(例如温度,PM10的浓度,O3等)放入网格中。因此,最后我想使用“反距离加权法”来预测没有实际值的值。
请帮助我这样做。谢谢。
答案 0 :(得分:0)
您可以做类似的事情
library(raster)
g <- getData("GADM", country="South Korea", level=1)
m <- spTransform(g, "+proj=merc +a=6378137 +b=6378137 +units=m")
r <- raster(m, res=10000)
但是,您选择的坐标参考系统(水星)不是一个好的选择,因为它不是等面积投影。另请注意,写出“ proj.4”描述比使用EPSG代码更好,因为这些代码是不透明的(您看不到相关信息)。我不知道对韩国来说,好的信用证是什么,但您可以查一下。 UTM可能是合理的。
m <- spTransform(g, "+proj=utm +zone=52 +datum=WGS84")
r <- raster(floor(extent(m)), res=10000)
(我四舍五入得到整数)。