[gdal-dev] Setting nodata tag with Python API
Roger André
randre at gmail.com
Thu Dec 31 10:58:08 EST 2009
Hi All,
I'm using the Python API to build some GeoTIFFs and would like to set
the nodata value to -9999 at creation time. How do I do that? Below
is a sample of my code
def makeRaster(self):
out_drv = gdal.GetDriverByName('GTiff')
out_ds = out_drv.Create(self.raster_name, 4320, 2160 , 1, gdal.GDT_Float32)
out_ds.SetGeoTransform([-180, 0.0833330, 0, 90, 0, -0.0833330])
out_band = numpy.zeros([out_ds.RasterYSize, out_ds.RasterXSize])
for iY in range(out_ds.RasterYSize):
for iX in range(out_ds.RasterXSize):
alloc_key = self.makeAllocKey(iY + 1, iX + 1)
pixel_value = self.checkPixel(alloc_key)
out_band[iY][iX] = pixel_value
out_ds.GetRasterBand(1).WriteArray(out_band)
out_ds = None
Thanks,
Roger
--
More information about the gdal-dev
mailing list