I\'m utilizing python GDAL to write a raster data into a .tif file. Here\'s the code:
import numpy, sys
from osgeo import gdal, utils
from osgeo.gdalconst impor
You don't need to Create
then Open
a raster (which you were reading GA_ReadOnly
). You also don't need gdal.AllRegister()
at the beginning, as it has already been called when you load GDAL into Python (see the Raster API tutorial).
Picking up somewhere above (with modifications):
# Create a new raster data source
outDs = driver.Create(out_fname, cols, rows, 3, gdal.GDT_UInt16)
# Write metadata
outDs.SetGeoTransform(inDs.GetGeoTransform())
outDs.SetProjection(inDs.GetProjection())
# Write raster data sets
for i in range(3):
outBand = outDs.GetRasterBand(i + 1)
outBand.WriteArray(data[i])
# Close raster file
outDs = None
Sometimes I add this to ensure the file is fully deallocated, and to prevent running into some gotchas:
del outDs, outBand