[gdal-dev] How to read an image of any data type

Jerome More jerome.more at hotmail.fr
Tue Jan 14 14:23:08 PST 2020

Hello to all gdal community members,

I had a very basic question, but I couldn't find a proper answer anywhere in the forums or mailing lists, even on the official tutorials like:

So my simple question is how to handle properly a "generic" data type (i.e. known only at runtime) when reading a raster dataset from an image.

So far I could use properly GetRasterDataType / RasterIO to read my data, but I always have to specify in my code the actual data type (ex uint16_t).

The best workaround that I could find is, first read the dataset as "raw" binary data (i.e. type=uint8_t) then "interpret" it to the proper actual type (ex uint16_t).
But this is still a heavy solution and moreover during the data interpretation I could not avoid a copy of the complete dataset !
Even my attemps to use templates did not help much because they only apply to functions (not variables or members) and don't really solve the problem.

So to sum up I would like to:
1) open an image (e.g. a tiff image with 1 single band) WITHOUT knowing its data type beforehand
2) store the raster dataset in a variable of any kind, WITHOUT making copy or type cast (I mean involving math operations ) !
3) easily find and print some values (ex: image[0;0])

I will appreciate any answer on this subject !
Thank you all.

Jérôme Moré.
PS: I included my current code in a separate file.

Envoyé à partir d’Outlook<http://aka.ms/weboutlook>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200114/28139705/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdal_mwe.cpp
Type: text/x-c++src
Size: 3723 bytes
Desc: gdal_mwe.cpp
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200114/28139705/attachment.cpp>

More information about the gdal-dev mailing list