64
64
65
65
from processing .tools import dataobjects
66
66
67
+ from qgis .utils import iface
68
+
67
69
68
70
class AlgorithmDialog (AlgorithmDialogBase ):
69
71
@@ -189,6 +191,37 @@ def setParamValue(self, param, widget, alg=None):
189
191
else :
190
192
return param .setValue (unicode (widget .text ()))
191
193
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
+
192
225
def accept (self ):
193
226
self .settings .setValue ("/Processing/dialogBase" , self .saveGeometry ())
194
227
@@ -204,6 +237,17 @@ def accept(self):
204
237
QMessageBox .No )
205
238
if reply == QMessageBox .No :
206
239
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
207
251
msg = self .alg ._checkParameterValuesBeforeExecuting ()
208
252
if msg :
209
253
QMessageBox .warning (
0 commit comments