4

I am trying to use the 'intersects' function within an 'if' condition. If a polygon in Layer A intersects a polygon in layer B, then the cell should display 'YES', otherwise 'No'.

However, I don't know how to properly call the Layer B in the field calculator. The expression I am working on looks like this :

if(intersects( $geometry,geometry('LayerB') ),"YES","NO")

Does anyone know how to put it correctly?

2
  • 1
    For one thing, the intersects command will return a true/false response without the if statement, so you can drop that part. More importantly, though, the intersects command requires that you have a specific geometry to test against. If you just want to check if it intersects ANY polygon in the second layer, you're going to need to do something a little more involved. Suggestion: use the Select by location tool to specify cross-layer intersections, then just create the new field and update selected features only.
    – jcarlson
    Commented Jun 12, 2018 at 15:03
  • I thought about 'Select By Location', but I wanted to use the graphical modeler and didn't know if it would work. Thank you !
    – Andare
    Commented Jun 12, 2018 at 15:22

2 Answers 2

4

The correct syntax for your expression is

    IF (aggregate(layer:='Layer B', aggregate:= 'count', expression:= $id, 
       filter:=intersects($geometry, geometry(@parent))), 
       concat ('yes'), concat('no'))

This is the result: enter image description here

2

Using refFunctions :

if( intersecting_geom_count('LayerB') > 0, 'YES', 'NO' )

(Sorry it is not QGIS3.0 specific, not using intersects function...)

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.