1

I have two layers, one being a manhole layer and the other a gravity main layer. I need to get the asset number from the manhole layer into the gravity main layer. On the gravity main layer I have a field "From_Manho" which contains an ID, that same ID exists on the manhole layer under the name "Facility_I". In my head, I'm thinking I can make an expression using the ID fields to extract the associated asset number. I came across this question but I wasn't able to get it to work.

This was my attempt at the expression:

attribute(
    get_feature(
        'ssManhole_642cc259_988d_404e_9458_9e5dc4f7b7b6', 
        Facility_I,  
        "From_Manho"
    ), 
    'Asset'
) 
2

1 Answer 1

1

I agree with the comments that this is a natural use case for an table join. That said, you can implement it using a field calculator expression. The overall structure of the OP code looks good, it looks like quotes are missing for the Facility_I field name in get_feature() function:

attribute(
  get_feature(
    'ssManhole_642cc259_988d_404e_9458_9e5dc4f7b7b6',
    'Facility_I',
    "From_Manho"
  ),
  'Asset'
)

The OP code can also be rewritten to explicitly retrieve the manhole instead of relying on implicit retrieval using double quotes:

attribute(
  get_feature(
    'ssManhole_642cc259_988d_404e_9458_9e5dc4f7b7b6',
    'Facility_I',
    attribute(
       'From_Manho'
    )
  ),
  'Asset'
)

5
  • Hello thanks for the help but it still didn't work. I was trying to avoid using table join as i was hoping to make it a default value. it's looking like table join is going to be the way to go.
    – Mow
    Apr 3 at 21:38
  • @Mow, what exactly isn't working? Any specific error(s)? I tested it on some mocked up data, and the general approach worked. Are both layers loaded into the same project? Is the manhole table really named with that GUID-like suffix?
    – bixb0012
    Apr 3 at 22:00
  • There are no errors it just doesn't return any results. Yes it is named with that GUID-like suffix. I went to the map layers tab in the expression builder and selected the manholes layer.
    – Mow
    Apr 3 at 22:45
  • I am using QGIS 3.28.2. I updated my answer to add a code sample that removes implicit attribute retrieval and replaces it with a call to attribute function. Also, the comparison between the field in the two tables will have to be identical, so could there be a capitalization or empty space issue (assuming comparing strings)?
    – bixb0012
    Apr 5 at 14:06
  • Is the field you are calculating the right type? If you accidentally created an Integer field but are trying to populate it with Strings then you will get null values.
    – Matt
    Apr 5 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.