26

I have a raster file and want to clip it, a vector file is supposed to be the mask layer. I use the most obvious method (Raster->Extraction->Clipper). No matter what I do, I get this error (see picture below):

Cannot compute bounding box of cutline

I tried it with changing the raster format, changing the projection etc. Of course I made research in older posts/Google too. I have no Idea how to solve this problem. If I clip by extend it does work.

Weird thing is, I remember doing this three months ago, same method and I did not get this error.

I also would (instead of a solution for this error) welcome an alternative way to perform this action. I just need to clip a rasterfile as described. Can someone help?

error

7
  • 3
    strange. guess: check, if your raster and your vectorfile have the same projection
    – Kurt
    Aug 29, 2012 at 7:42
  • you mean right click on layer and then set crs, right? I did. It is the same.
    – Shepherdjo
    Aug 29, 2012 at 7:53
  • Have you tried a polygon that lies completely inside the raster? For example by intersecting your polygon with another rectangular polygon that has the exact extend of the raster.
    – AndreJ
    Aug 29, 2012 at 8:35
  • Hm..I understand what you mean. But how can I get a polygon that has the the exact extend of the raster?
    – Shepherdjo
    Aug 29, 2012 at 9:06
  • 1
    Vector -> Research Tools -> Polygon from layer extend
    – AndreJ
    Aug 29, 2012 at 9:51

4 Answers 4

24

After trying around with everything I finally figured out how to solve the problem. It had indeed to do with the CRS. Right click "Set CRS" was not enough here. I had to perform (on the raster) Raster->Projections->Warp, then set the desired CRS again and save as Geotiff.

The mask layer (vector layer) had to be saved again with the same CRS. After that the process worked.

Still weird, because I know, that in 1.7.4 it did work immediately. I can remember pretty well, because that was when I started with QGIS.

3
  • I had this problem as well. I was trying to clip a Geotiff Raster which I had exported previously from AutoCAD Rasterdesign. There seemed to be multiple problems with this Geotiff. Since I had the same error message "cannot compute bounding box of cutline" I reprojected the file with gdalwrap without setting any CRS for "source" nor for "target". after this process I was not able to open the Geotiff. So I figured that additionally to this problem, the compression of the export in AutoCAD had to be set to "JPG" and not "raw-data". Then I repeated the solution from above and I was finally able t
    – user19482
    Jun 26, 2013 at 11:27
  • 1
    You do not have to warp per see, you can just save te raster file again as gtiff with the right CRS. This should also solve this problem. Jun 22, 2016 at 12:45
  • I had the same issue programmatically using gdalwarp. Set -s_srs fixed the problem. (for those using gdalwarp directly without qgis)
    – juminet
    Jan 4, 2019 at 11:38
6

After removing the '.prj' files from the directory with my shapefiles, my batch file ran without a hitch. Solution discovered at OSGeo's Using gdalwarp to effectively trim an image.

1
  • This is the answer, thanks for it.
    – Gery
    Aug 8, 2022 at 17:13
2

Since you don't want to do a clip by extend I assume you want to extract the raster cells that are inside each geometric figure of the vector file.

One way to do this, is to add a field in the vector file with the value 1, export it to raster format with the same resolution as the raster you have. This will create you a raster with value 1 for the geometric figures and 0 for the background. Finally you just need to multiply both rasters.

3
  • ok, I made a raster of the vector file with the field with the value 1, same resolution. What do you mean with "multiply both rasters"?
    – Shepherdjo
    Aug 29, 2012 at 9:17
  • by using the qgis raster calculator. check this tutorial: spatialgalaxy.net/2012/01/25/using-the-qgis-raster-calculator
    – Gago-Silva
    Aug 29, 2012 at 9:20
  • So...not completely sure but: my expression has to be simply raster1(derived from vector) * raster2(actual raster), right?
    – Shepherdjo
    Aug 29, 2012 at 9:39
2

As a test I've just used the Raster -> Extraction -> Clipper method to clip a raster image with no problems at all. The illustration shows the clipped part of the map image together with the polygon used for clipping.

QGIS Master, Ubuntu 12.04 (64-bit). You're in Windows by the look of it, but you do not specify the version of QGIS that you are using.

enter image description here

4
  • I know this method actually works pretty fine. But I think I m on the right track...I just need to try around more.. Qgis Version is 1.8.0.
    – Shepherdjo
    Aug 29, 2012 at 11:20
  • 2
    Just triple-checking. The raster and the polygon vector both have the same native CRS? In other words, they align properly with on-the-fly transformation disabled? If so, it might be worth trying again with OTF turned off. It might also be worth checking the validity of the vector layer's geometry (from under the Vector menu). N.
    – nhopton
    Aug 29, 2012 at 11:33
  • @shepherdjo did you check, what nhopton asked you to do: check geometry validity of your vector layer via vector-geometry tools - check geometry validity??
    – Kurt
    Aug 29, 2012 at 20:43
  • @nhopton, @Kurt; I figured it out, see answer.
    – Shepherdjo
    Aug 30, 2012 at 6:25

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