4848from processing .core .outputs import OutputTable
4949
5050
51+ from qgis .utils import iface
52+
53+
5154class 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