Search code examples
rrasterprojectionarea

R How to multiply the values of the raster pixels with the true surfaces of these pixels?


I want to multiply the precipitation values (mm) of each pixel of a raster by the area corresponding to each of these pixels under R.

At first, I directly multiplied the raster by the average pixel area (Total area / number of pixels). But if we work on a global scale with the WGS84 projection, in reality the pixel area at the equator and in the high latitude regions is very different? That is why I am asking this question.

Thank you in advance for your help


Solution

  • You can calculate the value of each pixel per unit area (here in meters) using:

    rows = init(raster , v='y') # latitude bands 
    PI = 3.14159265359 # PI number
    earth_radius = 6371007.181 # radius of earth in meter
    raster_resolution = xres(raster) # resolution of the raster layer
    
    new_raster <-  raster  * (( raster_resolution * (PI / 180) * earth_radius) * ( raster_resolution * (3.14159265359 / 180) * earth_radius * cos(rows/180*PI)))