3

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.

1
  • Was glad to find I wasn't the only one struggling with this, so thanks for posting. The within($geometry, @atlas_geometry )=1 suggestion below worked for me.
    – Mike D
    Commented Mar 25, 2020 at 14:39

4 Answers 4

8

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

7
  • Thanks for the response. I just tried your suggestion on my rivers layer and, unfortunately, that masks ALL of the labels for that layer - both inside and outside the Atlas' current feature.
    – brvee
    Commented Mar 25, 2019 at 13:58
  • @brvee I am currently not in front of my computer, but try to test different methods instead of intersects.
    – ahmadhanb
    Commented Mar 25, 2019 at 14:04
  • Well I've tried a variety of geometry functions other than intersect - intersection, within, contains, difference, geometry_n, overlaps, touches - and none get the desired result. I'm at a loss.
    – brvee
    Commented Mar 25, 2019 at 23:13
  • @brvee Then the only solution you have is to intersect the river layer with the watershed boundary using Vector -> Geoprocessing tools -> Intersection and use the output intersected river instead of the original river. Then use the expression in the answer. I am sure it will work this time.
    – ahmadhanb
    Commented Mar 26, 2019 at 0:51
  • 2
    Just out of curiosity are your river and watershed boundaries in different CRSes? That may be why they aren't intersecting in the expression builder.
    – she_weeds
    Commented Mar 27, 2019 at 6:27
4

To hide the labels outside feature - change to 'rule based labelling' and insert within($geometry, @atlas_geometry )=1 as filter

1
  • Thanks for posting this! The first suggestion didn't work for me, but this one did.
    – Mike D
    Commented Mar 25, 2020 at 14:39
3

The simplest fix is to use the expression $id = @atlas_featureid to only draw the feature you are interested in, rather than "hiding" the other features using a rendering rule. This is why the labels are still applied.

3
  • Thanks, but I already tried $id = @atlas_featureid and it didn't work, at least in hiding outside labels.
    – brvee
    Commented Mar 25, 2019 at 14:39
  • If you use it to only draw the feature you want labeled it will
    – Ian Turton
    Commented Mar 25, 2019 at 14:52
  • In the layers with the outside labels I'm wanting to hide, I added this expression as a new rule under rule-based labeling. It didn't work. I also tried adding this ruler under symbology, just in case. That didn't work either.
    – brvee
    Commented Mar 25, 2019 at 21:47
0

I also had troubles getting the solution to work (no labels were shown). I solved it by running Fix geometries in QGIS.

After that, I used intersects($geometry, @atlas_geometry )=1. Using $id = @atlas_featureid did not work for me.

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.