I am trying to rasterize a layer as follows:
attr = 'N_CT'
tif_driver = gdal.GetDriverByName('MEM')
raster = tif_driver.Create(path, x_res, y_res, num_bands, gdal.GDT_UInt16)
shp_driver = ogr.GetDriverByName('ESRI Shapefile')
shp_mem = shp_driver .Open('x.shp')
# loop through each layer in shapefile, add to raster band(s)
for idx in len(shp_mem.GetLayerCount()):
lyr = shp_mem.GetLayer(i)
gdal.RasterizeLayer(raster, [i+1], lyr, options=['ATTRIBUTE=' + attr])
*Do some raster computations*
# create .TIF
raster = createRaster(shp,'GTiff', path)
# configure band
band = raster.GetRasterBand(1)
band.Fill(NO_DATA_VALUE)
band.SetNoDataValue(NO_DATA_VALUE)
# write band
band.WriteArray(arr)
raster = None
What happens above is I rasterize a shapefile called 'x.shp' based on a field called N_CT (integers)
However, the output contains what I desire but surrounding it is what I imagine is no data (with value 0 - in black).
I could set my band no_data value to 0. However, is there a way I can change this default (0) to something that I don't need?
options=['init=somenumber', 'a_nodata=thesamenumber', 'ATTRIBUTE=' + attr]
. Haven't added as an answer as I can't test.