CLI: Allow "gdal vector rasterize" to initialize/clean an existing raster band
Feature description
Use case: I have converted footprint polygons into tiffs which I will later add into a raster maps as alpha bands with a VRT file. Sometimes the footprints are wrong and the mask tiffs must be updated. I want to keep the existing tiff and update only the values because the mask band must have the same size than the main raster, and I have already taken care of that.
The following command fails obviously because --init can only be used when creating a new output file.
gdal vector rasterize --init 0 --burn 255 -i mask.json -o output-alpha.tif --update
ERROR 6: '-tr xres yres' or '-ts xsize ysize' is required.
As a workaround I can run rasterize twice, first burn the pixels outside the polygon into 0 and then burn the pixels inside the polygon into 255. However, I am a bit worried if some old transparency pixels with wrong values from the initial mask may remain.
Additional context
No response
Wouldn't the following be the most natural way:
gdal raster create --like output-alpha.tif output-alpha-new.tif
gdal vector rasterize --burn 255 -i mask.json -o output-alpha.tif --update
mv output-alpha-new.tif output-alpha.tif
There may me many most natural ways (not including your example if followed literally and updating output-alpha.tif 😉 . Because I have also the main maps available I can save one command by starting over
gdal raster create --like mainmap.tif --band-count 1 output-alpha.tif --overwrite
gdal vector rasterize --burn 255 -i mask.json -o output-alpha.tif --update
But what if the alpha is already included in the RGBA file? Then the create-a-new-file-and-rename method cannot be used.