0

I have a (near) global raster of elevation data in WGS84 with a resolution of 0.00893153 x 0.00893153. I am trying to aggregate it to a resolution of 0.166667 x 0.166667 with the following:

fact = 0.166667/res(elevation_raster)[1]
aggregated <- aggregate(elevation_raster,fact=fact)

However, when I do res(aggregated) I get [1] 0.1706799 0.1706799 where I would expect [1] 0.166667 0.166667.

I'm confused as to why this is happening and can't find anything in the documentation which would suggest a reason for this discrepancy. Any ideas?

1 Answer 1

2

aggregate function decreases resolution x times according to fact. Since it's x times, fact is a positive integer. This is stated in description:

fact postive integer. Aggregation factor expressed as number of cells in each direction (horizontally and vertically). Or two integers (horizontal and vertical aggregation factor) or three integers (when also aggregating over layers). See Details

If you need a specific resolution, use projectRaster function. You can specify the desired resolution with res and the method for computing the new values (nearest neighbor or bilinear). If you are modifying resolution to match with another raster, use that raster as template with this function.

Also, resample function could be used if you have a raster layer as template.

4
  • The projectRaster function very quickly maxes out the RAM on my machine but I will try the resample method with a template to see how that goes
    – A. Bollans
    Commented May 4, 2022 at 14:50
  • 1
    @A.Bollans I recommend you to move from raster to terra package. Most functions have the same syntaxis and it's faster than raster
    – aldo_tapia
    Commented May 4, 2022 at 15:29
  • Is there an equivalent of projectRaster in terra, or would i need to use project and then resample/aggregate?
    – A. Bollans
    Commented May 4, 2022 at 15:48
  • 1
    @A.Bollans the equivalent is project. Use only one function: project or resample/aggregate. Check page 7 in library documentation: cran.r-project.org/web/packages/terra/terra.pdf
    – aldo_tapia
    Commented May 4, 2022 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.