Skip to content

Instantly share code, notes, and snippets.

@fpsampayo
Last active December 26, 2017 16:16
Show Gist options
  • Save fpsampayo/fdaf705add359e90f835d0c6cd777d4e to your computer and use it in GitHub Desktop.
Save fpsampayo/fdaf705add359e90f835d0c6cd777d4e to your computer and use it in GitHub Desktop.
Seleccionando en pyqgis por agregación
layer = iface.mapCanvas().currentLayer()

expr1 = """count("refcat", "refcat") > 1"""

exp = QgsExpression(expr1) 

exp_context = QgsExpressionContext()
exp_context.appendScope(QgsExpressionContextUtils.globalScope())
exp_context.appendScope(QgsExpressionContextUtils.projectScope())
exp_context.appendScope(QgsExpressionContextUtils.layerScope(layer))

qfr = QgsFeatureRequest(exp, exp_context)
it = layer.getFeatures(qfr)
ids = [i.id() for i in it]

layer.setSelectedFeatures(ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment