-
Notifications
You must be signed in to change notification settings - Fork 5
/
generalizer.py
68 lines (60 loc) · 2.69 KB
/
generalizer.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
"""
/***************************************************************************
generalizer
A QGIS plugin
Lines generalization (smooth and simplify) based on v.generalize GRASS module
-------------------
begin : 2011-08-17
copyright : (C) 2011 by Piotr Pociask
email : ppociask (at) o2 pl
***************************************************************************/
/***************************************************************************
* *
* 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
# Import the code for the dialog
from generalizerdialog import generalizerDialog, getLayersNames
class generalizer:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/generalizer/icon.png"), \
"Generalizer", self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect( self.run )
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Generalizer", self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&Generalizer",self.action)
self.iface.removeToolBarIcon(self.action)
# run method that performs all the real work
def run(self):
#check if there are loaded line layers
if len(getLayersNames()) == 0:
QMessageBox.critical(None, 'Generalizer', 'Load line layer!')
return
# create and show the dialog
dlg = generalizerDialog(self.iface)
# show the dialog
dlg.show()
result = dlg.exec_()
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code
pass