mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[processing] warn if extent might not be in the expected CRS
This commit is contained in:
parent
b4562d143e
commit
b83fbb16c9
@ -60,6 +60,7 @@ class ProcessingConfig(object):
|
|||||||
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
|
POST_EXECUTION_SCRIPT = 'POST_EXECUTION_SCRIPT'
|
||||||
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
|
SHOW_CRS_DEF = 'SHOW_CRS_DEF'
|
||||||
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
|
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_RASTER_LAYER_EXT = 'DEFAULT_OUTPUT_RASTER_LAYER_EXT'
|
||||||
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
|
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DEFAULT_OUTPUT_VECTOR_LAYER_EXT'
|
||||||
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
|
SHOW_PROVIDERS_TOOLTIP = "SHOW_PROVIDERS_TOOLTIP"
|
||||||
@ -108,6 +109,10 @@ class ProcessingConfig(object):
|
|||||||
ProcessingConfig.tr('General'),
|
ProcessingConfig.tr('General'),
|
||||||
ProcessingConfig.WARN_UNMATCHING_CRS,
|
ProcessingConfig.WARN_UNMATCHING_CRS,
|
||||||
ProcessingConfig.tr("Warn before executing if layer CRS's do not match"), True))
|
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.addSetting(Setting(
|
||||||
ProcessingConfig.tr('General'),
|
ProcessingConfig.tr('General'),
|
||||||
ProcessingConfig.RASTER_STYLE,
|
ProcessingConfig.RASTER_STYLE,
|
||||||
|
@ -48,6 +48,9 @@ from processing.core.outputs import OutputVector
|
|||||||
from processing.core.outputs import OutputTable
|
from processing.core.outputs import OutputTable
|
||||||
|
|
||||||
|
|
||||||
|
from qgis.utils import iface
|
||||||
|
|
||||||
|
|
||||||
class AlgorithmDialog(AlgorithmDialogBase):
|
class AlgorithmDialog(AlgorithmDialogBase):
|
||||||
|
|
||||||
def __init__(self, alg):
|
def __init__(self, alg):
|
||||||
@ -100,6 +103,37 @@ class AlgorithmDialog(AlgorithmDialogBase):
|
|||||||
def setParamValue(self, param, wrapper, alg=None):
|
def setParamValue(self, param, wrapper, alg=None):
|
||||||
return param.setValue(wrapper.value())
|
return param.setValue(wrapper.value())
|
||||||
|
|
||||||
|
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):
|
def accept(self):
|
||||||
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
|
self.settings.setValue("/Processing/dialogBase", self.saveGeometry())
|
||||||
|
|
||||||
@ -115,6 +149,17 @@ class AlgorithmDialog(AlgorithmDialogBase):
|
|||||||
QMessageBox.No)
|
QMessageBox.No)
|
||||||
if reply == QMessageBox.No:
|
if reply == QMessageBox.No:
|
||||||
return
|
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()
|
msg = self.alg._checkParameterValuesBeforeExecuting()
|
||||||
if msg:
|
if msg:
|
||||||
QMessageBox.warning(
|
QMessageBox.warning(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user