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 Jun 6 '14 at 14:52
  • The second layer is a polygon shapefile that has been added to the QGIS project. – Darren Cope Jun 6 '14 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. – Denilson de Jesus Nov 23 '16 at 18:04

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. – Darren Cope Jun 13 '14 at 15:30

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!

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.