[gdal-dev] C++ Range and Iterator for GDALDataSet

alex alexhighviz at hotmail.com
Tue Jan 26 07:58:48 PST 2016


Hi,

I developed a C++ class that wraps around a GDALDataSet. The class has
associated iterator class and begin() and end() member functions, so it can
be used with range-based for-loops. The iterator goes over all pixels
row-by-row (so not block-by-block as proposed in a recent message). 

The use of the class is basic. The following program prints all values in
the first rasterband of "input.tif" :

auto raster = open_gdal_dataset<int>("input.tif", GA_ReadOnly):
for(auto&& i : raster) {
  std::cout << i << std::endl;
}

I found these classes very useful for simple map algebra type applications,
when used in conjunction with a (my own) zip range. For instance the
following program creates a new dataset containing the square roots of the
input dataset. 

auto input = open_gdal_dataset<int>("input.tif", GA_ReadOnly);
auto output = create_gdal_dataset_from_model<double>("output.tif", input);
auto zip = make_zip_range(std::ref(input), std::ref(output));
for(auto&& i : zip) {
  std::get<1>(i) = std::sqrt(static_cast<double>(std::get<0>(i)) );
}

I am also using the classes for more complex analysis, such as moving window
analysis and distance transforms. Furthermore, I created classes to iterate
in col-major order and to iterate over edges (pairs of adjacent pixels)
instead of pixels.

I have made the source available on github (www.github.com/ahhz/raster),
however I would rather see this integrated in an existing and active open
source project. 
 
I realize that the primary language of GDAL is not C++. However, this may
still be of interest. Could you please let me know if this would be of
interest to GDAL or perhaps point me to a more appropriate project.

Thanks, Alex



More information about the gdal-dev mailing list