1

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())
  • From gdal.org/frmt_gtiff.html: Currently band types of Byte, UInt16, Int16, UInt32, Int32, Float32, Float64, CInt16, CInt32, CFloat32 and CFloat64 are supported for reading and writing. Byte seems to be the closest hit. – user30184 Nov 20 '14 at 9:53
  • Exactly 8 bits are 1 byte. Thank you for the reminder :) – gustavgans Nov 20 '14 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.