I recently did a rasterize in QGIS with our city map (which I clipped from the whole country map before) to produce the first map. Now I need to do the connectivity analysis in another software so I did a rasterize and produced the second map with the "extra extent."

My question is how to remove the extra extent (the black area)? I have tried the clip seems doesn't work here. Are there any steps I did wrong cause this?The city mapraster

  • 2
    Typically you would assign all the black area pixels the same value (e.g. 0, -9999, etc.) and then assign the raster with a 'No Data' value equal to to value you chose for the black pixels. The 'No Data' tag will tell most other software to render the image so that the black area is now transparent. Commented Dec 17, 2018 at 23:50
  • 1
    What parameters did you use for GDAL_Rasterize? gdal.org/gdal_rasterize.html There is a parameter -a_nodata value to specify a value outside your range (-9999 or -29999 is good for 32 bit float, 65535 works too for 32bit Integer) to make NoData as Charlie says, GIS software should ignore NoData areas when processing. Commented Dec 17, 2018 at 23:59
  • An image (i.e. a raster) is a rectangular regular grid by definition. If your shape containing pixels of interest is not aligned with the grid, the "extra" pixels as you called them must be assigned to a "No Data" value as stated above. Check your program manual to see which value is understood as "No Data" for a raster file. Commented Dec 18, 2018 at 6:34

2 Answers 2


The raster will be always a rectangle. Hence, the black pixels are always present there. As in the comments above, usually all pixels of this black area have one value which is considered "no data". If QGis (transparency settings in 2.18) knows which value it is, it renders this area transparent so that it seems like the black area is not present but it is still there.


If you perform "Clip Raster by Mask Layer" the result will have always no-data values for all the areas outside the mask layer, i.e. the process does not reduce the extent of the input raster.


Input Data for Clip Raster by Mask Layer


Output Raster of Clip Raster by Mask Layer

Note: In the previous raster, there are complete rows with no-data on top of the image.

If you want to remove the extra no-data cells, you can additionally perform a "Clip Raster by Extent", using the extent coordinates of the mask layer


Output Raster of Clip Raster by Mask Layer


Output Raster of Clip Raster by Extent

Note: The last one raster does not have extra no-data cells (complete lines or columns!) outside the area of interest. You can use the Transparency - No Data Value to change the black color (to transparent) in the raster (generally cell values equal to 0)

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.