如何使用GDAL重采样将栅格图层缩小到95th百分位数?

huangapple go评论49阅读模式
英文:

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支持进一步的重采样方法,如第一和第三四分位数的q1q3,但没有选项来定义自定义值。

英文:

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=&#39;dsm_1m.tif&#39; --method=11 --quantile=0.95 --output=&#39;dsm_50m_percentile.tif&#39; --GRASS_REGION_CELLSIZE_PARAMETER=50

with R terra::aggregate()

library(terra)

input &lt;- &quot;dsm_1m.tif&quot;
output &lt;- &quot;dsm_50m_percentile.tif&quot;

f = function(v){
  quantile(v, .95, type = 1, na.rm=TRUE)
}

aggregate(r, fact=50, fun=f, filename = output)

huangapple
  • 本文由 发表于 2023年8月10日 21:50:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定