Skip to content
Prev 28363 / 29559 Next

stars analogous of raster::aggregate

On 9/8/20 8:47 PM, Micha Silver wrote:
Yes; if you want to get similar behaviour as raster, choose a cell size 
that is an exact multiple of the origin's cell size, use_gdal = TRUE, 
and method = "average"; this currently seems to only work for single 
band rasters; along these lines:

library(stars)
# Loading required package: abind
# Loading required package: sf
# Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
l7_file = system.file("tif/L7_ETMs.tif", package = "stars")
l7 = read_stars(l7_file)
(dest = st_as_stars(st_bbox(l7), dx = 90, dy = 90))
# stars object with 2 dimensions and 1 attribute
# attribute(s):
#     values
#  Min.   :0
#  1st Qu.:0
#  Median :0
#  Mean   :0
#  3rd Qu.:0
#  Max.   :0
# dimension(s):
#   from  to  offset delta                       refsys point values x/y
# x    1 111  288776    90 UTM Zone 25, Southern Hem...    NA   NULL [x]
# y    1 112 9120761   -90 UTM Zone 25, Southern Hem...    NA   NULL [y]
(l7_lowres = st_warp(src = l7[,,,1], dest = dest, use_gdal = TRUE, 
method = "average"))
# stars object with 2 dimensions and 1 attribute
# attribute(s):
#  file14bb5c7321dc.tif
#  Min.   : 56.81
#  1st Qu.: 68.75
#  Median : 79.00
#  Mean   : 79.25
#  3rd Qu.: 88.62
#  Max.   :207.44
# dimension(s):
#   from  to  offset delta                       refsys point values x/y
# x    1 111  288776    90 UTM Zone 25, Southern Hem... FALSE   NULL [x]
# y    1 112 9120761   -90 UTM Zone 25, Southern Hem... FALSE   NULL [y]