I am trying to create a rule-based style based on geometries from another layer.

I have found an example that does exactly what I want, except that it uses a geometry from WKT:

intersects( $geometry, geomFromWKT( 'POLYGON' ) )

(from here)

What I want to do is exactly the same thing, but with the second geometry based on a different layer rather than WKT. As an example, I want to theme roads in black if they intersect a polygon layer, and grey if they do not. Is this possible?

  • What is the different layer type?
    – artwork21
    Commented Jun 6, 2014 at 14:52
  • The second layer is a polygon shapefile that has been added to the QGIS project. Commented Jun 6, 2014 at 14:55
  • I would like to know if the subject above "Is it possible to create Rule-Based Styling with $geometry intersecting a second layer? " is now possible in the new version of Qgis. thanks. Commented Nov 23, 2016 at 18:04

3 Answers 3


In QGIS 2.18 there is a plugin available called refFunctions and when using the query builder, they show up in the Reference portion. query/rule builder in qgis with refFunction geomintersects example

So this should work as a rule: geomintersects('polygon_layer','ogc_fid')

And possibly in conjunction with the geomdisjoint() function: symbology example with refFunctions plugin

The field column in the above example just uses the ogc_fid primary key/id column but can be any column... Says it also accepts the $geometry variable but I haven't got that to work yet!


Unfortunately, it is currently not possible to create cross-layer queries using field calculator or expressions.

See also How to use the Intersects function in the Field Calculator of QGIS?

  • Thanks underdark; at least I wasn't missing something! I figured perhaps it was not possible. Commented Jun 13, 2014 at 15:30

Yes, it is possible. In the 'rule based' symbology, choose the rule to be:

intersects($geometry, geometry(get_feature('layer name', 'attribute field name', 'value')))

Let's say you want your layer to intersect with geometry A (called 'A' in the field 'Name') in a second layer, called 'Other geometries'.

Then you would use:

intersects($geometry, geometry(get_feature('Other geometries', 'Name', 'A')))

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.