I am trying to perform the following task, but it does not seem to work:

I have got a raster file (raster.tif) containing an aerial photo, which I want to clip using a shapefile (clip.shp) that contains a polygon. The result I want is raster file (clipped.tif) containing the aerial photo inside the clip polygon and the rest being transparent, so I can overlay my clipped raster on an OSM map.

Basically I did this:

gdalwarp -cutline clip.shp raster.tif clipped.tif

The resulting clipped.tif shows the correct clipped aerial photo, but surrounded by a black background covering the extent of the original raster.tif file.

I have played around with the dstnodata and the dstalpha options, but with no luck. I am not exactly professor in raster processing, so the alpha channel stuff is new to me.

Any good ideas of how to perform such an operation?

2 Answers 2


Try the combination of options from the link below. It worked for me and shows the correct transparency in QGIS. You can grab the gralwarp command-line from there or try using the UI.

Clip a Raster in an Irregular Shape using QGIS

  • Hi Thanks for the tip. The QGIS raster clipping functionality is fine, that it is possible to see the command-line command beeing composed as you configure the clipping in the GUI. The only problem was that I was not able to actually do the clipping in QGIS as I keep getting the error "Cannot compute bounding box of cutline." Both raster and clipping file are in the same native SRS. When I copy the command-line gdalwarp -q -cutline clip.shp -crop_to_cutline -dstalpha -of GTiff raster.tif out.tif, gdalwarp acts if there is a syntaks error. Commented Nov 10, 2012 at 9:15
  • I have the same problem. Did you ever find a solution? Commented Nov 5, 2020 at 21:59

OK, I found the solution (work around). I realized, that I was working with an old version of gdalwarp, where the -cut_to_cropline option was not supported! Anyway I got an upgrade done and it seem to accept this option. I still got the "Cannot compute bounding box of cutline" error, that obviously has something to do with my cutline shape file. I removed the .prj file and ... tata ... it worked.

  • Ulrik Balslev, where the .prj file exist?
    – newGIS
    Commented Jul 16, 2017 at 6:46

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.