2

I have two feature classes: point and line. The purpose is to make geometrical relations between them. For instance, if points are on line then they automatically take attributes from a specific field from line layer (field-double).

But if i'm not giving any attribute it returns NULL (but it should aggregate from layer). What is wrong with expression?

if(NULL,
    aggregate(
        layer:='layer_you_want',
        aggregate:='concatenate',
        expression:=to_string("field_you_want"),
        concatenator:=', ',
        filter:=intersects($geometry, buffer(geometry(@parent), 0.0005))
        ),
    "remain_the_same_field"
    )
6
  • Can't work because condition in if-clause is NULL, but you don't tell what is NULL. Then again, it's unclear what you want to achieve... can you add a screenshot? If a point is on a line, you want to aggregate... what? Aggregate is to bring together attributes from different features, so each point would get values from several lines. This is unclear to me.
    – Babel
    Commented Sep 27, 2022 at 13:27
  • in my case, it is valve(point) and waterpipe(polyline). when I put valve on waterpipe I need it to take diameter from waterpipe if I'm not giving another value for valve diameter. if(NULL,aggregate( layer:= 'waterpipe', aggregate:='concatenate', expression:=to_string("diameter"), concatenator:=', ', filter:= intersects($geometry,buffer( geometry(@parent),0.0005) )), "diameter_valve") I wrote the code in layer properties- valve diameter feature-default value Commented Sep 28, 2022 at 5:15
  • You didn't answer the questions. Without making clear what you want to achieve, you won't geht a meaningful answer. Why Aggregate? You just want to geht the diamer of the Piper, right? You want one value, not several Differenz values per point? How should the result look like?
    – Babel
    Commented Sep 28, 2022 at 5:48
  • It's not necessary to use aggregate, it just works for me in another case. Yes, I want to get the diameter of the pipe if I don't give another value instead. Yes, I want one value for one point. the result should look in point feature - or my entered diameter, or aggregated diameter from line(if I don't give another value), or NULL(if it missing in both cases). Commented Sep 28, 2022 at 6:26
  • "if I don't give another value": and where does this "other value" come from...? Is it an attribute of the point layer?
    – Babel
    Commented Sep 28, 2022 at 6:48

3 Answers 3

3

Use the following expression on the point layer and adapt it to your needs. It checks whether the point layer's attribute named value is 0:

  • If not, the current value of value will be returned.
  • if value = 0, the expression returns the value of the attribute called name of the line layer waterpipe - but only if the point is on the line (you should set a very small tolerance for the distance from the line, here 0.01). If points are not on the line, NULL will be returned
if (
    "value"=0,  -- set a condition
    overlay_nearest(
        'waterpipe',  -- name of the line layer
        name,  -- name of the attribute of the point layer
        max_distance:=0.01  -- small tolerance distance
    )[0],
    value
)

Red label is generated by the expression: enter image description here

1

This one also worked:

if("diameter_valve" is NULL,
    aggregate(
        layer:='waterpipe_pipe',
        aggregate:='concatenate',
        expression:=to_string("diameter"),
        concatenator:=', ',
        filter:=intersects($geometry, buffer(geometry(@parent), 0.0005))
        ),
    "diameter_valve"
    )
0

This expression worked for me:

if("diameter_valve" is NULL,
    overlay_nearest('waterpipe', diameter_pipe, max_distance:=0.01)[0],
    "diameter_valve"
    )

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.