简体   繁体   中英

How to dowscale a raster but keeping the same values?

If I have this raster with 40 x 40 resolution.

 library(raster)
 #get some sample data
 data(meuse.grid)
 gridded(meuse.grid) <- ~x+y
 meuse.raster <- raster(meuse.grid)
 res(meuse.raster)
 #[1] 40 40

I would like to downscale this raster to 4 x 4. If a pixel of 40x40 = 125, so use the same values for all pixels of 4x4x within this pixel.

just divide each pixel of 40 x40 into 4x4 with keeping its value.

I am open to CDO solutions as well.

We can use raster::disaggregate

library(raster)

#get some sample data
data(meuse.grid)
gridded(meuse.grid) <- ~x+y
meuse.raster <- raster(meuse.grid)

#assign geographic coordinate system (from coordinates and location (Meuse) it seems like the standard projection for the Netherlands (Amersfoort, ESPG:28992)
crs(meuse.raster) <- "EPSG:28992"

#disaggregate
meuse.raster.dissaggregated <- disaggregate(meuse.raster, c(10,10))

I used c(10,10) to disaggregated from a 40x40 to 4x4 resolution (10 times more detailed).

res(meuse.raster.dissaggregated)
[1] 4 4

In the comments Chris mentioned the terra package. I also recommend shifting from raster to terra . I believe its the newest package and will eventually replaces packages like raster and stars .

terra also has a disaggregation function terra::disagg() which works in a similar way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM