-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMultiLayerSelection.py
executable file
·44 lines (36 loc) · 1.21 KB
/
MultiLayerSelection.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
'''
Created on 12/10/2014
@author: ferrari
'''
from qgis.core import QgsRectangle, QgsMapLayer
from qgis.gui import QgsMapTool
class MultiLayerSelection(QgsMapTool):
def __init__(self, canvas, action):
self.canvas = canvas
self.active = False
QgsMapTool.__init__(self, self.canvas)
self.setAction(action)
def canvasPressEvent(self, e):
p = self.toMapCoordinates(e.pos())
layers = self.canvas.layers()
w = self.canvas.mapUnitsPerPixel() * 3
rect = QgsRectangle(p.x()-w, p.y()-w, p.x()+w, p.y()+w)
for layer in layers:
if layer.type() == QgsMapLayer.RasterLayer:
continue
lRect = self.canvas.mapSettings().mapToLayerCoordinates(layer, rect)
layer.selectByRect(lRect, layer.SelectBehavior.SetSelection)
def deactivate(self):
try:
if self is not None:
QgsMapTool.deactivate(self)
except:
pass
def activate(self):
QgsMapTool.activate(self)
try:
self.selectionButton.setDefaultAction(self.sender())
except:
pass
def unload(self):
self.deactivate()