By David Crowther
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?
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!
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'
Once we apply the filter, the County Layer will be updated to only show the County of Northamptonshire polygon.
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.
If you Apply this change, notice that Northamptonshire is not styled but all other polygons are styled.
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.
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.
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!