Closed lvhengani closed 13 hours ago
You can use gdal_rasterize https://gdal.org/en/latest/programs/gdal_rasterize.html. The values to assign are defined with "-burn". With "-i" the pixels outside the polygons will be edited.
That said, a special "mask" option would be nice. It would burn the geometries into a mask band (or alpha), and add the mask/alpha band into the raster if that does not exist yet. So far I have been doing it this way:
Feature description
A command line utility from masking a raster with a vector data (i.e shapefile). This should allow the user to assign a vlaue to the masked out area None (NaN), -999 or any other value. Currentlly gdalwarp does this but lacks functionality of assigning values to the masked area. if the masking is smaller that the raster then the pixels outside the massed area are assigned the NaN value by default or the assigned value if provcided. If the raster is smallet than the masking file then pixels outside the raster are assigned the NaN value or the assigned value.
Additional context
gdalmask input.tif output.tif -mask input_mask.shp -mask-value 0