I am a novice with GIS and geospatial data, so I may be missing something basic.

I am working on a process which takes an input PNG, performs a calculation on each input pixel and writes the result to a single-band floating-point tiff. The whole process is achieved using the GDAL C# bindings. When I open my raster in QGIS, I am not seeing my expected output, even after adjusting the symbology settings.

The "layer properties" in QGIS indicate that my raster contain the data that I want; the histogram tab generating a histogram, roughly, with the values I expect.

When spot checking the pixels using the identify feature setting on the mouse, all of the values for the pixels I checked have a value of "nan".

My process for generating the tif is something like this (please assume CRS, GeoTransform and datatypes are correct, and code builds, runs):

// original data
Dataset PNGDataset = Gdal.Open(...);

//get the tiff driver
OSGeo.GDAL.Driver GDALRasterDriver =

// create output dataset
Dataset outDataset = GDALRasterDriver.Create(rasterOutPath,
                outx, outy, 1, DataType.GDT_CFloat32, null);

// read input band 
Band pngBand = cPNGDataset.GetRasterBand(1);
byte[] buffer = new byte[pngBand.XSize *
pngBand.ReadRaster(0, 0, pngBand.XSize, pngBand.YSize,
                pngBand, pngBand.XSize, pngBand.YSize, 0, 0);

float[] floatBuffer = new float[pngBand.XSize * pngBand.YSize];
for (int i = 0; i < (pngBand.XSize * pngBand.YSize); i++)
   floatBuffer[i] = // calculation based on input values
Band outputBand = outDataset.GetRasterBand(1);
outputBand.WriteRaster(0, 0, pngBand.XSize, pngBand.YSize,
                floatBuffer, pngBand.XSize, pngBand.YSize, 0, 0);

1 Answer 1


I discovered the issue. I made an error in the code when creating the output dataset. The output type should be DataType.GDT_Float32 rather than DataType.GDT_CFloat32. The latter specifies a complex floating point number, which does not appear to be supported by QGIS at the moment. After changing that the output raster displays perfectly.

The line in the code should be changed to: Dataset outDataset = GDALRasterDriver.Create(rasterOutPath, outx, outy, 1, DataType.GDT_Float32, null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.