我有一个与 shapefile 重叠的 geotiff 文件。要剪辑 tif 文件的重叠部分,我可以这样做:
gdalwarp -co compress=deflate -dstnodata 255 -cutline shapefile.shp original.tif overlap.tif
但是我怎样才能剪辑非相交部分?也就是说,我想创建"overlap.tif"
wrt的补充"original.tif"
。
You can use gdal_rasterize to burn a value where the shapefile overlaps the file. It works on an existing file, so make sure you use a copy.
gdal_rasterize -burn 255 shapefile.shp copy_of_original.tif
This burns a value of 255, setting -a_nodata 255
doesnt work on my version of GDAL. If you need it to be a real nodata value using gdal_translate
with -a_nodata 255
afterwards would do the trick.
Gdal_rasterize also has a convenient -i
flag which inverts the shapefile.