[Qgis-developer] Raster algebra C++

Marco Hugentobler marco.hugentobler at sourcepole.ch
Thu Oct 14 11:40:03 EDT 2010


Hi devs,

A very cool and handy tool is Alexander Bruys raster algebra plugin. It's so 
usefull in environmental modelling that Tim and I thought it would be good to 
have it in our analysis library (where it can be used by 3rd party 
applications too and without the dependency of the numpy library).
So here is my initial patch that implements a calculator tool as part of the 
analysis library by extending the search string mechanism.


Compared to the python plugin, is has some missing features (but they could be 
added):
- no 'difference' and 'NDVI' buttons
- only outputs float32 rasters
- no possibility to load / save expressions

On the other side, it has some additional features:
- Possibility to insert output extent and resolution and do calculations with 
layers that have different resolutions / extent. If a layer resolution does not 
match, it is automatically resampled to the output resolution (of course with 
higher computation costs)
- Selection of output format


You can try the functionality by applying the following patch:
http://karlinapp.ethz.ch/101014_qgis_rastercalculator.diff
The menu to open the calculator is located under 'Layer->Raster calculator'.

I didn't apply it to trunk directly, as it needs more testing and there are 
still some issues:

- Flex detects a string as raster if it has '@' followed by a single number 
(the raster band number). Don't know if there are better solutions, especially 
to avoid conflicts with vector columns named that way.

- QgsSearchTreeValue is extended with a new type to represent a raster matrix 
and with new operators and methods doing matrix operations. This class needs 
some code cleaning before applying to trunk

- Handling of nodata values could be done in a more clever way: out of band 
values during resampling receive the nodata value of the input raster band. In 
case of error (e.g. division through zero), QgsSearchStingValue applies 
'-100000'.

- More testing is needed. Especially with the automatic resampling option, 
there is a high risk for rounding errors. Send me a mail if you found a bug 
(possibly with a sample dataset and easy instruction on how to reproduce).


Looking forward for your feedback,
Marco




-- 
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Webereistrasse 66, 8134 Adliswil, Switzerland
marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee


More information about the Qgis-developer mailing list