forked from minorua/Qgis2threejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgis2threejsdialog.py
563 lines (476 loc) · 21.3 KB
/
qgis2threejsdialog.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Qgis2threejsDialog
A QGIS plugin
export terrain and map image into web browser
-------------------
begin : 2013-12-21
copyright : (C) 2013 by Minoru Akagi
email : [email protected]
RectangleMapTool class is from extentSelector.py of GdalTools plugin
copyright : (C) 2010 by Giuseppe Sucameli
***************************************************************************/
/***************************************************************************
* *
* 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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import QgsMessageBar, QgsMapToolEmitPoint, QgsRubberBand
from ui_qgis2threejsdialog import Ui_Qgis2threejsDialog
from qgis2threejsmain import *
import qgis2threejstools as tools
from quadtree import *
from vectorobject import *
from vectorstylewidgets import *
debug_mode = 1
class Qgis2threejsDialog(QDialog):
STYLE_MAX_COUNT = 3
def __init__(self, iface):
QDialog.__init__(self, iface.mainWindow())
self.iface = iface
self.apiChanged22 = False # not QgsApplication.prefixPath().startswith("C:/OSGeo4W") # QGis.QGIS_VERSION_INT >= 20200
# Set up the user interface from Designer.
self.ui = ui = Ui_Qgis2threejsDialog()
ui.setupUi(self)
self.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint)
ui.lineEdit_OutputFilename.setPlaceholderText("[Temporary file]")
ui.pushButton_Run.clicked.connect(self.run)
ui.pushButton_Close.clicked.connect(self.reject)
# DEM tab
ui.toolButton_switchFocusMode.setVisible(False)
ui.toolButton_PointTool.setVisible(False)
ui.progressBar.setVisible(False)
self.switchFocusMode(True)
ui.checkBox_useDEM.toggled.connect(self.useDemToggled)
ui.toolButton_Browse.clicked.connect(self.browseClicked)
ui.radioButton_Simple.toggled.connect(self.samplingModeChanged)
ui.horizontalSlider_Resolution.valueChanged.connect(self.calculateResolution)
ui.spinBox_Height.valueChanged.connect(self.updateQuads)
ui.toolButton_switchFocusMode.clicked.connect(self.switchFocusModeClicked)
ui.toolButton_PointTool.clicked.connect(self.startPointSelection)
# Vector tab
ui.treeWidget_VectorLayers.setHeaderLabel("Vector layers")
self.initVectorStyleWidgets()
ui.treeWidget_VectorLayers.currentItemChanged.connect(self.currentVectorLayerChanged)
ui.treeWidget_VectorLayers.itemChanged.connect(self.vectorLayerItemChanged)
ui.comboBox_ObjectType.currentIndexChanged.connect(self.objectTypeSelectionChanged)
self.bar = None
self.localBrowsingMode = True
self.rb_quads = self.rb_point = None
self.currentVectorLayer = None
self.vectorPropertiesDict = {}
self.objectTypeManager = ObjectTypeManager()
# set map tool
self.previousMapTool = None
self.mapTool = RectangleMapTool(iface.mapCanvas())
self.connect(self.mapTool, SIGNAL("rectangleCreated()"), self.rectangleSelected)
# self.mapTool = PointMapTool(iface.mapCanvas())
# QObject.connect(self.mapTool, SIGNAL("pointSelected()"), self.pointSelected)
iface.mapCanvas().mapToolSet.connect(self.mapToolSet)
self.startPointSelection()
def exec_(self):
ui = self.ui
messages = []
# show message if crs unit is degrees
mapSettings = self.iface.mapCanvas().mapSettings() if self.apiChanged22 else self.iface.mapCanvas().mapRenderer()
if mapSettings.destinationCrs().mapUnits() in [QGis.Degrees]:
self.showMessageBar("The unit of current CRS is degrees", "Terrain may not appear well.")
# show message if there are no dem layer
no_demlayer = ui.comboBox_DEMLayer.count() == 0
if no_demlayer:
ui.checkBox_useDEM.setEnabled(False)
ui.checkBox_useDEM.setChecked(False)
return QDialog.exec_(self)
def showMessageBar(self, title, text, level=QgsMessageBar.INFO):
if self.bar is None:
self.bar = QgsMessageBar()
self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
ui = self.ui
margins = ui.gridLayout.getContentsMargins()
vl = ui.gridLayout.takeAt(0)
ui.gridLayout.setContentsMargins(0,0,0,0)
ui.gridLayout.addWidget(self.bar, 0, 0)
ui.gridLayout.addItem(vl, 1, 0)
ui.verticalLayout.setContentsMargins(margins[0], margins[1] / 2, margins[2], margins[3])
self.bar.pushMessage(title, text, level=level)
def initDEMLayerList(self, layerId=None):
# list 1 band raster layers
self.ui.comboBox_DEMLayer.clear()
for id, layer in QgsMapLayerRegistry().instance().mapLayers().items():
if layer.type() == QgsMapLayer.RasterLayer and layer.providerType() == "gdal" and layer.bandCount() == 1:
self.ui.comboBox_DEMLayer.addItem(layer.name(), id)
# select the last selected layer
if layerId is not None:
index = self.ui.comboBox_DEMLayer.findData(layerId)
if index != -1:
self.ui.comboBox_DEMLayer.setCurrentIndex(index)
return index
return -1
def initVectorLayerTree(self, vectorPropertiesDict):
self.vectorPropertiesDict = vectorPropertiesDict
tree = self.ui.treeWidget_VectorLayers
tree.clear()
# add vector layers into tree widget
self.treeTopItems = topItems = {QGis.Point:QTreeWidgetItem(tree, ["Point"]), QGis.Line:QTreeWidgetItem(tree, ["Line"]), QGis.Polygon:QTreeWidgetItem(tree, ["Polygon"])}
self.vlItems = {}
for layer in self.iface.legendInterface().layers():
if layer.type() != QgsMapLayer.VectorLayer:
continue
geometry_type = layer.geometryType()
if geometry_type in [QGis.Point, QGis.Line, QGis.Polygon]:
self.vlItems[layer.id()] = item = QTreeWidgetItem(topItems[geometry_type], [layer.name()])
if layer.id() in self.vectorPropertiesDict:
isVisible = self.vectorPropertiesDict[layer.id()]["visible"]
else:
isVisible = False #self.iface.legendInterface().isLayerVisible(layer)
check_state = Qt.Checked if isVisible else Qt.Unchecked
item.setData(0, Qt.CheckStateRole, check_state)
item.setData(0, Qt.UserRole, layer.id())
#item.setDisabled(True)
#item.setData(0, Qt.CheckStateRole, Qt.Unchecked)
for item in topItems.values():
tree.expandItem(item)
self.setVectorStylesEnabled(False)
def initVectorStyleWidgets(self):
self.colorWidget = StyleWidget(StyleWidget.COLOR)
self.ui.verticalLayout_Styles.addWidget(self.colorWidget)
self.heightWidget = StyleWidget(StyleWidget.HEIGHT)
self.ui.verticalLayout_zCoordinate.addWidget(self.heightWidget)
self.styleWidgets = []
for i in range(self.STYLE_MAX_COUNT):
widget = StyleWidget()
widget.setVisible(False)
self.ui.verticalLayout_Styles.addWidget(widget)
self.styleWidgets.append(widget)
def currentVectorLayerChanged(self, currentItem, previousItem):
# save properties of previous item
if previousItem is not None:
layerid = previousItem.data(0, Qt.UserRole)
if layerid is not None:
self.saveVectorProperties(layerid)
layerid = currentItem.data(0, Qt.UserRole)
if layerid is None:
self.currentVectorLayer = None
return
self.currentVectorLayer = layer = QgsMapLayerRegistry().instance().mapLayer(layerid)
if layer is None:
return
for i in range(self.STYLE_MAX_COUNT):
self.styleWidgets[i].hide()
obj_types = self.objectTypeManager.objectTypeNames(layer.geometryType())
ui = self.ui
ui.comboBox_ObjectType.blockSignals(True)
ui.comboBox_ObjectType.clear()
ui.comboBox_ObjectType.addItems(obj_types)
ui.comboBox_ObjectType.blockSignals(False)
# set up property widgets
self.objectTypeSelectionChanged()
if layerid in self.vectorPropertiesDict:
# restore properties
self.restoreVectorProperties(layerid)
self.setVectorStylesEnabled(currentItem.data(0, Qt.CheckStateRole) == Qt.Checked)
def vectorLayerItemChanged(self, item, column):
# update style form enablement
currentItem = self.ui.treeWidget_VectorLayers.currentItem()
if currentItem:
self.setVectorStylesEnabled(currentItem.data(0, Qt.CheckStateRole) == Qt.Checked)
def objectTypeSelectionChanged(self, idx=None):
layer = self.currentVectorLayer
try:
ve = float(ui.lineEdit_zFactor.text())
except:
ve = 1
mapTo3d = MapTo3D(self.iface.mapCanvas(), verticalExaggeration=ve)
self.objectTypeManager.setupForm(self, mapTo3d, layer, layer.geometryType(), self.ui.comboBox_ObjectType.currentIndex())
def numericFields(self, layer):
# get attributes of a sample feature and create numeric field name list
numeric_fields = []
f = QgsFeature()
layer.getFeatures().nextFeature(f)
for field in f.fields():
isNumeric = False
try:
float(f.attribute(field.name()))
isNumeric = True
except:
pass
if isNumeric:
numeric_fields.append(field.name())
return numeric_fields
def setVectorStylesEnabled(self, enabled):
self.ui.comboBox_ObjectType.setEnabled(enabled)
self.ui.label_ObjectType.setEnabled(enabled)
self.colorWidget.setEnabled(enabled)
self.heightWidget.setEnabled(enabled)
for i in range(self.STYLE_MAX_COUNT):
self.styleWidgets[i].setEnabled(enabled)
def saveVectorProperties(self, layerid):
properties = {}
layer = QgsMapLayerRegistry().instance().mapLayer(layerid)
itemIndex = self.ui.comboBox_ObjectType.currentIndex()
properties["itemindex"] = itemIndex
properties["typeitem"] = self.objectTypeManager.objectTypeItem(layer.geometryType(), itemIndex)
properties["visible"] = self.vlItems[self.currentVectorLayer.id()].data(0, Qt.CheckStateRole) == Qt.Checked
properties["color"] = self.colorWidget.values()
properties["height"] = self.heightWidget.values()
for i in range(self.STYLE_MAX_COUNT):
if self.styleWidgets[i].isVisible():
properties[i] = self.styleWidgets[i].values()
self.vectorPropertiesDict[layerid] = properties
def restoreVectorProperties(self, layerid):
properties = self.vectorPropertiesDict[layerid]
self.ui.comboBox_ObjectType.setCurrentIndex(properties["itemindex"])
self.colorWidget.setValues(properties["color"])
self.heightWidget.setValues(properties["height"])
for i in range(self.STYLE_MAX_COUNT):
if i in properties:
self.styleWidgets[i].setValues(properties[i])
def calculateResolution(self, v=None):
extent = self.iface.mapCanvas().extent()
renderer = self.iface.mapCanvas().mapRenderer()
size = 100 * self.ui.horizontalSlider_Resolution.value()
self.ui.label_Resolution.setText("about {0} x {0} px".format(size))
# calculate resolution and size
width, height = renderer.width(), renderer.height()
s = (size * size / float(width * height)) ** 0.5
if s < 1:
width = int(width * s)
height = int(height * s)
xres = extent.width() / width
yres = extent.height() / height
self.ui.lineEdit_HRes.setText(str(xres))
self.ui.lineEdit_VRes.setText(str(yres))
self.ui.lineEdit_Width.setText(str(width + 1))
self.ui.lineEdit_Height.setText(str(height + 1))
def progress(self, percentage):
self.ui.progressBar.setValue(percentage)
self.ui.progressBar.setVisible(percentage != 100)
def run(self):
ui = self.ui
filename = ui.lineEdit_OutputFilename.text() # ""=Temporary file
if filename != "" and QFileInfo(filename).exists() and QMessageBox.question(None, "Qgis2threejs", "Output file already exists. Overwrite it?", QMessageBox.Ok | QMessageBox.Cancel) != QMessageBox.Ok:
return
self.endPointSelection()
item = ui.treeWidget_VectorLayers.currentItem()
if item:
self.saveVectorProperties(item.data(0, Qt.UserRole))
ui.pushButton_Run.setEnabled(False)
self.progress(0)
canvas = self.iface.mapCanvas()
htmlfilename = ui.lineEdit_OutputFilename.text()
if ui.checkBox_useDEM.isChecked():
demlayerid = ui.comboBox_DEMLayer.itemData(ui.comboBox_DEMLayer.currentIndex())
else:
demlayerid = None
mapTo3d = MapTo3D(canvas, verticalExaggeration=float(ui.lineEdit_zFactor.text()))
if self.ui.radioButton_Simple.isChecked() or demlayerid is None:
if demlayerid:
dem_width = int(ui.lineEdit_Width.text())
dem_height = int(ui.lineEdit_Height.text())
else:
dem_width = dem_height = 2
context = OutputContext(mapTo3d, canvas, demlayerid, self.vectorPropertiesDict, self.objectTypeManager, self.localBrowsingMode,
dem_width, dem_height, ui.spinBox_sidetransp.value(), ui.spinBox_demtransp.value())
htmlfilename = runSimple(htmlfilename, context, self.progress)
else:
context = OutputContext(mapTo3d, canvas, demlayerid, self.vectorPropertiesDict, self.objectTypeManager, self.localBrowsingMode)
htmlfilename = runAdvanced(htmlfilename, context, self, self.progress)
self.progress(100)
ui.pushButton_Run.setEnabled(True)
if htmlfilename is None:
return
self.clearRubberBands()
if not tools.openHTMLFile(htmlfilename):
return
QDialog.accept(self)
def reject(self):
self.endPointSelection()
self.clearRubberBands()
QDialog.reject(self)
def startPointSelection(self):
canvas = self.iface.mapCanvas()
self.previousMapTool = canvas.mapTool()
canvas.setMapTool(self.mapTool)
self.ui.toolButton_PointTool.setVisible(False)
def endPointSelection(self):
self.mapTool.reset()
self.iface.mapCanvas().setMapTool(self.previousMapTool)
def rectangleSelected(self):
ui = self.ui
ui.radioButton_Advanced.setChecked(True)
rect = self.mapTool.rectangle()
toRect = rect.width() and rect.height()
self.switchFocusMode(toRect)
ui.lineEdit_xmin.setText(str(rect.xMinimum()))
ui.lineEdit_ymin.setText(str(rect.yMinimum()))
ui.lineEdit_xmax.setText(str(rect.xMaximum()))
ui.lineEdit_ymax.setText(str(rect.yMaximum()))
quadtree = QuadTree(self.iface.mapCanvas().extent())
quadtree.buildTreeByRect(rect, self.ui.spinBox_Height.value())
self.createRubberBands(quadtree.quads(), rect.center())
self.setWindowState(self.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
def pointSelected(self):
# set values of controls
self.ui.lineEdit_CenterX.setText(str(self.mapTool.point.x()))
self.ui.lineEdit_CenterY.setText(str(self.mapTool.point.y()))
self.ui.radioButton_Advanced.setChecked(True)
quadtree = QuadTree(self.iface.mapCanvas().extent(), self.mapTool.point, self.ui.spinBox_Height.value())
self.createRubberBands(quadtree.quads(), self.mapTool.point)
self.setWindowState(self.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
def mapToolSet(self, mapTool):
if mapTool != self.mapTool:
self.ui.toolButton_PointTool.setVisible(True)
def createQuadTree(self):
ui = self.ui
try:
c = map(float, [ui.lineEdit_xmin.text(), ui.lineEdit_ymin.text(), ui.lineEdit_xmax.text(), ui.lineEdit_ymax.text()])
except:
return None
quadtree = QuadTree(self.iface.mapCanvas().extent())
quadtree.buildTreeByRect(QgsRectangle(c[0], c[1], c[2], c[3]), ui.spinBox_Height.value())
return quadtree
def createRubberBands(self, quads, point=None):
self.clearRubberBands()
# create quads with rubber band
self.rb_quads = QgsRubberBand(self.iface.mapCanvas(), QGis.Line)
self.rb_quads.setColor(Qt.blue)
self.rb_quads.setWidth(1)
for quad in quads:
points = []
extent = quad.extent
points.append(QgsPoint(extent.xMinimum(), extent.yMinimum()))
points.append(QgsPoint(extent.xMinimum(), extent.yMaximum()))
points.append(QgsPoint(extent.xMaximum(), extent.yMaximum()))
points.append(QgsPoint(extent.xMaximum(), extent.yMinimum()))
self.rb_quads.addGeometry(QgsGeometry.fromPolygon([points]), None)
self.log(extent.toString())
self.log("Quad count: %d" % len(quads))
# create a point with rubber band
if point:
self.rb_point = QgsRubberBand(self.iface.mapCanvas(), QGis.Point)
self.rb_point.setColor(Qt.red)
self.rb_point.addPoint(point)
def clearRubberBands(self):
# clear quads and point
if self.rb_quads:
self.iface.mapCanvas().scene().removeItem(self.rb_quads)
self.rb_quads = None
if self.rb_point:
self.iface.mapCanvas().scene().removeItem(self.rb_point)
self.rb_point = None
def useDemToggled(self, checked):
self.ui.comboBox_DEMLayer.setEnabled(checked)
self.ui.groupBox.setEnabled(checked)
def browseClicked(self):
directory = self.ui.lineEdit_OutputFilename.text()
if directory == "":
directory = QDir.homePath()
filename = QFileDialog.getSaveFileName(self, self.tr("Output filename"), directory, "HTML file (*.html *.htm)", options=QFileDialog.DontConfirmOverwrite)
if filename != "":
self.ui.lineEdit_OutputFilename.setText(filename)
def samplingModeChanged(self):
ui = self.ui
isSimpleMode = ui.radioButton_Simple.isChecked()
simple_widgets = [ui.horizontalSlider_Resolution, ui.lineEdit_Width, ui.lineEdit_Height, ui.lineEdit_HRes, ui.lineEdit_VRes, ui.spinBox_sidetransp, ui.spinBox_demtransp]
for w in simple_widgets:
w.setEnabled(isSimpleMode)
isAdvancedMode = not isSimpleMode
advanced_widgets = [ui.spinBox_Height, ui.lineEdit_xmin, ui.lineEdit_ymin, ui.lineEdit_xmax, ui.lineEdit_ymax, ui.toolButton_switchFocusMode]
for w in advanced_widgets:
w.setEnabled(isAdvancedMode)
def updateQuads(self, v=None):
quadtree = self.createQuadTree()
if quadtree:
self.createRubberBands(quadtree.quads(), quadtree.focusRect.center())
else:
self.clearRubberBands()
def switchFocusModeClicked(self):
self.switchFocusMode(not self.ui.label_xmin.isVisible())
def switchFocusMode(self, toRect):
ui = self.ui
toPoint = not toRect
ui.label_xmin.setVisible(toRect)
ui.label_ymin.setVisible(toRect)
ui.lineEdit_xmin.setVisible(toRect)
ui.lineEdit_ymin.setVisible(toRect)
suffix = "max" if toRect else ""
ui.label_xmax.setText("x" + suffix)
ui.label_ymax.setText("y" + suffix)
mode = "point" if toRect else "rectangle"
ui.toolButton_switchFocusMode.setText("To " + mode + " selection")
selection = "area" if toRect else "point"
action = "Stroke a rectangle" if toRect else "Click"
ui.label_Focus.setText("Focus {0} ({1} on map canvas to set values)".format(selection, action))
def log(self, msg):
if debug_mode:
qDebug(msg)
class PointMapTool(QgsMapToolEmitPoint):
def __init__(self, canvas):
self.canvas = canvas
QgsMapToolEmitPoint.__init__(self, self.canvas)
self.point = None
def canvasPressEvent(self, e):
self.point = self.toMapCoordinates(e.pos())
self.emit(SIGNAL("pointSelected()"))
class RectangleMapTool(QgsMapToolEmitPoint):
def __init__(self, canvas):
self.canvas = canvas
QgsMapToolEmitPoint.__init__(self, self.canvas)
self.rubberBand = QgsRubberBand(self.canvas, QGis.Polygon)
self.rubberBand.setColor(QColor(255, 0, 0, 180))
self.rubberBand.setWidth(1)
self.reset()
def reset(self):
self.startPoint = self.endPoint = None
self.isEmittingPoint = False
self.rubberBand.reset(QGis.Polygon)
def canvasPressEvent(self, e):
self.startPoint = self.toMapCoordinates(e.pos())
self.endPoint = self.startPoint
self.isEmittingPoint = True
self.showRect(self.startPoint, self.endPoint)
def canvasReleaseEvent(self, e):
self.isEmittingPoint = False
self.emit(SIGNAL("rectangleCreated()"))
def canvasMoveEvent(self, e):
if not self.isEmittingPoint:
return
self.endPoint = self.toMapCoordinates(e.pos())
self.showRect(self.startPoint, self.endPoint)
def showRect(self, startPoint, endPoint):
self.rubberBand.reset(QGis.Polygon)
if startPoint.x() == endPoint.x() or startPoint.y() == endPoint.y():
return
point1 = QgsPoint(startPoint.x(), startPoint.y())
point2 = QgsPoint(startPoint.x(), endPoint.y())
point3 = QgsPoint(endPoint.x(), endPoint.y())
point4 = QgsPoint(endPoint.x(), startPoint.y())
self.rubberBand.addPoint(point1, False)
self.rubberBand.addPoint(point2, False)
self.rubberBand.addPoint(point3, False)
self.rubberBand.addPoint(point4, True) # true to update canvas
self.rubberBand.show()
def rectangle(self):
if self.startPoint == None or self.endPoint == None:
return None
#elif self.startPoint.x() == self.endPoint.x() or self.startPoint.y() == self.endPoint.y():
# return None
return QgsRectangle(self.startPoint, self.endPoint)
def setRectangle(self, rect):
if rect == self.rectangle():
return False
if rect == None:
self.reset()
else:
self.startPoint = QgsPoint(rect.xMaximum(), rect.yMaximum())
self.endPoint = QgsPoint(rect.xMinimum(), rect.yMinimum())
self.showRect(self.startPoint, self.endPoint)
return True