2

In a newly digitised polyline vector layer, there are 7 columns attributes value that are choosen inside a value map combo-box that MUST be exactly the same for every newly digitised line (I choose the values for the first digitised line then all the other newly digitised lines must have the same value of the first one).

I'd like to fill them (in a kind of automatic, or auto completed way) with the exact same values of the first digitised row.

I was thinking about some unique values properties, but since the values are kept inside a combobox I can't use both field properties together. OR to complete the missing values with some field calculator expression at the end of the digiting.

EDIT: I'm using QGIS 2.8 and 2.10 running in both Windows and Ubuntu I post a screenshot of the value map used for 7 different columns, all real(4,3)

enter image description here

The attribute table is the following one and all the "empty" () columns should have the same value appearing in the first row

enter image description here

Like this enter image description here

  • see if now it s clear to you – Mattia Aug 24 '15 at 9:04
  • I tried to answer, but the more often I read the question, the more confused I am. – Bernd V. Aug 24 '15 at 11:11
  • edited again, hope that now my qestion is understandable – Mattia Aug 24 '15 at 12:28
3

Although you're asking for an answer related to value map combo-boxes, I thought to provide an alternative where you could use the following code to read the values in the first row for each column and copy it for each of the attributes. Select the layer in QGIS and copy/paste the code into the Python Console (Plugins -> Python Console or Ctrl + Alt + P):

layer = qgis.utils.iface.activeLayer()
layer.startEditing()
for field in layer.pendingFields():
    name = field.name()
    request = QgsFeatureRequest().setFilterFid(0)
    feat = layer.getFeatures(request).next()
    result = feat[name]
    for feature in layer.getFeatures():
        feature[name] = result
        layer.updateFeature(feature)

This is not automated, which is what you seem to be asking for. But I hope it helps a little anyway! Tested this on QGIS 2.8.2-Wien.


Update:

If you want to run the above script in the graphical modeler, first select the Create new script tool from Processing Toolbox -> Scripts. Note you said 7 columns but gave 8 :). Then insert the following:

##Copy attributes from first row=name
##Layer=vector

import qgis
from qgis.core import *

layer = processing.getObject(input)
layer.startEditing()
for field in layer.pendingFields():
        name = field.name()
        request = QgsFeatureRequest().setFilterFid(0)
        feat = layer.getFeatures(request).next()
        result = feat[name]
        for feature in layer.getFeatures():
                if name == 'ALT_0':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_1':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_2':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_3':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_4':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_5':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_Ideale':
                        feature[name] = result
                        layer.updateFeature(feature)
                if name == 'ALT_propos':
                        feature[name] = result
                        layer.updateFeature(feature)

Also note that I purposely did not save the changes just incase there's a mistake. If you want the script to save the changes, use the layer.commitChanges() code at the end of the script outside all the for loops.

I tested this and it seems to work so hopefully it will for you too =)

  • Thank You! It's kind of what I was looking for, the only thing that I have to improve to your script is the fact that I need to update the values of only 7 columns (ALT_0, ALT_1, ALT_2, ALT_3, ALT_4, ALT_5, ALT_Ideale and ALT_propos) and not all the attributes of the layer. Can you help me to modify the script in order to do this? – Mattia Aug 24 '15 at 14:32
  • And I have to put this script inside the graphical modeler, is there anything else I have to modify? – Mattia Aug 24 '15 at 14:38
  • @Mattia - I edited my post, hopefully it will work for you :) – Joseph Aug 24 '15 at 14:59
  • 1
    Works like a charm! thank you so much Joseph! I'll give a try inside the modeler in the next days. – Mattia Aug 24 '15 at 15:16
  • 1
    @Mattia - I will see what I can do as the code I added does need some cleaning up :) – Joseph Aug 25 '15 at 9:21

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.