appelmar / gdalcubes_cpp

Earth observation data cubes from GDAL image collections
MIT License
74 stars 7 forks source link

Possibility to pipe raster cubes? #43

Closed glaroc closed 1 year ago

glaroc commented 2 years ago

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 ?

appelmar commented 2 years ago

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?

glaroc commented 2 years ago

Yes, an aggreate_space function would be perfect for this!

appelmar commented 2 years ago

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") 
glaroc commented 2 years ago

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

glaroc commented 2 years ago

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