2

I am trying to filter features in one layer outside features in another layer using geometry generator.

I have a buildings layer and an area layer and now I want to only show the buildings outside the areas.

The buildings layer is a polygon layer and the area layer is also a polygon layer consisting of several areas (features).

Since it is a many feature area layer I think I need to use an aggregate function e.g. collect() and/or aggregate() from the QGIS expression builder.

I trying the following expression on the geometry generator on the buildings layer...

difference( 
    $geometry, collect(geometry
                            (get_feature('layer_id','attribute','value')
                                )
                            )
                       )

...which ends up in an syntax error message.

1 Answer 1

3

Try something like this:

if(disjoint($geometry,aggregate('area','collect',$geometry)) = 1,$geometry,NULL)

Explanation:

  • aggregate('area','collect',$geometry) creates one single MultiPolygon out of your area layer
  • disjoint($geometry,MultiPolygonFromAreaLayer) then checks if the current building is outside the MultiPolygon or inside. It will return 1 if its outside and 0 if its inside. If disjoint() does not meet your criteria, you can use intersects(), within(), contains(), etc instead.
  • The if() statement then evaluates wheter the current geometry should be displayed ($geometry) or not (NULL). Depending on your usecase you can vary this.

enter image description here

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.