I have a fine-scale raster (say 30 m) and a coarse-scale raster (say 100 m). I would like to use R to resample the fine-scale raster to produce a new, coarser raster at 100 m in which the grid perfectly aligns with my existing 100 m raster (same origin and resolution). I would like the values in the new 100 m raster to reflect the average of all the 30 m raster cells that fall within it, but where each 30 m cell's contribution to the 100 m cell mean is weighted by the proportion of each 30 m cell that falls within the 100 m cell. Is there a function (and package) in R that I can use for this?
I am aware of GDAL's gdalwarp
, but it appears to consider finer-resolution pixels as either "contributing" or "not contributing" to the coarser pixels without the possibility of partially contributing based on the percentage of the finer pixel that falls within the coarser pixel.
Another approximation is to use the aggregate
function in the raster
package to get as close as possible to the target resolution (in this case, an aggregation factor of 3 to yield a 90 m raster) and then sync the resulting grid to align with my existing 100 m grid using the spatial_sync_raster
function in the spatial.tools
package. However, this approach results in excessive smoothing and data loss relative to an approach where the raster is aggregated and synced in a single step.
Any help would be much appreciated!
Building on @jgadoury's suggestion, I found an approach that more closely achieves my desired outcome:
projectRaster
aggregate
The finer you make your raster in step #1, the less you smooth over local highs and lows (i.e., the less data you have contributing to a given 100m pixel from areas outside that pixel), but the less efficient the process becomes.