-
Notifications
You must be signed in to change notification settings - Fork 6
/
feature_selection_tool.py
52 lines (38 loc) · 1.2 KB
/
feature_selection_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""Modulo per la selezione di una feature.
Descrizione
-----------
Librerie/Moduli
-----------------
Note
-----
Autore
-------
- Creato da Sandro Moretti il 09/02/2022.
Dedagroup spa.
Membri
-------
"""
from qgis.gui import QgsMapToolIdentifyFeature
from qgis.PyQt.QtCore import pyqtSignal
#
#-----------------------------------------------------------
class FeatureSelectionTool(QgsMapToolIdentifyFeature):
# signal
featuresIdentified = pyqtSignal(object, list)
def __init__(self, canvas):
self.canvas = canvas
QgsMapToolIdentifyFeature.__init__(self, self.canvas)
def keyPressEvent( self, e ):
pass # disable escape key event to prevent loosing maptool
def canvasReleaseEvent(self, mouseEvent):
results = self.identify(
mouseEvent.x(), mouseEvent.y(), self.TopDownStopAtFirst, [], self.VectorLayer)
if len(results) > 0:
res = results[0]
features = []
layer = res.mLayer
for res in results:
if res.mLayer == layer:
features.append(res.mFeature.id())
self.featuresIdentified.emit(layer, features)