3

I have a shapefile with a single geometry as the following:

enter image description here

I also have a GeoTIFF raster that I can put behind this vector layer... I'd like to find a way of programmatically clipping this shapefile feature from my GeoTIFF file, in a way that I get a png image as a result.

The closest solution I found to this problem is this answer. This solution solves the problem using gdalwarp with the following command line:

gdalwarp -of GTiff -cutline area_of_interest.shp -cl area_of_interest  -crop_to_cutline PCE_in_gw.asc  data_masked7.tiff 

In my case, I only have the Shapefile and the GeoTIFF file. I didn't get what I'm supposed to put on the .asc file and the area_of_interest parameter in this command line sample. What extra procedures do I have to do to clip my GeoTIFF with a Shapefile while using gdalwarp?

2 Answers 2

2

From the command line you can do the following:

gdalwarp -of GTiff -cutline input.shp -crop_to_cutline input.tif input_clip.tif

Another alternative is with pkcrop from pktools

pkcrop -i input.tif -e input.shp -cut -o input_clip.tif

2

Look this example in Pyhton and Jupyter Notebook:

gdal.Warp(destNameOrDestDS = outputpath, 
          srcDSOrSrcDSTab  = intputpath, 
          cutlineDSName    = shapefile or geojson, 
          cropToCutline    = True,
          copyMetadata     = True,
          dstNodata        = 0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.