Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] warn if extent might not be in the expected CRS
  • Loading branch information
volaya committed Oct 13, 2016
1 parent 5fd4cee commit 948dcc2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -58,6 +58,7 @@ class ProcessingConfig:
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
WARN_UNMATCHING_EXTENT_CRS = 'WARN_UNMATCHING_EXTENT_CRS'
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
Expand Down Expand Up @@ -106,6 +107,10 @@ def initialize():
ProcessingConfig.tr('General'),
ProcessingConfig.WARN_UNMATCHING_CRS,
ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS,
ProcessingConfig.tr("Warn before executing if extent CRS might not match layers CRS"), True))
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.RASTER_STYLE,
Expand Down
44 changes: 44 additions & 0 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -64,6 +64,8 @@

from processing.tools import dataobjects

from qgis.utils import iface


class AlgorithmDialog(AlgorithmDialogBase):

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

def checkExtentCRS(self):
unmatchingCRS = False
hasExtent = False
projectCRS = iface.mapCanvas().mapSettings().destinationCrs()
layers = dataobjects.getAllLayers()
for param in self.alg.parameters:
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
if param.value:
if isinstance(param, ParameterMultipleInput):
inputlayers = param.value.split(';')
else:
inputlayers = [param.value]
for inputlayer in inputlayers:
for layer in layers:
if layer.source() == inputlayer:
if layer.crs() != projectCRS:
unmatchingCRS = True

p = dataobjects.getObjectFromUri(inputlayer)
if p is not None:
if p.crs() != projectCRS:
unmatchingCRS = True
if isinstance(param, ParameterExtent):
value = self.mainWidget.valueItems[param.name].leText.text().strip()
print value
if value:
hasExtent = True

return hasExtent and unmatchingCRS


def accept(self):
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())

Expand All @@ -204,6 +237,17 @@ def accept(self):
QMessageBox.No)
if reply == QMessageBox.No:
return
checkExtentCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS)
if checkExtentCRS and self.checkExtentCRS():
reply = QMessageBox.question(self, self.tr("Extent CRS"),
self.tr('Extent parameters must use the same CRS as the input layers.\n'
'Your input layers do not have the same extent as the project, '
'so the extent might be in a wrong CRS if you have selected it from the canvas.\n'
'Do you want to continue?'),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.No:
return
msg = self.alg._checkParameterValuesBeforeExecuting()
if msg:
QMessageBox.warning(
Expand Down

0 comments on commit 948dcc2

Please sign in to comment.