I would like to write an array to a geotiff with Python script using the GDAL module. When I try to do something simple like copying an existing GeoTiff via reading it to an array, then, writing to a new array, QGIS reads the integer value 1 as "nan". I have verified that the actual values that QGIS presents as "nan" are the integer value 1 in the GeoTiff. Is there some additional information that I need to write to the GeoTiff file so that QGIS will read my integer values of 1 as 1? My code is copied below:
import os
import gdal
os.chdir(r'C:\Users\pipi\Documents\Rogaine\Tarlo\gpx')
in_ds = gdal.Open('0011aa0011aa.tif')
in_band = in_ds.GetRasterBand(1)
noData = in_band.GetNoDataValue()
if noData:
pass
else:
noData = 0
cols = in_band.XSize
rows = in_band.YSize
# Creates an output file with the same dimensions and data type.
out_ds = gdal.GetDriverByName('GTiff').Create(
'master.tif', cols, rows, 1, gdal.GDT_Byte)
out_ds.SetProjection(in_ds.GetProjection())
out_ds.SetGeoTransform(in_ds.GetGeoTransform())
out_band = out_ds.GetRasterBand(1)
data = in_band.ReadAsArray()
out_band.WriteArray(data)
out_band.SetNoDataValue(noData)
del out_ds
out_band.ComputeStatistics(False)
to the script it does not change the outcome. Is this what you mean by "try forcing the computation of stats"?