Skip to content

Commit b83fbb1

Browse files
volayaalexbruy
authored andcommitted
[processing] warn if extent might not be in the expected CRS
1 parent b4562d1 commit b83fbb1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

python/plugins/processing/core/ProcessingConfig.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ProcessingConfig(object):
6060
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
6161
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
6262
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
63+
WARN_UNMATCHING_EXTENT_CRS = 'WARN_UNMATCHING_EXTENT_CRS'
6364
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
6465
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
6566
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
@@ -108,6 +109,10 @@ def initialize():
108109
ProcessingConfig.tr('General'),
109110
ProcessingConfig.WARN_UNMATCHING_CRS,
110111
ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True))
112+
ProcessingConfig.addSetting(Setting(
113+
ProcessingConfig.tr('General'),
114+
ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS,
115+
ProcessingConfig.tr("Warn before executing if extent CRS might not match layers CRS"), True))
111116
ProcessingConfig.addSetting(Setting(
112117
ProcessingConfig.tr('General'),
113118
ProcessingConfig.RASTER_STYLE,

python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
from processing.core.outputs import OutputTable
4949

5050

51+
from qgis.utils import iface
52+
53+
5154
class AlgorithmDialog(AlgorithmDialogBase):
5255

5356
def __init__(self, alg):
@@ -100,6 +103,37 @@ def setParamValues(self):
100103
def setParamValue(self, param, wrapper, alg=None):
101104
return param.setValue(wrapper.value())
102105

106+
def checkExtentCRS(self):
107+
unmatchingCRS = False
108+
hasExtent = False
109+
projectCRS = iface.mapCanvas().mapSettings().destinationCrs()
110+
layers = dataobjects.getAllLayers()
111+
for param in self.alg.parameters:
112+
if isinstance(param, (ParameterRaster, ParameterVector, ParameterMultipleInput)):
113+
if param.value:
114+
if isinstance(param, ParameterMultipleInput):
115+
inputlayers = param.value.split(';')
116+
else:
117+
inputlayers = [param.value]
118+
for inputlayer in inputlayers:
119+
for layer in layers:
120+
if layer.source() == inputlayer:
121+
if layer.crs() != projectCRS:
122+
unmatchingCRS = True
123+
124+
p = dataobjects.getObjectFromUri(inputlayer)
125+
if p is not None:
126+
if p.crs() != projectCRS:
127+
unmatchingCRS = True
128+
if isinstance(param, ParameterExtent):
129+
value = self.mainWidget.valueItems[param.name].leText.text().strip()
130+
print value
131+
if value:
132+
hasExtent = True
133+
134+
return hasExtent and unmatchingCRS
135+
136+
103137
def accept(self):
104138
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
105139

@@ -115,6 +149,17 @@ def accept(self):
115149
QMessageBox.No)
116150
if reply == QMessageBox.No:
117151
return
152+
checkExtentCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_EXTENT_CRS)
153+
if checkExtentCRS and self.checkExtentCRS():
154+
reply = QMessageBox.question(self, self.tr("Extent CRS"),
155+
self.tr('Extent parameters must use the same CRS as the input layers.\n'
156+
'Your input layers do not have the same extent as the project, '
157+
'so the extent might be in a wrong CRS if you have selected it from the canvas.\n'
158+
'Do you want to continue?'),
159+
QMessageBox.Yes | QMessageBox.No,
160+
QMessageBox.No)
161+
if reply == QMessageBox.No:
162+
return
118163
msg = self.alg._checkParameterValuesBeforeExecuting()
119164
if msg:
120165
QMessageBox.warning(

0 commit comments

Comments
 (0)