Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 Shape file (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 beeing 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?

Thank you

Ulrik

share|improve this question
add comment

2 Answers

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

share|improve this answer
    
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. –  Ulrik Balslev Nov 10 '12 at 9:15
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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