英文:
How to downscale a raster layer with GDAL resampling to 95th percentile?
问题
如何计算每个降采样栅格单元的95th百分位数?
假设我们有一个高分辨率的栅格图层(1米数字地表模型),想要创建一个分辨率较低的版本(50米地表模型)。与传统的中位数等标准指标不同,我们想要将新的栅格单元分配为底层值的95th百分位数。
例如,使用gdalwarp -tr 50 50 -r med dsm_1m.tif dsm_50m_percentile.tif
,我们可以计算中位数版本。而且,gdalwarp
支持进一步的重采样方法,如第一和第三四分位数的q1
或q3
,但没有选项来定义自定义值。
英文:
How can we calculate the 95th percentile for each raster cell of a downsampled raster?
Lets say we have a high resolution raster layer (1m digital surface model) and want to create a version of it with lower resolution (50m surface model). Instead of standard metrics such as median we want to assign the new raster cells with the 95th percentile of the underlaying values.
With e.g. gdalwarp -tr 50 50 -r med dsm_1m.tif dsm_50m_percentile.tif
we could calculate the median version. And gdalwarp
supports further resampling methods such as q1
or q3
for the first and third quartile, but no option to define custom values.
答案1
得分: 0
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)
英文:
gdal seems not to support this out of the box.
Alternatives are e.g.:
with 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
with 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论