Skip to content
Permalink
Browse files

Return a referenced rectangle from ExtentSelectionPanel

  • Loading branch information
nyalldawson committed Sep 14, 2017
1 parent 74565e2 commit 80a1d71131040a67a60d542d85a05343173a69c9
@@ -218,7 +218,7 @@ def accept(self):
feedback.pushInfo(self.tr('Input parameters:'))
display_params = []
for k, v in parameters.items():
display_params.append( "'" + k + "' : " + self.alg.parameterDefinition(k).valueAsPythonString(v,context))
display_params.append("'" + k + "' : " + self.alg.parameterDefinition(k).valueAsPythonString(v, context))
feedback.pushCommandInfo('{ ' + ', '.join(display_params) + ' }')
feedback.pushInfo('')
start_time = time.time()
@@ -36,7 +36,11 @@
from qgis.utils import iface
from qgis.core import (QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProject)
QgsProcessingParameters,
QgsProject,
QgsCoordinateReferenceSystem,
QgsRectangle,
QgsReferencedRectangle)
from processing.gui.RectangleMapTool import RectangleMapTool
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.dataobjects import createContext
@@ -54,6 +58,8 @@ def __init__(self, dialog, param):

self.dialog = dialog
self.param = param
self.crs = QgsProject.instance().crs()

if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
if hasattr(self.leText, 'setPlaceholderText'):
self.leText.setPlaceholderText(
@@ -126,7 +132,7 @@ def useLayerExtent(self):
(item, ok) = QInputDialog.getItem(self, self.tr('Select extent'),
self.tr('Use extent from'), extents, False)
if ok:
self.setValueFromRect(extentsDict[item]["extent"])
self.setValueFromRect(QgsReferencedRectangle(extentsDict[item]["extent"], QgsCoordinateReferenceSystem(extentsDict[item]["authid"])))
if extentsDict[item]["authid"] != iface.mapCanvas().mapSettings().destinationCrs().authid():
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("The projection of the chosen layer is not the same as canvas projection! The selected extent might not be what was intended."),
@@ -146,6 +152,10 @@ def setValueFromRect(self, r):
r.xMinimum(), r.xMaximum(), r.yMinimum(), r.yMaximum())

self.leText.setText(s)
try:
self.crs = r.crs()
except:
self.crs = QgsProject.instance().crs()
self.tool.reset()
canvas = iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
@@ -155,7 +165,13 @@ def setValueFromRect(self, r):

def getValue(self):
if str(self.leText.text()).strip() != '':
return str(self.leText.text())
try:
parts = self.leText.text().split(',')
parts = [float(p) for p in parts]
r = QgsReferencedRectangle(QgsRectangle(parts[0], parts[2], parts[1], parts[3]), self.crs)
return r
except:
return str(self.leText.text())
else:
return None

0 comments on commit 80a1d71

Please sign in to comment.
You can’t perform that action at this time.