Skip to content

Instantly share code, notes, and snippets.

@aborruso
Last active April 14, 2017 09:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aborruso/70f499780f7ac636d78f47abfb4c9747 to your computer and use it in GitHub Desktop.
Save aborruso/70f499780f7ac636d78f47abfb4c9747 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 )
# zoom alla selezione
box = cLayer.boundingBoxOfSelected()
iface.mapCanvas().setExtent(box)
iface.mapCanvas().refresh()
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