[GIS] mask raster with shapefile using gdalwarp/gdal

gdalgdalwarprastershapefile

I am struggling to use gdalwarp with cutline option.
The following command keeps failing and I do not understand why :

gdalwarp  -cutline shapefile.shp  file.tiff newfile.tiff

Warning 1: Self-intersection at or near point 1890.1578688362522 >211.13062073074084

ERROR 1: Cutline is not valid after transformation

The produced file is indeed not valid being filled with NA …
I tried with several shapefiles and tiff files but I could not make it works.

I use debian and gdal version 2.1.0

Best Answer

Try adding the option

--config GDALWARP_IGNORE_BAD_CUTLINE YES

to gdalwarp, like this:

gdalwarp --config GDALWARP_IGNORE_BAD_CUTLINE YES -cutline shapefile.shp file.tiff newfile.tiff