gdalcubes_cpp icon indicating copy to clipboard operation
gdalcubes_cpp copied to clipboard

Possibility to pipe raster cubes?

Open glaroc opened this issue 3 years ago • 5 comments

We have a use case where we would like to take a land cover map, say at 250 meter resolution, isolate one category, and resample it at 1 km resolution to identify the proportion of 250 m pixels of that category within each 1km pixel. In other words, we would need to do something like

prop12 <- raster_cube(col, cube_view(dx = 250, dy = 250, ....),...) |> 
apply_pixel(function(v) {v[1]==12}) |> 
raster_cube(cube_view(dx = 1000, dy = 1000, resampling='average',....),...)

This is not possible, but is there another way of doing this without bringing the 250 m raster in memory ?

glaroc avatar Apr 28 '22 21:04 glaroc

No, there is currently no method to reduce the spatial resolution of a cube. The implementation should be relatively straightforward though, because there is already aggregate_time(), which seems to do exactly this (but in time). Happy to work on aggregate_space for the next release. For now, maybe terra / stars can do this without loading everything into memory?

appelmar avatar Apr 29 '22 08:04 appelmar

Yes, an aggreate_space function would be perfect for this!

glaroc avatar Apr 29 '22 15:04 glaroc

This is now added to the GitHub version of the package. Still needs some more testing but the following should now work:

prop12 <- raster_cube(col, cube_view(dx = 250, dy = 250, ....),...) |> 
   apply_pixel(function(v) {v[1]==12}) |> 
   aggregate_space(dx = 1000, dy = 1000,  method = "mean") 

appelmar avatar May 03 '22 19:05 appelmar

Wonderful ! We'll test it and let you know if we have issues!

glaroc avatar May 03 '22 19:05 glaroc

It seems to work like charm! Thank you for putting this together so quickly.

glaroc avatar May 05 '22 17:05 glaroc