Skip to content

Instantly share code, notes, and snippets.

@jecogeo
Created June 28, 2021 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jecogeo/be3002cd603d2a5472a20f4be28b528d to your computer and use it in GitHub Desktop.
Save jecogeo/be3002cd603d2a5472a20f4be28b528d to your computer and use it in GitHub Desktop.
selecionar features cuja soma da tabela de atributos ordenada é >=x
# pega o layer
layer = qgis.utils.iface.activeLayer()
# acessa a tabela de atributos
features = layer.getFeatures()
# ordena a tabela ded atributos
# aqui um teste
for feat in features:
print(sorted(feat["producao"]))
# valor que será o limiar de seleção
x = 2000
# seleciona todas as features cuja soma ordenada pelo campo producao" é <=2000
@kylefelipe
Copy link

Segue

field_name = 'producao'
def field_to_order(f):
    """Essa funcao retorna o valor do campo a ser ordenado"""
    return f[field_name]

features = sorted(layer.getFeatures(), key=field_to_order)

for feat in features:
    print(feature[field_name]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment