4

I have two layers that share a Unique "ID" field. Can I easily update the field values in one layer with the field values in the other layer using the Unique "ID" as the link field? As the layers also sit on top of each other I suppose I could alternatively use the 'equals' operator in 'Join Attributes by location' but I thought using a fixed field value would be more reliable. One way seems to be to join the two layers and then to perform a field update but I thought it might be possible in one step with the right function.

I am aware that I can join the layers, but I need to get the data into the original layer itself so they can be handled separately.

1
  • 1
    The correct answer to your current question would be "yes, this is possible". I suggest you a) do some more research, since this issue was dealt with rather often, and b) show your efforts/attempts and where you're stuck.
    – Erik
    Commented Apr 20, 2021 at 12:49

1 Answer 1

5

You can use QGIS expressions with field calculator to create a new field or updating an existing one. Use the function get_feature() to identify the feature on the other layer with the same id and the attribute () function to get the value of any attribute from this other layer.

In my case, a have a polygon layer named polygon with an attibute named value and a point layer named point. Both share the same id. The copy the value attribute from the polygon to the point layer, I use this expression (replace polygon, id and value with the names of your layer and attributes):

attribute( 
    get_feature( 
        'polygon', 
        'id', 
        "id"
    ),
    'value'
)

enter image description here

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.