I have two layers: 1 polygon layer where the depth of an area is written in the database (as DRVAL1) and and where the depth is exported as a Z-value to the geometry. 1 point layer that I use to plan Aids-to-Navigation. two test opjects.

In the screenshot to test objects are placed in the point layer. I want to write the depth from the polygonlayer (that is displayed under the pointlayer) that is true for the position of the point, to the poinlayer.

I've tried to make a virtual field in the pointlayer with:

 (WHEN intersects($geometry,geometry(get_features('layer_id',"DRVAL1", 
 '50')))) = true THEN '50'

I've repeated the WHEN->THEN for all the values in the polygonlager. but I get a reply with (can't convert to double) or (can't find DRVAL1)

what do I need to change or are there better ways to tackle this issue?

2 Answers 2


If you install the RefFunctions plugin as @Joseph suggests, there's no need to use conditional statements. Instead, use the geomintersects() function to get the 'DRVAL' value of the polygon that the point intersects, like this:

geomintersects( 'polygonlayer', 'DRVAL1')

Note: Your expression uses a function called get_features() (plural). That function doesn't exist, but there's a function get_feature() (singular). It "returns the first feature of a layer matching a given attribute value." So if your polygon layer has more than one feature with 'DRVAL1' = 50, intersects($geometry,geometry(get_feature('layer_id',"DRVAL1", '50'))) will return false if the current point intersects a different polygon than whichever one QGIS decides is the first. This limitation of the built-in geometry functions is exactly why the RefFunctions plugin exists.

  • I wasn't aware of the limitation you described in get_feature, neither of the existence of RefFunctions, many thanks. Still getting a NULL reply if i use this method. Will try harder. Apr 4, 2019 at 19:09
  • A few suggestions: Make sure you substituted the correct layer and field names into the expression (check your spelling and look for leading or ending whitespace). Double-check that the "polygon layer" is actually polygons, not lines. Try geomwithin() instead of geomintersects().
    – csk
    Apr 4, 2019 at 19:15
  • I tried both but somewhere i’m going wrong. I know the spelling is right cause if it isn’t i get an error. I tried dissolving and then singleparts to multiparts. Both no succes, i just get a read-out (NULL). Is it possible both layers need to have the same CRS? Apr 7, 2019 at 20:05
  • yes. always use the same crs for geometry operations (union, intersect, etc).
    – csk
    Apr 8, 2019 at 14:00
  • problem solved, works flawless, thnx! Apr 8, 2019 at 18:24

I find it easier to install the refFunctions plugin as this contains a set of geospatial expressions which can be called from the field calculator. You could then use something like:

WHEN geomintersects( 'polygonlayer', 'DRVAL1') = '50'
THEN '50'

where polygonlayer is the name of your polygon layer.

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.