col*_*etl 5 r raster spatial resampling r-raster
我想将人口栅格聚合1.5倍,将细胞的值相加.
虽然aggregate()允许我在聚合时对值求和,但其factor参数仅接受整数值.projectRaster()并resample()允许我精确地调整分辨率,但(据我所知)我被限制在预先打包的双线性插值和最近邻计算方法.
有没有办法通过非整数因子聚合栅格并指定聚合时要使用的函数?
library(raster)
set.seed(10)
proj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
r <- raster(resolution = 1, nrow = 100, crs = proj)
r[] <- round(rnorm(ncell(r), 100, 10))
# Doesn't accept non-integer factors
aggregate(r, fact = 1.5, fun = sum)
template <- raster(extent(r), crs = crs(r), resolution = 1.5)
# Correct resolution, but incorrect / impossible values for population
projectRaster(r, to = template, method = "ngb")
projectRaster(r, to = template, method = "bilinear")
Run Code Online (Sandbox Code Playgroud)
到目前为止,我能够提出的唯一方法是将模板强制转换为SpatialPoints对象; 从原始的高分辨率栅格中提取值; 而rasterize()结果:
pts <- as(template, "SpatialPoints")
vals <- extract(r, pts)
pts2 <- SpatialPointsDataFrame(pts, data.frame(vals))
rasterize(pts2, template, field = "vals", fun = sum)
Run Code Online (Sandbox Code Playgroud)
但是,如果在栅格单元的质心处创建点,我不确定在以原始栅格的1.5倍分辨率提取时如何处理它们.我首选的方法是创建一个SpatialPolygonsDataFrame和栅格化fun = mean,但(根据我的经验)使用多边形提取栅格值是非常低效的.
这里有一个解决方法:
#first resample to higher resolution
template <- raster(extent(r), crs = crs(r), resolution = .5)
detailedRas <- projectRaster(r, to = template, method = "ngb")
#then use an integer as a factor (in this case 3)
aggRas <- aggregate(detailedRas, fact=3, fun=sum)
Run Code Online (Sandbox Code Playgroud)
但请注意,这种情况下的总和不会返回居住在某个聚合区域的人口总和。
即:假设我们有四个像元,这些值的分辨率为 1 m:
10 15
12 18
Run Code Online (Sandbox Code Playgroud)
使用 NN 重采样到 0.5 后:
10 10 15 15
10 10 15 15
12 12 18 18
12 12 18 18
Run Code Online (Sandbox Code Playgroud)
然后按总和聚合到 1.5m,我们得到第一个像素:
10+10+15+10+10+15+12+12+18 = 112
事实上它应该是这样的:10 + 15/2 + 12/2 + 18/4 = 28(如果我们假设每个像素上的人口分布相等。)
我建议使用focal栅格函数和自定义/用户定义的函数来根据您的意愿汇总人口值。
或者将重新采样的栅格除以 4,然后求和:
2.5 2.5 3.75 3.75
2.5 2.5 3.75 3.75
3 3 4.5 4.5
3 3 4.5 4.5
Run Code Online (Sandbox Code Playgroud)
2.5 + 2.5 + 3.75 + 2.5 + 2.5 + 3.75 + 3 + 3 + 4.5 = 28
| 归档时间: |
|
| 查看次数: |
767 次 |
| 最近记录: |