-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
77 lines (63 loc) · 2.38 KB
/
utils.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
***************************************************************************
Name : Geocoding
Description : Geocoding and reverse Geocoding using Google
Date : 28/May/09
copyright : (C) 2009 by ItOpen
email : info@itopen.it
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from qgis.core import *
from qgis.gui import *
class ClickTool(QgsMapTool):
def __init__(self, iface, callback):
QgsMapTool.__init__(self, iface.mapCanvas())
self.iface = iface
self.callback = callback
self.canvas = iface.mapCanvas()
return None
def canvasReleaseEvent(self, e):
point = self.canvas.getCoordinateTransform().toMapPoint(
e.pos().x(), e.pos().y()
)
self.callback(point)
return None
def get_dest_projection():
"""
Returns project projection
"""
"""
p = QgsProject.instance()
(proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String")
if not ok :
return None
crs = QgsCoordinateReferenceSystem()
crs.createFromProj4(proj4string)
"""
# TODO: CHANGE
crs = QgsCoordinateReferenceSystem()
# crs.createFromProj4('+proj=utm +zone=28 +datum=WGS84 +units=m +no_defs')
crs.createFromSrid(32628)
return crs
def pointToWGS84(point):
t = QgsCoordinateReferenceSystem()
t.createFromSrid(4326)
transformer = QgsCoordinateTransform(get_dest_projection(), t)
pt = transformer.transform(point)
return pt
def pointFromWGS84(point):
f = QgsCoordinateReferenceSystem()
f.createFromSrid(4326)
transformer = QgsCoordinateTransform(f, get_dest_projection())
pt = transformer.transform(point)
return pt
if __name__ == "__main__":
pass