forked from sdteffen/qgis-elevation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.py
65 lines (54 loc) · 2.22 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
"""
***************************************************************************
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 pointToWGS84(point):
p = QgsProject.instance()
(proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String")
if not ok:
return point
t=QgsCoordinateReferenceSystem()
t.createFromEpsg(4326)
f=QgsCoordinateReferenceSystem()
f.createFromProj4(proj4string)
transformer = QgsCoordinateTransform(f,t)
pt = transformer.transform(point)
return pt
def pointFromWGS84(point):
p = QgsProject.instance()
(proj4string,ok) = p.readEntry("SpatialRefSys","ProjectCRSProj4String")
if not ok:
return point
f=QgsCoordinateReferenceSystem()
f.createFromEpsg(4326)
t=QgsCoordinateReferenceSystem()
t.createFromProj4(proj4string)
transformer = QgsCoordinateTransform(f,t)
pt = transformer.transform(point)
return pt