[GIS] Create 8Bit unsigned GeoTIFF with GDAL

gdalgeotiff-tiffpython

I'm trying to create a 8 bit GeoTIFF with this code.

Is there a way to use unsigned 8 bit? I only found the GDT_UInt16?

import numpy as np
from osgeo import ogr, osr, gdal
from osgeo.gdalconst import *

dataset = gdal.Open('test.tif')
driver = dataset.GetDriver()
driver.Create("out.tiff", cols, rows, 1, GDT_UInt16) # <- here

out_band = out_dataset.GetRasterBand(1)
out_data = np.zeros((rows,cols), np.int16)
out_band.WriteArray(out_data, 0, 0)
out_band.FlushCache()
out_dataset.SetGeoTransform(dataset.GetGeoTransform())
out_dataset.SetProjection(dataset.GetProjection())

Best Answer

The gdal documentation describes the GDT_Byte as an 8 bit unsigned integer (see here). So the correct gdal constant is the GDT_Byte. In your code it would be:

driver.Create("out.tiff", cols, rows, 1, gdal.GDT_Byte)