1

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:

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

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?

1

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. – CaptainAhab Apr 4 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 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? – CaptainAhab Apr 7 at 20:05
  • yes. always use the same crs for geometry operations (union, intersect, etc). – csk Apr 8 at 14:00
  • problem solved, works flawless, thnx! – CaptainAhab Apr 8 at 18:24
0

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:

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

where polygonlayer is the name of your polygon layer.

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.