Skip to content
Permalink
Browse files
Move createContext to dataobjects
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent b067bd7 commit 86002f3b6fa555cfdaa81e8e0ee45e0505033853
@@ -48,7 +48,7 @@
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 @@ def execute(self, context=None, feedback=None, model=None):
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.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 @@ def runAlgorithm(algOrName, onFinish, *args, **kwargs):
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 @@
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 @@ def __init__(self, name='', description='', options=[], default=None, isSource=F
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 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 @@ def accept(self):
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.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,15 +38,18 @@
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
from processing.tools.system import (getTempFilenameInTempFolder,
getTempFilename,
removeInvalidChars,
isWindows)
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

ALL_TYPES = [-1]

@@ -59,6 +62,29 @@
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 @@
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

0 comments on commit 86002f3

Please sign in to comment.