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.

1
  • What GIS software are you using?
    – PolyGeo
    Commented May 22, 2023 at 20:12

1 Answer 1

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.

4
  • Do you know where can i learn more about this?
    – Cortod
    Commented May 23, 2023 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
    Commented May 23, 2023 at 11:30
  • Documentation for QGIS expressions: docs.qgis.org/latest/en/docs/user_manual/expressions/… array_to_string() should work in newer QGIS versions.
    – Babel
    Commented May 23, 2023 at 12:39
  • Please, could you see my other question? gis.stackexchange.com/questions/460202/…
    – Cortod
    Commented May 23, 2023 at 17:06

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.