• Blog posts

    Bio

    by David Crowther

    QGIS_Mask_Raster_DC_01.png

    Question:

    Is it possible to set a Mask around Raster Tiles in QGIS?

    Answer:

    Masks are commonly used to allow the end user to better interpret the map being shown to them. For example, using an inverted polygon boundary you can mask all layers that fall outside your area of interest – so that users only see the information that is important to them!

    QGIS_Mask_Raster_DC_02.jpg

    See this Cadline Community blog for more details:

    https://www.cadlinecommunity.co.uk/hc/en-us/articles/360004789857-QGIS-Creating-Masks

    The same idea can be applied with Raster tiles, where you could simply use the same vector inverted polygon to mask the raster layer that falls outside of the polygon – this could be useful for printing purposes.

    However – you can also clip the Raster layer using the mask polygon to create a new tile that only includes the raster tile within the clip polygon area. Below we have one Raster tile – TQ0057 and a Mask Polygon called – SchoolPolygon.

    QGIS_Mask_Raster_DC_03.jpg

    You can choose to clip the raster tile using the map extents, or by using a Mask Layer, such as the SchoolPolygon.

    We will choose the second option, so from the menu Raster > Extraction > choose > Clip Raster by Mask Layer…

    QGIS_Mask_Raster_DC_04.jpg

    Choose the input raster tile and the mask polygon layer, and set the Source CRS as needed – e.g. 27700.

    QGIS_Mask_Raster_DC_05.jpg

    Then choose to output the result to a new File, saving the tile with a new name and choosing the image type e.g. .tif

    QGIS_Mask_Raster_DC_06.jpg

    Once ran it creates a new raster tile, showing only the area that falls inside the mask polygon. However the area around the edges of the tile, that fell outside of the Mask polygon are coloured as black pixels.

    QGIS_Mask_Raster_DC_07.jpg

    This time, when you run the routine, tick the option to Create an output alpha band, in addition to the pre-ticked option to match the extent of the clipped raster to the extent of the mask layer.

    QGIS_Mask_Raster_DC_08.jpg

    Once you run this again, the output clipped raster tile, will have the areas outside the mask polygon changed to white, which now shows the clipped Raster tile as we would need it.

    QGIS_Mask_Raster_DC_09.jpg

    If you tick to show the clip Mask layer – SchoolPolygon – we can now see that our image was correctly clipped using the Mask layer.

    QGIS_Mask_Raster_DC_10.jpg