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

Ari Jolma ari.jolma at gmail.com
Tue Jan 26 23:33:08 PST 2016


26.01.2016, 17:58, alex kirjoitti:
> 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,

In map algebra you often have two operands. Assuming two raster bands 
have the same size and georeferencing, how would you write a code that 
works on both of them?

> 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++.

GDAL is written in C++ but it has a C API, which is used with other 
languages.

Ari

>   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
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list