[gdal-dev] Map algebra, update

Ari Jolma ari.jolma at gmail.com
Mon Apr 18 08:28:43 PDT 2016


Folks,

Some updates on the RFC 62.

Working on the code, I've managed to rewrite the C++ API almost 
completely OO. There is a need for only a bootstrap function, which 
constructs a new band object from a regular GDALRasterBand. The map 
algebra methods are methods of this object. The new band class is an 
interface class with only virtual methods. The actual implementations of 
the virtual methods are in templated classes, which take care of all 
datatypes etc.

The inner workings are pretty complex, for example two band operations 
need to go from an interface class to a template class and then to a 
second template class via one more interface class. The second template 
class has two datatypes and the first one datatype as template 
parameter. Control is moved from band level operation to block level 
operation with method pointers.

I've added support for nodata values and mask bands, so that, for 
example when summing two bands, nodata values and masked out cells can 
be ignored.

In the actual code I'm still moving the code from functions to methods, 
so it's a mixture but all the test and demo codes should work. OO makes 
the code much more readable, here's an example:

     GDALDriver *d = GetGDALDriverManager()->GetDriverByName("MEM");
     int w_band = 16, h_band = 10;
     GDALDataset *ds = d->Create("", w_band, h_band, 2, GDT_Int32, NULL);
     GDALRasterBand *b = ds->GetRasterBand(1);

     gma_band_t *bx = (gma_band_t*)gma_new_object(b, gma_band);
     bx->rand();
     bx->modulus(20);
     bx->print();
     bx->add(5);
     bx->print();

     GDALRasterBand *b2 = ds->GetRasterBand(2);
     gma_band_t *by = (gma_band_t*)gma_new_object(b2, gma_band);
     by->rand();
     by->modulus(10);
     by->print();
     bx->add(by);
     bx->print();

I'm expecting that the amount of code becomes less with this more OO 
approach and especially the switch tables of GDAL datatype are reduced 
to the minimum.

I've studied STL and I'm using it, but for a simple hash (integer type 
to object) I did not find I good solution in STL so I'm still using a 
DYI one.

Ari



More information about the gdal-dev mailing list