I need to clip a raster layer with a vector layer. When I try this, the following error appears:

**ERROR 1: Attempt to create 0x0 dataset is illegal,sizes must be larger than zero.** 

What am I doing wrong?

  • Sorry! QGIS. I tried to use the same projektion for both layers but it didn´t work
    – Lisa E.
    Commented Apr 3, 2013 at 22:12
  • what is your raster resolution? what are the dimensions of your vector layer?
    – Gago-Silva
    Commented Apr 5, 2013 at 15:57

1 Answer 1


The problem was in the source files. If you open one of those files (i.e. map-3), you'll see that they have 4 bands. I think the four band is an alpha channel (for transparency) added by some photoediting software (photoshop, gimp). To drop the 4th band on the merged image, use the raster conversion tool and edit the command line by hand:

gdal_translate -b 1 -b 2 -b 3 sourcefilename.tif bands.tif

Now, you have a 3 band raster. Then, you'll see that the clipper tool won't work. Why? I don't know (I think source file are corrupted). So, use another strategy: rasterize the polygon in the rav.shp file (I'll call ravrast.tif the raster version), and then use the raster calculator to extract the values of the 3 bands:

output file: band1.tif; expression: bands@1 * ravrast@1 output file: band2.tif; expression: bands@2 * ravrast@1 output file: band3.tif; expression: bands@3 * ravrast@1

Now, you have to merge these three files. Use the Raster/Miscellaneus/Union menu voice.

The final command of this tool should appear as follows:

gdal_merge.py -separate -of GTiff -o united.tif band1.tif band2.tif band3.tif

Now, united.tif will contain the clipped 3 bands image you were searching, but there is one last step, in order to remove the black color for notada cells. From the command line, type:

rgb2pct.py -n 256 united.tif final.tif

(I'm on linux, maybe on Windows it can be rgb2pct.bat)

Load the final.tif file on QGIS, ask for pixel values in the black area of the image, then go to the layer properties and set nodata or transparent pixel values to this number (in my case (the file that I attached).

The final file is a pseudo-colored tif file. You can edit it on QGIS or on gimp and save it an another format.



  • sorry for this stupid questions, but I am really new in this whole gis-thing.. Where kann I see that the vector layer is not empty? If I use the same projection for both layers, they don´t overlap. But for the clipping I transformed them into the same projection.
    – Lisa E.
    Commented Apr 3, 2013 at 23:20
  • Okay i checked the layers again. My shapefile has one object, so it´s not empty. Right? I think the problem is the projection. I used EPSG: 3857 as the project CSR. The shapefile is projected in EPSG: 4326. I tried to use the same CSR for the raster, but then they didn´t overlap. So I used EPSG: 3857 for the raster. I think that´s the problem. But what can I do that both layers overlap AND I can clip them?
    – Lisa E.
    Commented Apr 4, 2013 at 8:08
  • I tried to edit the shapelayer again. Both layers now have the same projection (EPSG 3857), but the error still appears. Is it the problem with the empty shapefile, after all?
    – Lisa E.
    Commented Apr 4, 2013 at 10:36
  • One last question to be sure that everything is ok: are you able to load both the layers in QGIS, with the same projection for both (EPSG 3857) and see them overlapping (you must be able to see the polygon over the raster). Can you share these files somewhere? If you can do it, I could try to clip the raster and see if I get the same error message.
    – diegogb
    Commented Apr 4, 2013 at 10:58
  • Yes, now both layers are in QGIS with the projection EPSG 3857 and the polygon is over the raster. I need to clip it, because the polygon is the outline of a city and the raster sould have the same design. Thank you for your offer, but I am not allowed to share the data :( do you think something is wrong with the polygon?
    – Lisa E.
    Commented Apr 4, 2013 at 11:32

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.