Processing of GeoTiffs containing DEM 32-bit floating point data

Topics: SharpMap v0.9 / v1.x
Jan 27, 2016 at 3:20 PM
Hi again :)

Up until now my use of SharpMap for processing Tiff files has been to be able to create TMS bitmaps. My source Tiff files are not on tile boundaries, so I have to load and correctly project multiple Tiffs, and then render the required tiles. This has worked beautifully, and uses the following code:
using (Bitmap bmp = new Bitmap(256, 256))
   var mapBox = new Map(bmp.Size);
   var bbox = GeometryTransform.TransformBox(...);

   using (Graphics g = Graphics.FromImage(bmp))
      foreach (var file in _fileList)
         var layer = new GdalRasterLayer(file, file);

The problem I now have is that I need to make similar 256x256 tiles containing 16 bit signed values of elevation. My source Tiff files for this are 32-bit floating point gridded matrix.

Using the above method nicely stitches the Tiff files together and creates a BMP, but of course the data has been mangled - I don't think internally it is necessarily being read as floating point, and certainly by the time an 8 bit ARGB bitmap has been created as grey scale, the elevation data is no longer usable, obviously!

Is there a simple approach to achieve what I want, without throwing away the functionality of projections and extracting the required extent from loading multiple Tiffs, however also preserving the 32 bit data.... my target is to convert to signed 16bit in a 256x256 array binary file.

Many thanks for any suggestions!
Jan 28, 2016 at 8:26 AM
Out of the box this is not possible. Sorry, but you will have to code that yourself.
Jan 29, 2016 at 12:44 AM
Further investigation, by setting the format of my Bitmap to Format64bppArgb, I can actually get 16 bit values that appear to be related, though incorrectly, to the elevation data extracted from the GeoTiffs. It is as if the ONLY issue is incorrect reading of the GeoTiff 32-bit float point data..... for example, if my Tiff contains the range -0.141 to 138.998, the layer StretchPoint is 0 to 138, and the Bitmap when using Format32bppArgb is loaded with values between 0 and 138. But when using Format64bppArgb the values are 0 to 1253. When the Tiff contains -9999 to 16 because of NODATA, the stretch again is correct, but the Bitmap is loaded with values from 0 to 7206. Likewise when the Tiff data is 0 to 8, the Bitmap is loaded with 0 to 7. It is as if there is some non-linear factor affecting the conversion from 32bit FP to 16 bit int?

This is so close to working! Any thoughts would be much appreciated as everything else is sorted with this approach... :)

Jan 29, 2016 at 8:42 AM
Tim, copy this to a work item and provide a sample tiff-file.