我有一个数据框,其中包含栅格单元的x和y坐标的最小值和最大值。它是这样开始的:
xmin ymin ymax xmax
1 -73.99139 -18.04158 -17.04158 -72.99139
2 -72.99139 -18.04158 -17.04158 -71.99139
3 -71.99139 -18.04158 -17.04158 -70.99139
4 -70.99139 -18.04158 -17.04158 -69.99139
5 -69.99139 -18.04158 -17.04158 -68.99139
6 -68.99139 -18.04158 -17.04158 -67.99139
继续约800行,其中每行代表一个栅格单元
似乎raster
包中的raster
函数允许将xmn
设置为最小x坐标(左边框)以及xmx
和{{1 }和ymn
。然而,这是关于整个rastr对象本身的栅格范围...而不是单个细胞。
如何创建具有单个单元格值的栅格对象?
答案 0 :(得分:0)
这样的事情怎么样......
当df是具有最小值和最大值的数据帧时:
xmin ymin ymax xmax
1 -73.99139 -18.04158 -17.04158 -72.99139
2 -72.99139 -18.04158 -17.04158 -71.99139
3 -71.99139 -18.04158 -17.04158 -70.99139
4 -70.99139 -18.04158 -17.04158 -69.99139
5 -69.99139 -18.04158 -17.04158 -68.99139
6 -68.99139 -18.04158 -17.04158 -67.99139
#calculate point center
xcoords <- (df[,"xmax"] - df[,"xmin"])/2 + df[,"xmin"]
ycoords <- (df[,"ymax"] - df[,"ymin"])/2 + df[,"ymin"]
#create dataframe from coordinates
points <-data.frame("x"=c(xcoords),
"y"=c(ycoords))
#create raster
ras <- raster(SpatialPoints(points))