Skip to content

Instantly share code, notes, and snippets.

@pigreco
Forked from aborruso/README.md
Created April 14, 2017 07:47
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 pigreco/3cc6d6bee07deb12afdff2839d808e0c to your computer and use it in GitHub Desktop.
Save pigreco/3cc6d6bee07deb12afdff2839d808e0c to your computer and use it in GitHub Desktop.
QGIS: selezionare geometrie da una tabella correlata, via una action in Python. Un GIST a servizio di questo post https://medium.com/tantotanto/qgis-selezionare-geometrie-da-una-tabella-di-attributi-correlata-bea37747a7e2

Qui sotto un video che mostra come usare un action Python, per selezionare una geometria a partire da una tabella con valori correlati al layer con le geometrie. Il campo di join è id.

Sotto trovate pure:

  • la action in Python;
  • il file con le geometrie;
  • il file con la tabella con i dati correlati.

from qgis.utils import iface
# inserire qui il nome del layer geometrico
vl = QgsMapLayerRegistry.instance().mapLayersByName('layerGeometrico OGRGeoJSON Point')[0]
iface.setActiveLayer(vl)
cLayer = iface.mapCanvas().currentLayer()
#inserire qui il campo su cui fare la query per selezionare la feature del layer geometrico
expr = QgsExpression("\"id\"=[% "id" %]")
it = cLayer.getFeatures( QgsFeatureRequest( expr ) )
ids = [i.id() for i in it]
cLayer.setSelectedFeatures( ids )
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
id particella
1 253a
2 253b
3 254a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment