I think I understood the steps to write an array to a raster file using python. however it doesn't work in my case and I don't know why. I have an array that I want to write to a Geotiff with Swiss Oblique Mercator Projection. I have a DEM as Geotiff in the exact same location with same projections and Geotransform, so I thought I just read all parameters from that DEM and use them to write my new raster.Here's the code that I'm, using:
driver.Register()fn = '/media/LACIE_SHARE/davos2015.tif'inDs = gdal.Open(fn)if inDs is None: print 'Could not open ' + fn sys.exit(1)rows=inDs.RasterYSizecols=inDs.RasterXSizedriver=inDs.GetDriver()outDs=driver.Create('/home/grassdata/test.tif',cols,rows,1,gdal.GDT_Float32)if outDs is None: print "crap" sys.exit(1)outBand=outDs.GetRasterBand(1)outData=coh0 #coh0 is the array I want to convert to raster. it's an array with float32 entries. outBand.WriteArray(outData) # this gives 0outBand.FlushCache()outBand.SetNoDataValue(-99) #this gives 0outDs.SetGeoTransform(inDs.GetGeoTransform()) #this gives 0outDs.SetProjection(inDs.GetProjection()) #this gives 0del outDatathe lines where I commented accordingly raise 0 as result and I don't understand why...Thanks for the help!
أكثر...
driver.Register()fn = '/media/LACIE_SHARE/davos2015.tif'inDs = gdal.Open(fn)if inDs is None: print 'Could not open ' + fn sys.exit(1)rows=inDs.RasterYSizecols=inDs.RasterXSizedriver=inDs.GetDriver()outDs=driver.Create('/home/grassdata/test.tif',cols,rows,1,gdal.GDT_Float32)if outDs is None: print "crap" sys.exit(1)outBand=outDs.GetRasterBand(1)outData=coh0 #coh0 is the array I want to convert to raster. it's an array with float32 entries. outBand.WriteArray(outData) # this gives 0outBand.FlushCache()outBand.SetNoDataValue(-99) #this gives 0outDs.SetGeoTransform(inDs.GetGeoTransform()) #this gives 0outDs.SetProjection(inDs.GetProjection()) #this gives 0del outDatathe lines where I commented accordingly raise 0 as result and I don't understand why...Thanks for the help!
أكثر...