2

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.

3

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

  • 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 Mar 25 at 13:58
  • @brvee I am currently not in front of my computer, but try to test different methods instead of intersects. – ahmadhanb Mar 25 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 Mar 25 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 Mar 26 at 0:51
  • Yeah, that’s basically where I started. I was just trying to avoid doing that with the many layers I am using - repeatedly turning them off and on. Thanks for all your help! – brvee Mar 26 at 11:52
1

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.

  • Thanks, but I already tried $id = @atlas_featureid and it didn't work, at least in hiding outside labels. – brvee Mar 25 at 14:39
  • If you use it to only draw the feature you want labeled it will – Ian Turton Mar 25 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 Mar 25 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.