我们如何计算下采样栅格的每个栅格像元的第 95 个百分位数?
假设我们有一个高分辨率栅格图层(1m 数字表面模型),并且想要创建一个较低分辨率的版本(50m 表面模型)。我们希望为新的栅格单元分配基础值的第 95 个百分位数,而不是中位数等标准指标。
例如
gdalwarp -tr 50 50 -r med dsm_1m.tif dsm_50m_percentile.tif
我们可以计算中值版本。并且 gdalwarp
支持进一步的重采样方法,例如针对第一和第三四分位数的 q1
或 q3
,但没有定义自定义值的选项。
gdal 似乎不支持开箱即用。
替代方案例如:
与 GRASS Gis
r.resamp.stats
grass7:r.resamp.stats --input='dsm_1m.tif' --method=11 --quantile=0.95 --output='dsm_50m_percentile.tif' --GRASS_REGION_CELLSIZE_PARAMETER=50
与 R
terra::aggregate()
library(terra)
input <- "dsm_1m.tif"
output <- "dsm_50m_percentile.tif"
f = function(v){
quantile(v, .95, type = 1, na.rm=TRUE)
}
aggregate(r, fact=50, fun=f, filename = output)