mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Move createContext to dataobjects
This commit is contained in:
parent
b067bd786a
commit
86002f3b6f
@ -48,7 +48,7 @@ from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecution
|
||||
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
|
||||
from processing.core.outputs import OutputVector, OutputRaster, OutputTable, OutputHTML, Output
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
from processing.tools import dataobjects, vector, general
|
||||
from processing.tools import dataobjects
|
||||
from processing.algs.help import shortHelp
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ class GeoAlgorithm(QgsProcessingAlgorithm):
|
||||
if feedback is None:
|
||||
feedback = QgsProcessingFeedback()
|
||||
if context is None:
|
||||
context = general.createContext()
|
||||
context = dataobjects.createContext()
|
||||
|
||||
self.model = model
|
||||
try:
|
||||
|
@ -49,7 +49,7 @@ from processing.gui.MessageBarProgress import MessageBarProgress
|
||||
from processing.gui.RenderingStyles import RenderingStyles
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.gui.AlgorithmExecutor import execute
|
||||
from processing.tools import dataobjects, general
|
||||
from processing.tools import dataobjects
|
||||
|
||||
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider # NOQA
|
||||
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
|
||||
@ -233,7 +233,7 @@ class Processing(object):
|
||||
feedback = kwargs["feedback"]
|
||||
elif iface is not None:
|
||||
feedback = MessageBarProgress(alg.displayName())
|
||||
context = general.createContext()
|
||||
context = dataobjects.createContext()
|
||||
|
||||
ret = execute(alg, context, feedback)
|
||||
if ret:
|
||||
|
@ -45,7 +45,7 @@ from qgis.core import (QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinat
|
||||
QgsVectorFileWriter)
|
||||
|
||||
from processing.tools.vector import resolveFieldIndex
|
||||
from processing.tools import dataobjects, general
|
||||
from processing.tools import dataobjects
|
||||
from processing.core.outputs import OutputNumber, OutputRaster, OutputVector
|
||||
|
||||
|
||||
@ -1082,7 +1082,7 @@ class ParameterSelection(Parameter):
|
||||
if layer.isValid():
|
||||
try:
|
||||
index = resolveFieldIndex(layer, options[1])
|
||||
feats = QgsProcessingUtils.getFeatures(layer, general.createContext())
|
||||
feats = QgsProcessingUtils.getFeatures(layer, dataobjects.createContext())
|
||||
for feature in feats:
|
||||
self.options.append(str(feature.attributes()[index]))
|
||||
except ValueError:
|
||||
|
@ -52,7 +52,7 @@ from processing.core.outputs import OutputRaster
|
||||
from processing.core.outputs import OutputVector
|
||||
from processing.core.outputs import OutputTable
|
||||
|
||||
from processing.tools import dataobjects, general
|
||||
from processing.tools import dataobjects
|
||||
|
||||
|
||||
class AlgorithmDialog(AlgorithmDialogBase):
|
||||
@ -198,7 +198,7 @@ class AlgorithmDialog(AlgorithmDialogBase):
|
||||
self.setInfo(
|
||||
self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))
|
||||
|
||||
context = general.createContext()
|
||||
context = dataobjects.createContext()
|
||||
|
||||
if self.iterateParam:
|
||||
if executeIterating(self.alg, self.iterateParam, context, self.feedback):
|
||||
|
@ -40,7 +40,6 @@ from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecution
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.tools import dataobjects
|
||||
from processing.tools.system import getTempFilename
|
||||
from processing.tools import vector, general
|
||||
|
||||
|
||||
def execute(alg, context=None, feedback=None):
|
||||
@ -54,7 +53,7 @@ def execute(alg, context=None, feedback=None):
|
||||
if feedback is None:
|
||||
feedback = QgsProcessingFeedback()
|
||||
if context is None:
|
||||
context = general.createContext()
|
||||
context = dataobjects.createContext()
|
||||
|
||||
try:
|
||||
alg.execute(context, feedback)
|
||||
|
@ -38,8 +38,10 @@ from qgis.core import (QgsVectorFileWriter,
|
||||
QgsProject,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsSettings,
|
||||
QgsProcessingUtils)
|
||||
QgsProcessingUtils,
|
||||
QgsProcessingContext)
|
||||
from qgis.gui import QgsSublayersDialog
|
||||
from qgis.PyQt.QtCore import QCoreApplication
|
||||
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
@ -47,6 +49,7 @@ from processing.tools.system import (getTempFilenameInTempFolder,
|
||||
getTempFilename,
|
||||
removeInvalidChars,
|
||||
isWindows)
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
ALL_TYPES = [-1]
|
||||
|
||||
@ -59,6 +62,29 @@ TYPE_FILE = 4
|
||||
TYPE_TABLE = 5
|
||||
|
||||
|
||||
def createContext():
|
||||
"""
|
||||
Creates a default processing context
|
||||
"""
|
||||
context = QgsProcessingContext()
|
||||
context.setProject(QgsProject.instance())
|
||||
|
||||
use_selection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
|
||||
if use_selection:
|
||||
context.setFlags(QgsProcessingContext.UseSelectionIfPresent)
|
||||
|
||||
invalid_features_method = ProcessingConfig.getSetting(ProcessingConfig.FILTER_INVALID_GEOMETRIES)
|
||||
context.setInvalidGeometryCheck(invalid_features_method)
|
||||
|
||||
def raise_error(f):
|
||||
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
|
||||
'Features with invalid geometries found. Please fix these geometries or specify the "Ignore invalid input features" flag'))
|
||||
|
||||
context.setInvalidGeometryCallback(raise_error)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def getSupportedOutputRasterLayerExtensions():
|
||||
allexts = []
|
||||
for exts in list(GdalUtils.getSupportedRasters().values()):
|
||||
|
@ -35,15 +35,10 @@ try:
|
||||
except ImportError:
|
||||
import configparser as configparser
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingContext,
|
||||
QgsProject)
|
||||
from qgis.PyQt.QtCore import (QCoreApplication)
|
||||
from qgis.core import (QgsApplication)
|
||||
from processing.core.Processing import Processing
|
||||
from processing.core.parameters import ParameterSelection
|
||||
from processing.gui.Postprocessing import handleAlgorithmResults
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
||||
|
||||
|
||||
def algorithmOptions(id):
|
||||
@ -97,26 +92,3 @@ def version():
|
||||
cfg.read(os.path.join(pluginPath, 'metadata.txt'))
|
||||
ver = cfg.get('general', 'version').split('.')
|
||||
return 10000 * int(ver[0]) + 100 * int(ver[1]) + int(ver[2])
|
||||
|
||||
|
||||
def createContext():
|
||||
"""
|
||||
Creates a default processing context
|
||||
"""
|
||||
context = QgsProcessingContext()
|
||||
context.setProject(QgsProject.instance())
|
||||
|
||||
use_selection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
|
||||
if use_selection:
|
||||
context.setFlags(QgsProcessingContext.UseSelectionIfPresent)
|
||||
|
||||
invalid_features_method = ProcessingConfig.getSetting(ProcessingConfig.FILTER_INVALID_GEOMETRIES)
|
||||
context.setInvalidGeometryCheck(invalid_features_method)
|
||||
|
||||
def raise_error(f):
|
||||
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
|
||||
'Features with invalid geometries found. Please fix these geometries or specify the "Ignore invalid input features" flag'))
|
||||
|
||||
context.setInvalidGeometryCallback(raise_error)
|
||||
|
||||
return context
|
||||
|
Loading…
x
Reference in New Issue
Block a user