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 need to clip a rasterlayer 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? I would be very glad, if somebody could help me.

Thank you, Lisa

share|improve this question
    
Sorry! QGIS. I tried to use the same projektion for both layers but it didn´t work –  Lisa E. Apr 3 '13 at 22:12
    
what is your raster resolution? what are the dimensions of your vector layer? –  A.R Apr 5 '13 at 15:57

1 Answer 1

up vote 1 down vote accepted

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.

Bye,

Diego

share|improve this answer
    
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. Apr 3 '13 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. Apr 4 '13 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. Apr 4 '13 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 Apr 4 '13 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. Apr 4 '13 at 11:32

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.