/
demtools.py
118 lines (93 loc) · 4.44 KB
/
demtools.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
"""
/***************************************************************************
DemTools
A QGIS plugin
A suite of tools for doing neat things with DEMs
-------------------
begin : 2014-05-15
copyright : (C) 2014 by Kris Hammerberg
email : kris.hammerberg@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. *
* *
***************************************************************************/
"""
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
# Initialize Qt resources from file resources.py
import resources_rc
# Import the code for the dialog
import os.path
import sys
from shaDEM import shaDEM
from svf import svf
from solaraccess import SolarAccess
class DemTools:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# save reference to tool interfaces
self.shaDEM = shaDEM(iface)
self.svf = svf(iface)
self.SolarAccess = SolarAccess(iface)
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'demtools_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
#check necessary libraries
try:
import numpy
import numexpr
except ImportError:
QMessageBox.critical( self.iface.mainWindow(),"ImportError", "Plugin requires Numpy & Numexpr libraries.\n\See http://www.numpy.org & https://code.google.com/p/numexpr/" )
try:
import Pysolar as solar
except ImportError:
try:
import solar
except ImportError:
QMessageBox.critical( self.iface.mainWindow(),"ImportError", "Plugin requires Pysolar libraries.\n\See http://pysolar.org/" )
def initGui(self):
# Create action that will start plugin configuration
self.shaDEMact = QAction(
QIcon(":/plugins/demtools/shaDEM.png"),
u"ShaDEM", self.iface.mainWindow())
self.SVFact = QAction(
QIcon(":/plugins/demtools/SVF.png"),
u"SVF", self.iface.mainWindow())
self.solaract = QAction(
QIcon(":/plugins/demtools/solaraccess.png"),
u"SolarAccess", self.iface.mainWindow())
# connect the actions to the run methods
self.shaDEMact.triggered.connect(self.shaDEM.start)
self.SVFact.triggered.connect(self.svf.start)
self.solaract.triggered.connect(self.SolarAccess.start)
# Add toolbar buttons and menu items
self.iface.addToolBarIcon(self.shaDEMact)
self.iface.addPluginToRasterMenu(u"&DEM Tools", self.shaDEMact)
self.iface.addToolBarIcon(self.SVFact)
self.iface.addPluginToRasterMenu(u"&DEM Tools", self.SVFact)
self.iface.addToolBarIcon(self.solaract)
self.iface.addPluginToRasterMenu(u"&DEM Tools", self.solaract)
def unload(self):
# Remove the plugin menu items and icons
self.iface.removePluginRasterMenu(u"&DEM Tools", self.shaDEMact)
self.iface.removeToolBarIcon(self.shaDEMact)
self.iface.removePluginRasterMenu(u"&DEM Tools", self.SVFact)
self.iface.removeToolBarIcon(self.SVFact)
self.iface.removePluginRasterMenu(u"&DEM Tools", self.solaract)
self.iface.removeToolBarIcon(self.solaract)