Created
April 21, 2017 14:18
-
-
Save slarosa/bc3fa13ce5555693ac81311a66c4dbdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
QGIS Action to select and zoom the feature from related table | |
when one of field pairs is string. Using LIKE in QgsExpression. | |
Ref: https://lists.osgeo.org/pipermail/qgis-it-user/2017-April/002413.html | |
''' | |
from qgis.utils import iface | |
# inserire qui il nome del layer geometrico | |
vl = QgsMapLayerRegistry.instance().mapLayersByName('punti')[0] | |
iface.setActiveLayer(vl) | |
cLayer = iface.mapCanvas().currentLayer() | |
# qui sotto i nomi dei due campi da correlare | |
expr = QgsExpression("id_punto LIKE '[% "punto" %]%'") | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment