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 clip my Raster file according to a shape file geometry. I am using the following code

gdalwarp -cutline INPUT.shp INPUT.tif OUTPUT.tif

But it is resulting a black color outside the shape file geometry extent. I am giving the example here. In the first Image that I want to clip. The second image is the resultant raster but I want the 3rd Raster where the outside of the geometry will be null.

1st Image: INPUT Raster

1st Image: INPUT Raster

2nd Image: OUTPUT Raster

2nd Image: OUTPUT Raster

enter image description here

3rd Image: I want to get output like this

share|improve this question

3 Answers 3

up vote 5 down vote accepted

You need to use the -dstalpha option to gdalwarp e.g.:

gdalwarp -cutline INPUT.shp -crop_to_cutline -dstalpha INPUT.tif OUTPUT.tif

This will add an alpha band to the output tiff which masks out the area falling outside the cutline.

A late answer, but hopefully it will help someone else with the same problem.

share|improve this answer
    
without the -srcnodata <in> -dstnodata <out> hint by Curlew it did not work for me. –  Jens Jun 4 at 19:33

Try to specify the nodata-value from your input raster and set it for the output as well. Furthermore add the option -crop_to_cutline to make exact crops. More about the options here.

gdalwarp -srcnodata <in> -dstnodata <out> -crop_to_cutline -cutline INPUT.shp INPUT.tif OUTPUT.tif
share|improve this answer
    
Can You elaborate little bit more? What is used as <in> and <out> ? –  Devils Dream Jan 2 '13 at 19:02
    
<in> is your input rasters nodata-value and <out> for your output-raster. Please have a look at the provided link where you can find all information and options (output format, source, extent, ... ) –  Curlew Jan 2 '13 at 23:15

You can use raster clip option in QGIS which runs gdalwarp in the background and configures the right options for you.

http://qgistips.spatialthoughts.com/2012/11/clip-raster-in-irregular-shape-using.html

share|improve this answer
    
I want a ***.tif format –  Devils Dream Jan 2 '13 at 19:18
    
The steps outlined in the link above should give you a .tif output. –  spatialthoughts Jan 2 '13 at 20:01

protected by Aaron 1 hour ago

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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