OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.92k stars 2.56k forks source link

gdalmask #11322

Closed lvhengani closed 13 hours ago

lvhengani commented 16 hours ago

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

jratike80 commented 16 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: