Advertisement
Guest User

1:n string attribute concatenation

a guest
May 28th, 2014
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from qgis.utils import iface
  2. layer = iface.activeLayer()
  3. layer.startEditing()
  4. compare_field_index = 15
  5. concat_field_index = 5
  6. new_field_index = 10
  7. feature_dict = {f.id(): f for f in layer.getFeatures()}
  8. for f in feature_dict.values():
  9.   if f[concat_field_index]:
  10.     new_field_text = f[concat_field_index]
  11.   else:
  12.     new_field_text = ''
  13.   # Another for loop to go over features
  14.   for compare_f in feature_dict.values():
  15.     if (f != compare_f
  16.         and f[compare_field_index] == compare_f[compare_field_index]):
  17.       print '%s matches' % f[compare_field_index]
  18.       if compare_f[concat_field_index]:
  19.         new_field_text += compare_f[concat_field_index]
  20.   print new_field_text
  21.   f[new_field_index] = new_field_text
  22. layer.commitChanges()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement