xarray-spatial icon indicating copy to clipboard operation
xarray-spatial copied to clipboard

How to perform raster/map algebra.

Open theoway opened this issue 4 years ago • 1 comments

Enhancement/Code example: Adding a function where the user can pass the layer(s) from different rasters to perform map algebra and create another raster as the output. Or provide an example of how to perform it using existing features. Suppose, I've two raster layers: red.tif & nir.tif. I load them into variables red & nir. Then, I should be able to create a new layer, output = (red - nir) / (red + nir). This new layer should have the transform and bounding box of the input layers(The input layers will be of the same transforms, projections). Code examples on how to do it would be much appreciated.

theoway avatar Jan 06 '22 07:01 theoway

This module already does that, although, it doesn't provide flexibility to create custom expressions.

theoway avatar May 04 '22 18:05 theoway

I'm going to add a second for this. There's a high appeal for utilising this module - since it does not call GDAL, using xarray/numba etc means that math should generally be highly efficient (vectorised).

I'd like to put xarray-spatial to use in a similar fashion to OP, but with other custom functions built on top of environmental data. Sometimes I may want to simply multiple two rasters, othertimes add, and sometimes perform some particularly complex function that takes many steps in a desktop GIS package but could likely be a single line operation in Python (known from using row data in Pandas / Dask, but would love to be able to do the same with rasters).

Neither the documentation or current examples suggest that this is possible, though obviously its exactly what the xarray-spatial is doing with its custom functions.

sxwebster avatar Jan 15 '23 07:01 sxwebster

@sxwebster hey sorry for late reply. I'd be happy to chat more about your use case.

brendancol avatar Jun 02 '23 16:06 brendancol