I want to export my processed raster layer which are np arrays as tif with following steps, after creating the out.tif raster with the driver I could not load the created tif file back into python. I tried to change the 'gdal.GDT_Int32' into other types but it didn't work. I also tried using instead of 'inds.GetDriver' 'GetDriverByName('GTiff') but that also didn't make any changes, messages as below:
In [13]: driver.Create('out.tif', cols, rows, 1, gdal.GDT_Int32)
Out[13]: <osgeo.gdal.Dataset; proxy of <Swig Object of type
'GDALDatasetShadow *
' at 0x000000000F437360> >
In [18]: outds=gdal.Open('out.tif')
-----------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-18-82ed958ff66e> in <module>()
----> 1 outds = gdal.Open('out.tif')
RuntimeError: `out.tif' not recognised as a supported file format.
or
In [14]: outds = gdal.Open('out.tif')
ERROR 4: `out.tif' not recognised as a supported file format.
My code:
#load inds for processing
inds = gdal.Open('in.tif', gdal.GA_ReadOnly)
cols = inds.RasterXSize
rows = inds.RasterYSize
driver = inds.GetDriver()
driver.Create('out.tif', cols, rows, 1, gdal.GDT_Int32)
**#The step with errors!**
**outds = gdal.Open('out.tif')**
outband = outds.GetRasterBand()
data = inds.GetRasterBand().ReadAsArray()
outds.SetGeoTransform(inds.GetGeoTransform())
outds.SetProjection(inds.GetProjection())
outband = outds.GetRasterBand()
outband.WriteArray(data)