Skip to content

Commit 948dcc2

Browse files
committedOct 13, 2016
[processing] warn if extent might not be in the expected CRS
1 parent 5fd4cee commit 948dcc2

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
 

‎python/plugins/processing/core/ProcessingConfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ProcessingConfig:
5858
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
5959
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
6060
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
61+
WARN_UNMATCHING_EXTENT_CRS = 'WARN_UNMATCHING_EXTENT_CRS'
6162
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
6263
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
6364
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
@@ -106,6 +107,10 @@ def initialize():
106107
ProcessingConfig.tr('General'),
107108
ProcessingConfig.WARN_UNMATCHING_CRS,
108109
ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True))
110+
ProcessingConfig.addSetting(Setting(
111+
ProcessingConfig.tr('General'),
112+
ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS,
113+
ProcessingConfig.tr("Warn before executing if extent CRS might not match layers CRS"), True))
109114
ProcessingConfig.addSetting(Setting(
110115
ProcessingConfig.tr('General'),
111116
ProcessingConfig.RASTER_STYLE,

‎python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464

6565
from processing.tools import dataobjects
6666

67+
from qgis.utils import iface
68+
6769

6870
class AlgorithmDialog(AlgorithmDialogBase):
6971

@@ -189,6 +191,37 @@ def setParamValue(self, param, widget, alg=None):
189191
else:
190192
return param.setValue(unicode(widget.text()))
191193

194+
def checkExtentCRS(self):
195+
unmatchingCRS = False
196+
hasExtent = False
197+
projectCRS = iface.mapCanvas().mapSettings().destinationCrs()
198+
layers = dataobjects.getAllLayers()
199+
for param in self.alg.parameters:
200+
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
201+
if param.value:
202+
if isinstance(param, ParameterMultipleInput):
203+
inputlayers = param.value.split(';')
204+
else:
205+
inputlayers = [param.value]
206+
for inputlayer in inputlayers:
207+
for layer in layers:
208+
if layer.source() == inputlayer:
209+
if layer.crs() != projectCRS:
210+
unmatchingCRS = True
211+
212+
p = dataobjects.getObjectFromUri(inputlayer)
213+
if p is not None:
214+
if p.crs() != projectCRS:
215+
unmatchingCRS = True
216+
if isinstance(param, ParameterExtent):
217+
value = self.mainWidget.valueItems[param.name].leText.text().strip()
218+
print value
219+
if value:
220+
hasExtent = True
221+
222+
return hasExtent and unmatchingCRS
223+
224+
192225
def accept(self):
193226
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
194227

@@ -204,6 +237,17 @@ def accept(self):
204237
QMessageBox.No)
205238
if reply == QMessageBox.No:
206239
return
240+
checkExtentCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS)
241+
if checkExtentCRS and self.checkExtentCRS():
242+
reply = QMessageBox.question(self, self.tr("Extent CRS"),
243+
self.tr('Extent parameters must use the same CRS as the input layers.\n'
244+
'Your input layers do not have the same extent as the project, '
245+
'so the extent might be in a wrong CRS if you have selected it from the canvas.\n'
246+
'Do you want to continue?'),
247+
QMessageBox.Yes | QMessageBox.No,
248+
QMessageBox.No)
249+
if reply == QMessageBox.No:
250+
return
207251
msg = self.alg._checkParameterValuesBeforeExecuting()
208252
if msg:
209253
QMessageBox.warning(

0 commit comments

Comments
 (0)
Please sign in to comment.