[GIS] Filtering out labels surrounding active feature in Atlas

atlaslabelingpolygonqgisshapefile

Let me put it this way, if I’ve tried data-defined rendering and the common featureid expression and it’s still not working – and I think one or both options should – what basic thing could I be doing wrong?

I am using QGIS version 3.4 to create atlas maps utilizing a polygon coverage layer of 19 watersheds. Everything works fine in layout as I can jump/zoom to each desired watershed map. Furthermore, to filter out features surrounding the active watershed, I've applied symbology with inverted polygons and rule-based sub-renderer with the expression $id = @atlas_featureid. This successfully removes outlying features, but not their labels. The labels are from both polygon and point shapefiles.Atlas watershed map with surrounding labels

I've tried seemingly everything – different types of symbology, various other expressions (which I, admittedly, don't fully understand), old versions of QGIS, a new project using only two shapefiles (using counties to filter out surrounding cities) – but nothing gets rid of the outlying labels. I've got to believe it's something simple I'm doing wrong. What could that be?

BTW, I’ve tried using the mask plugin, but with the same result.

Best Answer

To hide the labels outside the atlas geometry boundary, you need to do the following:

  • Right-click the layers that their labels are shown outside the atlas geometry boundary
  • Go to Layer properties for each layer -> Labels -> Rendering -> Show Labels

enter image description here

  • Select Data Defined override -> Edit..., and write the following formula:

    intersects( $geometry , @atlas_geometry )
    
  • The above formula will show the labels only within the atlas geometry.

  • Repeat the same formula for other layers to hide the labels outside the atlas geometry boundary.

Without using the formula:

enter image description here

With using the above formula:

enter image description here

Related Question