I need to generate an atlas based on a polygon shapefile, but I'd like to see just what is inside the polygon itself. Maybe with rules that involves other shape's attributes. Any suggestion?
You can do as described below. But I strongly recommend to do this only on small(er) datasets, as this will need a lot of calculation. If you want to do this with a bigger dataset, I suggest to first
join attributes by location, so you don't need to perform an intersection by expression for every single feature and perform the rule based selection based on the joined attributes.
Create a rule based symbology for your polygon layer using this expression:
@atlas_featureid = $id
Now create a rule based symbology on your other layers. Use
within() for point layers and
intersects() for line and polygon layers:
intersects( geometry( get_feature_by_id( 'polygonlayername', @atlas_featureid)),$geometry)
When you now preview your atlas only features are displayed that fall within or intersect with the current atlas polygon feature.
Addition to show surrounding features:
You can also build a buffer around your polygon. Just use this expression for it:
intersects( buffer( geometry( get_feature_by_id( 'polygon', @atlas_featureid)),100),$geometry)
100 is the buffer size in meters. Be aware you will need a projected CRS (like UTM) to use this properly. The result:
If your polygons are square or rectangular, you can size the map extent to suit and select 0% as the margin around the feature.
If you polygons are some other shape (possibly irregular), I would make a new layer that is supersized to cover all your Atlas polygons. Then find the difference between the two layers (which will give you a copy of the supersized polygon but with holes in it where your Atlas polygons are. Add this at the top of your layers and colour it either opaque white or semi transparent (to fade out the surrounding area but still let people see the wider context of the map).
I've used this method both with Atlas and with other maps where I want to focus attention on a specific area.