-
Notifications
You must be signed in to change notification settings - Fork 2
/
mapcanvaseffects.py
55 lines (47 loc) · 2.17 KB
/
mapcanvaseffects.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
53
54
55
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Map Canvas Effects
Description : Tools for show the geometry of feature
Date : January, 2019
copyright : (C) 2019 by Luiz Motta
email : motta.luiz@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
__author__ = 'Luiz Motta'
__date__ = '2019-01-31'
__copyright__ = '(C) 2019, Luiz Motta'
__revision__ = '$Format:%H$'
from qgis import utils as QgsUtils
from qgis.core import QgsProject, QgsCoordinateTransform
class MapCanvasGeometry():
def __init__(self):
self.project = QgsProject().instance()
self.canvas = QgsUtils.iface.mapCanvas()
def flash(self, geometries, layer=None):
if layer is None:
self.canvas.flashGeometries( geometries )
else:
self.canvas.flashGeometries( geometries, layer.crs() )
def zoom(self, geometries, layer=None):
bbox = geometries[0].boundingBox()
for geom in geometries[1:]:
bbox.combineExtentWith( geom.boundingBox() )
if not layer is None:
crsLayer = layer.crs()
crsCanvas = self.project.crs()
if not crsLayer == crsCanvas:
ct = QgsCoordinateTransform( layer.crs(), self.project.crs(), self.project )
bbox = ct.transform( bbox )
self.canvas.setExtent( bbox )
self.canvas.zoomByFactor( 1.05 )
self.canvas.refresh()
self.flash( geometries, layer )