Skip to content

Instantly share code, notes, and snippets.

@pigreco
Last active November 2, 2019 11:33
Show Gist options
  • Save pigreco/4b10950c673dbfacc719c2acb06ea840 to your computer and use it in GitHub Desktop.
Save pigreco/4b10950c673dbfacc719c2acb06ea840 to your computer and use it in GitHub Desktop.

Tabella di esempio:

fid l cum cum_2 cum_3
1 0 0 0 0
2 10 10 10 10
3 20 30 30 30
4 30 60 60 60
5 40 100 100 100
6 50 150 150 150
  • usando la funzione attribute (risultato colonna cum)
if(
$id = 1, attribute($currentfeature, 'l'),
attribute($currentfeature, 'l') +
attribute(get_feature_by_id(@layer_name, $id-1), 'cum'))
  • usando le funzioni di aggregazione (risultato colonna cum2)
if(
$id = 1, array_agg( "l")[0],
eval(
replace(
array_to_string(
array_slice( array_agg( "l"),0,$id-1)), ',','+'))
)
  • usando il plugin ArrayPlus e la funzione array_sum (risultato colonna cum3)

NB: nel core di QGIS manca la funzione array_sum e tante altre sugli array

if(
$id = 1, array_agg( "l")[0],
array_sum( array_slice( array_agg( "l"),0,$id-1))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment