Suppose that you are adding another feature and suppose that you want to automatically fill all the fields with some values. These values should be copied from an existing feature on the map by selecting it on the map.

Example: you want to copy all the values from the red feature (labeled with road) to the new one (bottom right corner). The new feature table should have type = road, subtype = one-way, width = 5.

I cannot use the Default Value of the Attributes Form because there is not fixed rule.

enter image description here

The button that I'm looking for is already available in the Attribute Form when you change to Widget Type to Relation Reference, but you need to have a Relation set up with 2 layers (so not this case).

  • So, you want to copy the attribute from another feature? The question was not clear to me. Jun 4, 2020 at 23:45
  • @AlexandreNeto I edited the question with an hopefully more clear explanation.
    – matteo
    Jun 5, 2020 at 6:26
  • 1
    My best bet would be a action on the form. Jun 5, 2020 at 8:41
  • mmm nice idea. Do yo suggest to do something smooth or go with a python snippet? Have you a template to share?
    – matteo
    Jun 5, 2020 at 12:10
  • Probably needs python. No not really. That would just be my first try, but I have no idea if it would work Jun 5, 2020 at 12:59

2 Answers 2


Contrary to what you stated in your question, the Default Value should be adequate to accomplish what you want, if we also make use of a Virtual Field.

I have a sample dataset of lines, with the fields type and other_field, both of which are labeled for reference.

sample lines

  1. Open the Field Calculator and create a new virtual field. This is important, because we need the field to be able to recalculate on the fly, not be a static value.
  2. Name the field "is-selected", or whatever you want, and make sure it is a boolean type.
  3. In the expression editor, enter is_selected() and click OK.
  4. Open the attribute table. Notice that they are probably all set to false, but if you select some rows and refresh the table, they will change.

new field with is_selected set to false

new field with selected rows showing true

  1. Open Properties for the layer, and go to the Attributes Form tab.
  2. With type selected, scroll down to the Default Value section and open the expression editor.
  3. Enter the following expression: attribute(get_feature([your_map_layer], 'is-selected', 'true'), 'type')
  4. Repeat the same process for any other fields you'd like to copy from the selected feature to the new feature.
  5. You'll be warned that using fields in a default value only work if apply default value on update is checked. Go ahead and check the box. There are simple ways of avoiding accidental attribute updates if you're editing existing features, but I will let you address that on your own, as it is somewhat beyond the scope of this question.
  6. Go ahead and test it out! In my sample dataset, I have both type and other_field grabbing their value from the selected feature. With the top line, which is type 2, other_field C, selected:

new feature with default attributes

You may notice a warning that the "check failed" for is_selected, but in my test, the form successfully pulled in the selected feature's attribute every time.

Happy mapping!

  • Nice solution, thanks! I still think that a button (or an action like @AlexandreNeto suggested) would be more user friendly. Anyway, thanks ;)
    – matteo
    Jun 6, 2020 at 8:06

There is the "Merge Feature Attributes" tool in the advanced digitizing toolbar.

You select two (or more) feature, choose one of the selected feature, click on the "Take attribute from selected feature" button then on OK, it will copy the attribute from the selected (in the tool dialog) feature to the other selected (in the first selection step in canvas) feature.

enter image description here

  • yep but this is an operation (together with Merge Selected Features) that I have to do after I've created the feature. What I'm looking for is an immediate way to do that.
    – matteo
    Jun 5, 2020 at 12:09

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.