How do I clip a shapefile with a raster file with gdalwarp?
Input: a shapefile
Cutter: a raster file
Output: a cut shapefile
I can only find the answer of cutting the raster file by a shapefile but not vice versa.
How do I clip a shapefile with a raster file with gdalwarp?
Input: a shapefile
Cutter: a raster file
Output: a cut shapefile
I can only find the answer of cutting the raster file by a shapefile but not vice versa.
Try to create the data extent of the raster e.g. with gdal-dans-scripts (apt install dans-gdal-scripts) by using gdal_trace_outline like (ndv is the no data value that will be not considered so if you need to clip with certain value you can create a mask before):
gdal_trace_outline clipper_image.tif -ndv 0 -dp-toler 10 -min-ring-area 10000 -no-donuts -ogr-out clipper_shape.shp
Also you can try to vectorize your raster e.g. with gdal_polygonize.
And then clip with ogr2ogr:
ogr2ogr your_shape_to_be_clipped.shp -clipsrc clipper_shape.shp final_clip.shp