Skip to content

Commit

Permalink
Return a referenced rectangle from ExtentSelectionPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2017
1 parent 74565e2 commit 80a1d71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -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()
Expand Down
22 changes: 19 additions & 3 deletions python/plugins/processing/gui/ExtentSelectionPanel.py
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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."),
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 80a1d71

Please sign in to comment.