2

I have this attribute table:

enter image description here

I want to run a script for labelling:

label=''  
parametros=array("Alumínio","Antimônio")

for i in range(len(parametros)): label=prof[i] if ID_sprof[i]==ID_sprof[i-1]: label+=prof[i-1]

This is a try of labeling the Profs of the next attribute together with the previous one. for example, considering that SO-31 has 3 Prof, I wanted one labelling like:

0,6 1,6 3,0

This is a resume of what I'm trying. I know this doesn't work in an expression. But this can be done by making some changes and defining a function in the expression editor.

This is just an example how I could access the information of another atribute to put in the other, but I know it doesn't work.

Vince
  • 20,017
  • 15
  • 45
  • 64
Cortod
  • 21
  • 3

1 Answers1

3

For QGIS, use this expression:

array_to_string(array_agg(Prof, group_by:=ID_sprof))

You can add an optional argument between the second last and the last closing bracket ) to define (a) delimiter character(s) like this: delimiter:=' ' - what is inside the single quotes ' (here: a space enter code here) will be used as a delimiter. Use \n to insert a linebreak and get a separate row for each value.

Taras
  • 32,823
  • 4
  • 66
  • 137
Babel
  • 71,072
  • 14
  • 78
  • 208
  • Do you know where can i learn more about this? – Cortod May 23 '23 at 11:23
  • I'm trying to use that inside a function, when i run the function it goes well. But in the "expression" it acuses 'array_to_string' is not defined. Is it a native expression in qgis? When i just put the expression directly in the "expression" it works – Cortod May 23 '23 at 11:30
  • Documentation for QGIS expressions: https://docs.qgis.org/latest/en/docs/user_manual/expressions/functions_list.html array_to_string() should work in newer QGIS versions. – Babel May 23 '23 at 12:39
  • Please, could you see my other question?

    https://gis.stackexchange.com/questions/460202/functions-in-the-expression-tab-used-in-function-editor?noredirect=1#comment751565_460202

    – Cortod May 23 '23 at 17:06