-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector_selectbypoint.py
105 lines (85 loc) · 4.14 KB
/
vector_selectbypoint.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
vector_selectbypoint
A QGIS plugin
Select vector features, point and click.
-------------------
begin : 2014-04-07
copyright : (C) 2014 by Brylie Oxley
email : brylie@geolibre.org
***************************************************************************/
/***************************************************************************
* *
* 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 *
from qgis.gui import *
# Initialize Qt resources from file resources.py
import resources_rc
# Import the code for the dialog
from vector_selectbypointdialog import vector_selectbypointDialog
import os.path
class vector_selectbypoint:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# Reference map canvas
self.canvas = self.iface.mapCanvas()
# Emit QgsPoint after each click on canvas
self.clickTool = QgsMapToolEmitPoint(self.canvas)
# 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', 'vector_selectbypoint_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.dlg = vector_selectbypointDialog()
# Create the GUI
self.canvas.setMapTool( self.clickTool )
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(
QIcon(":/plugins/vector_selectbypoint/icon.png"),
u"Select by point and click.", 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(u"&Select vector features by point and click.", self.action)
# Signal connections for mouse clicks
result = QObject.connect(self.clickTool, SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"), self.handleMouseDown)
#QMessageBox.information( self.iface.mainWindow(), "Info", "connect = %s" %str(result) )
def handleMouseDown(self, point, button):
#QMessageBox.information( self.iface.mainWindow(), "Info", "X,Y = %s, %s" % (str(point.x()), str(point.y())) )
self.dlg.clearTextBrowser()
self.dlg.setTextBrowser( str(point.x()) + " , " + str(point.y()) )
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(u"&Select vector features by point and click.", self.action)
self.iface.removeToolBarIcon(self.action)
# run method that performs all the real work
def run(self):
# Activate click tool
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code)
pass