[GIS] Extracting raster by mask outputs raster with extent beyond the mask layer’s in QGIS

extentsextract-by-maskqgis

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:
merged_dem

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

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.

Best Answer

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