I'm trying to extract a section of a raster file that overlaps with a polygon shapefile in QGIS 2.18.3. When I run extract, I'm left with a large null value area as part of the extent of the output raster.

I have the polygon (.shp):
vector mask

And the raster (.tif) which had this large null value area since the first time I clipped one of two DEMs that were merged together to create this layer:

I used Raster -> Extraction -> Clipper tool with the .tif input and .shp mask layer shown above, and it produced this output:

Using clipping option "Crop the extent of the target dataset to the extent of the cutline" didn't do much better:
clipped to extent ws dem

Here are the settings I'm using in QGIS' clipping tool:
clipping config

How do I get the DEM clipped exactly to the boundaries of the shapefile of interest in QGIS? Open to recommendations of other open source GIS tools as well but would prefer using this since I'm already up and running and learning my way around it.

1 Answer 1


The raster is clipped exactly to the shapefile boundaries.

But remember, a raster is a kind of matrix. It's composed by n rows and m columns, so the extent of it is rectangular.

The black area are pixels without values, so you only have valid pixels in the extent of the shapefile.

If you want to hide null pixels, check this answer How to display NoData of a raster in QGIS.

What have you done is clip out some values. The result is the desired but the meaning is different:

What have you done:

enter image description here

In this case, NULL pixels are defined by a value equals to 255. You can clip out those pixels setting a max of 254 and clipping out the remains values:

enter image description here

Sure work, even you can set two boundaries to remove some values of the render (min and max). But QGIS has a dedicated section to remove NULL or No Data values. Gives you more control about how to handle these values:

enter image description here

  • 1
    Aha! That linked question is the opposite of what I wanted to do but led me to the answer: on the raster layer in question, go to properties, style, load min/max values, then check "clip extent to canvas". I applied that and got a raster with the extent only displaying as the vector's boundary.
    – cr0
    Jul 31, 2017 at 1:29
  • I think your answer is pretty complete if you add that last part. You could take my text and add it, then I'll check yours off. Thanks
    – cr0
    Jul 31, 2017 at 1:29
  • @cr0 ok, I updated my answer
    – aldo_tapia
    Jul 31, 2017 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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