I was trying to mask the building given its TIFF file and GeoJSON file creating a new raster TIFF file. I don't know what is the problem, the result is all black, here is the code below:
from osgeo import gdal, ogr
def create_building_mask(rasterSrc, vectorSrc, npDistFileName='',
noDataValue=0, burn_values=1):
source_ds = ogr.Open(vectorSrc)
source_layer = source_ds.GetLayer()
srcRas_ds = gdal.Open(rasterSrc)
cols = srcRas_ds.RasterXSize
rows = srcRas_ds.RasterYSize
memdrv = gdal.GetDriverByName('GTiff')
dst_ds = memdrv.Create(npDistFileName, cols, rows, 1, gdal.GDT_Byte)
dst_ds.SetGeoTransform(srcRas_ds.GetGeoTransform())
dst_ds.SetProjection(srcRas_ds.GetProjection())
band = dst_ds.GetRasterBand(1)
band.SetNoDataValue(noDataValue)
gdal.RasterizeLayer(dst_ds, [1], source_layer, burn_values=[burn_values])
dst_ds = 0
return
create_building_mask("img.tif", "img.geojson", npDistFileName='mask.tif', noDataValue=0, burn_values=1)