• Blog posts

    Bio

    By David Crowther

    QGIS___Creating_Masks_-_1.JPG

    Question:

    I would like to add a Mask to my QGIS map to hide all the features outside of a specific boundary, how is this best achieved?

    Answer:

    This can be achieved in QGIS by using the Invert Polygon styling option.

    For example, below we have a map of the UK with Counties, Schools, Hospitals and ARoads. At the moment the map is a little messy!

    QGIS___Creating_Masks_-_2.JPG

    We have decided that we only want to show/print the map elements that are within the County of Northamptonshire.

    The first step is to only show the Counties where the Name is Northamptonshire and the easiest way to do this is to update the Properties of the County Layer to provide a definition query where the name is ‘Northampton’.

    In the Layer Properties choose the Source Tab and press Query Builder. In the Query Builder we can define the filter using the following syntax:

    "FILE_NAME" = 'NORTHAMPTONSHIRE_COUNTY'

    QGIS___Creating_Masks_-_3.jpg

    Once we apply the filter, the County Layer will be updated to only show the County of Northamptonshire polygon.

    QGIS___Creating_Masks_-_4.JPG

    Finally we need to edit the STYLE of the County Layer to apply an Inverted Polygon.

    In the Layer Properties choose the Symbology Tab and change the option from Single Symbol to be Inverted polygons.

    QGIS___Creating_Masks_-_5.JPG

    If you Apply this change, notice that Northamptonshire is not styled but all other polygons are styled.

    QGIS___Creating_Masks_-_6.JPG

    Choose to Edit the Style options again for the Layer and set the FILL COLOUR to be White. If we apply the change we can see that the other Counties are White and Northamptonshire is not styled – so it is see through. However we can still see the Point and Line Layers which are above the Counties.

    QGIS___Creating_Masks_-_7.JPG

    We have one last change to make…….. in order to MASK the map features that fall outside of Northamptonshire, we simply need to re-order the Layers so that the County Layer sits above all other layers. Use the Layers Panel and move the Counties Layer to the top of the Layer list.

    QGIS___Creating_Masks_-_8.JPG

    Once this change is made, the County Layer now acts as a MASK over the map with the Inverted Polygon providing a gap for the County of Northamptonshire!

    QGIS___Creating_Masks_-_9.JPG

    QGIS___Creating_Masks_-_10.JPG