-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPlugin.py
More file actions
84 lines (73 loc) · 3.04 KB
/
Plugin.py
File metadata and controls
84 lines (73 loc) · 3.04 KB
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
# ***************************************************************************
# Point Sampling Tool
#
# A QGIS plugin for collecting polygon attributes and raster values
# from multiple layers at specified sampling points
#
# Copyright (C) 2008 Borys Jurgiel
# based on Carson Farmer's PointsInPoly plugin, Copyright (C) 2008 Carson Farmer
#
# ***************************************************************************
# * *
# * 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 os
from builtins import object
from qgis.PyQt.QtCore import (
QCoreApplication,
QLocale,
QSettings,
QTranslator,
)
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from .PointSamplingToolDialog import PointSamplingToolDialog
from . import resources # noqa: F401
class Plugin(object):
def __init__(self, iface):
self.iface = iface
if QSettings().value("locale/overrideFlag", type=bool):
locale = QSettings().value("locale/userLocale")
else:
locale = QLocale.system().name()
locale_path = os.path.join(
os.path.dirname(__file__),
"i18n",
"pointSamplingTool_{}.qm".format(locale[0:2]),
)
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
# create action
self.action = QAction(
QIcon(":/plugins/pointSamplingTool/pointSamplingToolIcon.png"),
QCoreApplication.translate("Point Sampling Tool", "Point Sampling Tool"),
self.iface.mainWindow(),
)
self.action.setWhatsThis(
QCoreApplication.translate(
"Point Sampling Tool",
"Collects polygon attributes and raster values from multiple layers at specified sampling points",
)
)
self.action.triggered.connect(self.run)
# add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(
QCoreApplication.translate("Point Sampling Tool", "&Analyses"), self.action
)
def unload(self):
# remove the plugin menu item and icon
self.iface.removePluginMenu(
QCoreApplication.translate("Point Sampling Tool", "&Analyses"), self.action
)
self.iface.removeToolBarIcon(self.action)
def run(self):
# create and show a configuration dialog or something similar
PointSamplingToolDialog(self.iface).exec()