I would like to have an example on how to use the Intersects function in the Field Calculator of QGIS.

Basically, I want to know which feature from a polylines layer intersects a polygons layer and store the result in an attribute. (0 = not intersecting, 1 = Intersecting).

I'm aware of the geoprocessing tools "Clip" or "Intersect", but is it possible in the Field calculator ?


This is not possible in field calculator. The intersect function in the field calculator does not work with two layers. What you can do is calculate intersections with specific geometries, e.g.

intersects( $geometry, geomFromWKT( 'LINESTRING(765145.88 6274561.22, 776031.67 6284189.52)' ) )

For more on these spatial operators check http://docs.qgis.org/latest/en/docs/user_manual/working_with_vector/expression.html#geometry-functions

Instead, use the Spatial query plugin to first select all features that intersect the polygon layer. Then use field calculator and only update selected features to set the intersection attribute to 1.

  • Dead link unfortunately... really looking for more documentation on how these operators work... – DPSSpatial_BoycottingGISSE Nov 3 '17 at 15:05
  • @DPSSpatial Field calculator has built-in documentation. What are you missing? I've also added the relevant user manual link – underdark Nov 3 '17 at 17:47
  • Thanks, Anita. I've never seen this, and likely because I don't use the field calculator, always looking in the expression, rules, atlas settings, etc... when you access these as Variables, they're hard to figure out what they expect in terms of inputs and outputs... I'll go through that doc, so thanks for that! – DPSSpatial_BoycottingGISSE Nov 3 '17 at 19:16

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.