def accept(self): styles = {} for key in list(self.valueItems.keys()): styles[key] = str(self.valueItems[key].getValue()) RenderingStyles.addAlgStylesAndSave(self.alg.id(), styles) QDialog.accept(self)
def accept(self): styles = {} for key in self.valueItems.keys(): styles[key] = unicode(self.valueItems[key].getValue()) RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles) QDialog.accept(self)
def initialize(): # Add the basic providers Processing.addProvider(QGISAlgorithmProvider()) Processing.addProvider(ModelerOnlyAlgorithmProvider()) Processing.addProvider(GdalOgrAlgorithmProvider()) Processing.addProvider(LidarToolsAlgorithmProvider()) Processing.addProvider(OTBAlgorithmProvider()) Processing.addProvider(RAlgorithmProvider()) Processing.addProvider(SagaAlgorithmProvider()) Processing.addProvider(GrassAlgorithmProvider()) Processing.addProvider(Grass7AlgorithmProvider()) Processing.addProvider(ScriptAlgorithmProvider()) Processing.addProvider(TauDEMAlgorithmProvider()) Processing.addProvider(Processing.modeler) Processing.modeler.initializeSettings() # And initialize AlgorithmDecorator.loadClassification() ProcessingLog.startLogging() ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles() Processing.loadFromProviders() # Inform registered listeners that all providers' algorithms have been loaded Processing.fireAlgsListHasChanged()
def initialize(): if "model" in [p.getName() for p in Processing.providers]: return # Add the basic providers for c in AlgorithmProvider.__subclasses__(): Processing.addProvider(c()) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def initialize(): if "model" in [p.id() for p in QgsApplication.processingRegistry().providers()]: return # Add the basic providers for c in QgsProcessingProvider.__subclasses__(): p = c() Processing.BASIC_PROVIDERS.append(p) QgsApplication.processingRegistry().addProvider(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def initialize(): if "model" in [p.id() for p in QgsApplication.processingRegistry().providers()]: return # Add the basic providers for c in QgsProcessingProvider.__subclasses__(): p = c() if p.id() in ('native', '3d'): # c++ providers are already registered continue if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def handleAlgorithmResults(alg, progress, showResults = True): wrongLayers = [] htmlResults = False; progress.setText("Loading resulting layers") i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if out.value.startswith("memory:"): layer = out.memoryLayer QgsMapLayerRegistry.instance().addMapLayers([layer]) else: if ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name)) except Exception, e: wrongLayers.append(out) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True
def setTableContent(self): numOutputs = 0 for output in self.alg.outputDefinitions(): if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)): numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputDefinitions(): if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)): item = QTableWidgetItem(output.description() + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.id(), output.name()) if style: item.setText(str(style)) self.valueItems[output.name()] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.flags() & QgsProcessingParameterDefinition.FlagHidden: numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.flags() & QgsProcessingParameterDefinition.FlagHidden: item = QTableWidgetItem(output.description() + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.id(), output.name()) if style: item.setText(str(style)) self.valueItems[output.name()] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: item = QTableWidgetItem(output.description + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.commandLineName(), output.name) if style: item.setText(unicode(style)) self.valueItems[output.name] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] htmlResults = False if progress is None: progress = SilentProgress() progress.setText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if out.value.startswith('memory:'): layer = out.memoryLayer QgsMapLayerRegistry.instance().addMapLayers([layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load( out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name)) except Exception, e: wrongLayers.append(out) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: numOutputs += 1 self.tblStyles.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: item = QTableWidgetItem(output.description + '<' + output.__class__.__name__ + '>') item.setFlags(Qt.ItemIsEnabled) self.tblStyles.setItem(i, 0, item) item = RenderingStyleFilePanel() style = \ RenderingStyles.getStyle(self.alg.commandLineName(), output.name) if style: item.setText(str(style)) self.valueItems[output.name] = item self.tblStyles.setCellWidget(i, 1, item) self.tblStyles.setRowHeight(i, 22) i += 1
def handleAlgorithmResults(alg, context, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString(l, context) if layer is not None: if not ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): layer.setName(details.name) style = None if details.outputName: style = RenderingStyles.getStyle(alg.id(), details.outputName) if style is None: if layer.type() == QgsMapLayer.RasterLayer: style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE) else: if layer.geometryType() == QgsWkbTypes.PointGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE) elif layer.geometryType() == QgsWkbTypes.LineGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_LINE_STYLE) else: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE) if style: layer.loadNamedStyle(style) details.project.addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) if details.postProcessor(): details.postProcessor().postProcessLayer(layer, context, feedback) else: wrongLayers.append(str(l)) except Exception: QgsMessageLog.logMessage(QCoreApplication.translate('Postprocessing', "Error loading result layer:") + "\n" + traceback.format_exc(), 'Processing', Qgis.Critical) wrongLayers.append(str(l)) i += 1 feedback.setProgress(100) if wrongLayers: msg = QCoreApplication.translate('Postprocessing', "The following layers were not correctly generated.") msg += "<ul>" + "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += QCoreApplication.translate('Postprocessing', "You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.") feedback.reportError(msg) return len(wrongLayers) == 0
def initialize(): if "model" in [ p.id() for p in QgsApplication.processingRegistry().providers() ]: return # Add the basic providers for c in QgsProcessingProvider.__subclasses__(): p = c() if p.id() in ('native', '3d'): # c++ providers are already registered continue if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def handleAlgorithmResults(alg, context, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString(l, context, typeHint=details.layerTypeHint) if layer is not None: set_layer_name(layer, details) style = None if details.outputName: style = RenderingStyles.getStyle(alg.id(), details.outputName) if style is None: if layer.type() == QgsMapLayer.RasterLayer: style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE) else: if layer.geometryType() == QgsWkbTypes.PointGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE) elif layer.geometryType() == QgsWkbTypes.LineGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_LINE_STYLE) else: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE) if style: layer.loadNamedStyle(style) details.project.addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) if details.postProcessor(): details.postProcessor().postProcessLayer(layer, context, feedback) else: wrongLayers.append(str(l)) except Exception: QgsMessageLog.logMessage(QCoreApplication.translate('Postprocessing', "Error loading result layer:") + "\n" + traceback.format_exc(), 'Processing', Qgis.Critical) wrongLayers.append(str(l)) i += 1 feedback.setProgress(100) if wrongLayers: msg = QCoreApplication.translate('Postprocessing', "The following layers were not correctly generated.") msg += "<ul>" + "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += QCoreApplication.translate('Postprocessing', "You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.") feedback.reportError(msg) return len(wrongLayers) == 0
def initialize(): if "model" in [ p.id() for p in QgsApplication.processingRegistry().providers() ]: return with QgsRuntimeProfiler.profile('Initialize'): # add native provider if not already added if "native" not in [ p.id() for p in QgsApplication.processingRegistry().providers() ]: QgsApplication.processingRegistry().addProvider( QgsNativeAlgorithms(QgsApplication.processingRegistry())) # add 3d provider if available and not already added if "3d" not in [ p.id() for p in QgsApplication.processingRegistry().providers() ]: try: from qgis._3d import Qgs3DAlgorithms QgsApplication.processingRegistry().addProvider( Qgs3DAlgorithms(QgsApplication.processingRegistry())) except ImportError: # no 3d library available pass # Add the basic providers for c in [ QgisAlgorithmProvider, Grass7AlgorithmProvider, GdalAlgorithmProvider, OtbAlgorithmProvider, SagaAlgorithmProvider, ScriptAlgorithmProvider, ModelerAlgorithmProvider, ProjectProvider ]: p = c() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def initialize(): if "model" in [p.id() for p in QgsApplication.processingRegistry().providers()]: return # Add the basic providers for c in [ QgisAlgorithmProvider, Grass7AlgorithmProvider, GdalAlgorithmProvider, SagaAlgorithmProvider, ScriptAlgorithmProvider, ModelerAlgorithmProvider ]: p = c() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def initialize(): if "model" in [ p.id() for p in QgsApplication.processingRegistry().providers() ]: return # Add the basic providers for c in [ QgisAlgorithmProvider, Grass7AlgorithmProvider, GdalAlgorithmProvider, SagaAlgorithmProvider, ScriptAlgorithmProvider, ModelerAlgorithmProvider ]: p = c() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def initialize(): #add the basic providers Processing.addProvider(QGISAlgorithmProvider()) Processing.addProvider(ModelerOnlyAlgorithmProvider()) Processing.addProvider(GdalOgrAlgorithmProvider()) Processing.addProvider(LidarToolsAlgorithmProvider()) Processing.addProvider(OTBAlgorithmProvider()) Processing.addProvider(RAlgorithmProvider()) Processing.addProvider(SagaAlgorithmProvider()) Processing.addProvider(GrassAlgorithmProvider()) Processing.addProvider(ScriptAlgorithmProvider()) Processing.addProvider(TauDEMAlgorithmProvider()) Processing.addProvider(AdminToolsAlgorithmProvider()) Processing.modeler.initializeSettings(); #and initialize AlgorithmDecorator.loadClassification() ProcessingLog.startLogging() ProcessingConfig.initialize() ProcessingConfig.loadSettings() RenderingStyles.loadStyles() Processing.loadFromProviders()
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] htmlResults = False if progress is None: progress = SilentProgress() progress.setText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)) or \ (isinstance(out, OutputFile) and out.ext == 'csv'): try: if hasattr(out, "layer") and out.layer is not None: out.layer.setLayerName(out.description) QgsMapLayerRegistry.instance().addMapLayers([out.layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description isRaster = True if isinstance(out, OutputRaster) else False dataobjects.load( out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name), isRaster) except Exception: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, "Error loading result layer:\n" + traceback.format_exc()) wrongLayers.append(out.description) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" progress.error(msg) if showResults and htmlResults and not wrongLayers: dlg = ResultsDialog() dlg.exec_() return len(wrongLayers) == 0
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] htmlResults = False if progress is None: progress = SilentProgress() progress.setText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if out.value.startswith('memory:'): layer = out.memoryLayer QgsMapLayerRegistry.instance().addMapLayers([layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load( out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name)) except Exception as e: wrongLayers.append(out.description) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True i += 1 if wrongLayers: QApplication.restoreOverrideCursor() dlg = MessageDialog() dlg.setTitle( QCoreApplication.translate('Postprocessing', 'Problem loading output layers')) msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the <a href='log'>log messages</a> to find more information about the execution of the algorithm" dlg.setMessage(msg) dlg.exec_() if showResults and htmlResults and not wrongLayers: QApplication.restoreOverrideCursor() dlg = ResultsDialog() dlg.exec_() return len(wrongLayers) == 0
def initialize(): # Add the basic providers Processing.addProvider(QGISAlgorithmProvider()) Processing.addProvider(ModelerOnlyAlgorithmProvider()) Processing.addProvider(GdalOgrAlgorithmProvider()) Processing.addProvider(LidarToolsAlgorithmProvider()) Processing.addProvider(OTBAlgorithmProvider()) Processing.addProvider(RAlgorithmProvider()) Processing.addProvider(SagaAlgorithmProvider()) Processing.addProvider(GrassAlgorithmProvider()) Processing.addProvider(Grass7AlgorithmProvider()) Processing.addProvider(ScriptAlgorithmProvider()) Processing.addProvider(TauDEMAlgorithmProvider()) Processing.modeler.initializeSettings() # And initialize AlgorithmDecorator.loadClassification() ProcessingLog.startLogging() ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles() Processing.loadFromProviders()
def initialize(): # Add the basic providers Processing.addProvider(QGISAlgorithmProvider(), updateList=False) Processing.addProvider(ModelerOnlyAlgorithmProvider(), updateList=False) Processing.addProvider(GdalOgrAlgorithmProvider(), updateList=False) Processing.addProvider(LidarToolsAlgorithmProvider(), updateList=False) Processing.addProvider(OTBAlgorithmProvider(), updateList=False) Processing.addProvider(RAlgorithmProvider(), updateList=False) Processing.addProvider(SagaAlgorithmProvider(), updateList=False) Processing.addProvider(GrassAlgorithmProvider(), updateList=False) Processing.addProvider(Grass7AlgorithmProvider(), updateList=False) Processing.addProvider(ScriptAlgorithmProvider(), updateList=False) Processing.addProvider(TauDEMAlgorithmProvider(), updateList=False) Processing.addProvider(PreconfiguredAlgorithmProvider(), updateList=False) Processing.addProvider(Processing.modeler, updateList=False) Processing.modeler.initializeSettings() # And initialize AlgorithmClassification.loadClassification() ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles() Processing.loadFromProviders()
def initialize(): # Add the basic providers Processing.addProvider(QGISAlgorithmProvider(), updateList=False) Processing.addProvider(ModelerOnlyAlgorithmProvider(), updateList=False) Processing.addProvider(GdalOgrAlgorithmProvider(), updateList=False) Processing.addProvider(LidarToolsAlgorithmProvider(), updateList=False) Processing.addProvider(OTBAlgorithmProvider(), updateList=False) Processing.addProvider(RAlgorithmProvider(), updateList=False) Processing.addProvider(SagaAlgorithmProvider(), updateList=False) Processing.addProvider(GrassAlgorithmProvider(), updateList=False) Processing.addProvider(Grass7AlgorithmProvider(), updateList=False) Processing.addProvider(ScriptAlgorithmProvider(), updateList=False) Processing.addProvider(TauDEMAlgorithmProvider(), updateList=False) Processing.addProvider(Processing.modeler, updateList=False) Processing.modeler.initializeSettings() # And initialize AlgorithmClassification.loadClassification() ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles() Processing.loadFromProviders() # Inform registered listeners that all providers' algorithms have been loaded Processing.fireAlgsListHasChanged()
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] htmlResults = False if progress is None: progress = SilentProgress() progress.setText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if hasattr(out, "layer") and out.layer is not None: out.layer.setLayerName(out.description) QgsMapLayerRegistry.instance().addMapLayers([out.layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description isRaster = True if isinstance(out, OutputRaster) else False dataobjects.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name), isRaster) except Exception: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error loading result layer:\n" + traceback.format_exc()) wrongLayers.append(out.description) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" progress.error(msg) if showResults and htmlResults and not wrongLayers: dlg = ResultsDialog() dlg.exec_() return len(wrongLayers) == 0
def handleAlgorithmResults(alg, context, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: feedback.setProgress(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: layer = QgsProcessingUtils.mapLayerFromString( out.value, context) if layer: layer.setName(out.description) QgsProject.instance().addMapLayer( context.temporaryLayerStore().takeMapLayer(layer)) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description isRaster = True if isinstance(out, OutputRaster) else False dataobjects.load( out.value, name, alg.crs, RenderingStyles.getStyle(alg.id(), out.name), isRaster) except Exception: QgsMessageLog.logMessage( "Error loading result layer:\n" + traceback.format_exc(), 'Processing', QgsMessageLog.CRITICAL) wrongLayers.append(out.description) elif isinstance(out, OutputHTML): resultsList.addResult(alg.icon(), out.description, out.value) i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" feedback.reportError(msg) return len(wrongLayers) == 0
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] htmlResults = False if progress is None: progress = SilentProgress() progress.setText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if out.value.startswith('memory:'): layer = out.memoryLayer QgsMapLayerRegistry.instance().addMapLayers([layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name)) except Exception as e: wrongLayers.append(out.description) elif isinstance(out, OutputHTML): ProcessingResults.addResult(out.description, out.value) htmlResults = True i += 1 if wrongLayers: QApplication.restoreOverrideCursor() dlg = MessageDialog() dlg.setTitle(QCoreApplication.translate('Postprocessing', 'Problem loading output layers')) msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the <a href='log'>log messages</a> to find more information about the execution of the algorithm" dlg.setMessage(msg) dlg.exec_() if showResults and htmlResults and not wrongLayers: QApplication.restoreOverrideCursor() dlg = ResultsDialog() dlg.exec_() return len(wrongLayers) == 0
def handleAlgorithmResults(alg, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: feedback.setProgress(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if hasattr(out, "layer") and out.layer is not None: out.layer.setName(out.description) QgsProject.instance().addMapLayers([out.layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load( out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name)) except Exception: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, "Error loading result layer:\n" + traceback.format_exc()) wrongLayers.append(out.description) elif isinstance(out, OutputHTML): resultsList.addResult(alg.getIcon(), out.description, out.value) i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" feedback.reportError(msg) return len(wrongLayers) == 0
def handleAlgorithmResults(alg, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for out in alg.outputs: feedback.setProgress(100 * i / float(len(alg.outputs))) if out.hidden or not out.open: continue if isinstance(out, (OutputRaster, OutputVector, OutputTable)): try: if hasattr(out, "layer") and out.layer is not None: out.layer.setName(out.description) QgsProject.instance().addMapLayers([out.layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) else: name = out.description dataobjects.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.id(), out.name)) except Exception: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Error loading result layer:\n" + traceback.format_exc()) wrongLayers.append(out.description) elif isinstance(out, OutputHTML): resultsList.addResult(alg.icon(), out.description, out.value) i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" feedback.reportError(msg) return len(wrongLayers) == 0
def setTableContent(self): numOutputs = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: numOutputs += 1 self.tableWidget.setRowCount(numOutputs) i = 0 for output in self.alg.outputs: if isinstance(output, (OutputVector, OutputRaster)): if not output.hidden: item = QtGui.QTableWidgetItem(output.description + "<" + output.__module__.split(".")[-1] + ">") item.setFlags(QtCore.Qt.ItemIsEnabled) self.tableWidget.setItem(i, 0, item) item = RenderingStyleFilePanel() style = RenderingStyles.getStyle(self.alg.commandLineName(), output.name) if style: item.setText(str(style)) self.valueItems[output.name] = item self.tableWidget.setCellWidget(i, 1, item) self.tableWidget.setRowHeight(i, 22) i += 1
def handleAlgorithmResults(alg, progress=None, showResults=True): wrongLayers = [] reslayers = [] if progress is None: progress = SilentProgress() progress.setText(QCoreApplication.translate('ArpaGeoprocessing', 'Loading resulting layer')) i = 0 for out in alg.outputs: progress.setPercentage(100 * i / float(len(alg.outputs))) #if out.hidden or not out.open: #continue if isinstance(out, (OutputVector)): try: if alg.outputType == 'Postgis': outUri = QgsDataSourceURI() psql = out.value['PSQL'] outUri.setConnection(psql.PSQLHost, psql.PSQLPort, psql.PSQLDatabase, psql.PSQLUsername, psql.PSQLPassword) outUri.setDataSource(out.value['schema'],out.value['table'],out.value['geoColumn']) layer = QgsVectorLayer(outUri.uri(), out.value['table'], "postgres") QgsMapLayerRegistry.instance().addMapLayers([layer]) else: if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(out.value) name = name.split('.')[0] else: name = out.description # removing .ext from name if exixst layer = dataobjects.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(), out.name)) reslayers.append(layer) except Exception, e: wrongLayers.append(out) i += 1
def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parameters={}): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress( 100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString( l, context, typeHint=details.layerTypeHint) if layer is not None: set_layer_name(layer, details) '''If running a model, the execution will arrive here when an algorithm that is part of that model is executed. We check if its output is a final otuput of the model, and adapt the output name accordingly''' outputName = details.outputName expcontext = QgsExpressionContext() scope = QgsExpressionContextScope() expcontext.appendScope(scope) for out in alg.outputDefinitions(): if out.name() not in parameters: continue outValue = parameters[out.name()] if hasattr(outValue, "sink"): outValue = outValue.sink.valueAsString(expcontext)[0] else: outValue = str(outValue) if outValue == l: outputName = out.name() break style = None if outputName: style = RenderingStyles.getStyle(alg.id(), outputName) if style is None: if layer.type() == QgsMapLayerType.RasterLayer: style = ProcessingConfig.getSetting( ProcessingConfig.RASTER_STYLE) else: if layer.geometryType() == QgsWkbTypes.PointGeometry: style = ProcessingConfig.getSetting( ProcessingConfig.VECTOR_POINT_STYLE) elif layer.geometryType() == QgsWkbTypes.LineGeometry: style = ProcessingConfig.getSetting( ProcessingConfig.VECTOR_LINE_STYLE) else: style = ProcessingConfig.getSetting( ProcessingConfig.VECTOR_POLYGON_STYLE) if style: layer.loadNamedStyle(style) details.project.addMapLayer( context.temporaryLayerStore().takeMapLayer(layer)) if details.postProcessor(): details.postProcessor().postProcessLayer( layer, context, feedback) else: wrongLayers.append(str(l)) except Exception: QgsMessageLog.logMessage( QCoreApplication.translate( 'Postprocessing', "Error loading result layer:") + "\n" + traceback.format_exc(), 'Processing', Qgis.Critical) wrongLayers.append(str(l)) i += 1 feedback.setProgress(100) if wrongLayers: msg = QCoreApplication.translate( 'Postprocessing', "The following layers were not correctly generated.") msg += "<ul>" + "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += QCoreApplication.translate( 'Postprocessing', "You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm." ) feedback.reportError(msg) return len(wrongLayers) == 0
def initialize(): if "model" in [p.id() for p in QgsApplication.processingRegistry().providers()]: return with QgsRuntimeProfiler.profile('Initialize'): # add native provider if not already added if "native" not in [p.id() for p in QgsApplication.processingRegistry().providers()]: QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms(QgsApplication.processingRegistry())) # add 3d provider if available and not already added if "3d" not in [p.id() for p in QgsApplication.processingRegistry().providers()]: try: from qgis._3d import Qgs3DAlgorithms QgsApplication.processingRegistry().addProvider(Qgs3DAlgorithms(QgsApplication.processingRegistry())) except ImportError: # no 3d library available pass # Add the basic providers for c in [ QgisAlgorithmProvider, GdalAlgorithmProvider, ScriptAlgorithmProvider, ModelerAlgorithmProvider, ProjectProvider ]: p = c() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) if QgsApplication.platform() == 'external': # for external applications we must also load the builtin providers stored in separate plugins try: from grassprovider.Grass7AlgorithmProvider import Grass7AlgorithmProvider p = Grass7AlgorithmProvider() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) except ImportError: pass try: from otbprovider.OtbAlgorithmProvider import OtbAlgorithmProvider p = OtbAlgorithmProvider() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) except ImportError: pass try: from sagaprovider.SagaAlgorithmProvider import SagaAlgorithmProvider p = SagaAlgorithmProvider() if QgsApplication.processingRegistry().addProvider(p): Processing.BASIC_PROVIDERS.append(p) except ImportError: pass # And initialize ProcessingConfig.initialize() ProcessingConfig.readSettings() RenderingStyles.loadStyles()
def handleAlgorithmResults(alg, context, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText( QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress( 100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString(l, context) if layer is not None: layer.setName(details.name) details.project.addMapLayer( context.temporaryLayerStore().takeMapLayer(layer)) else: name = details.name if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(l) dataobjects.load(l, name, alg.crs, RenderingStyles.getStyle(alg.id(), l)) except Exception: QgsMessageLog.logMessage( "Error loading result layer:\n" + traceback.format_exc(), 'Processing', QgsMessageLog.CRITICAL) #wrongLayers.append(out.description()) wrongLayers.append(l) # for out in alg.outputs: # feedback.setProgress(100 * i / float(len(alg.outputs))) # if out.flags() & QgsProcessingParameterDefinition.FlagHidden or not out.open: # continue # if isinstance(out, (OutputRaster, OutputVector, OutputTable)): # try: # layer = QgsProcessingUtils.mapLayerFromString(out.value, context) # if layer: # layer.setName(out.description) # QgsProject.instance().addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) # else: # if ProcessingConfig.getSetting( # ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): # name = os.path.basename(out.value) # else: # name = out.description # # isRaster = True if isinstance(out, OutputRaster) else False # dataobjects.load(out.value, name, alg.crs, # RenderingStyles.getStyle(alg.id(), out.name), # isRaster) # except Exception: # QgsMessageLog.logMessage("Error loading result layer:\n" + traceback.format_exc(), 'Processing', QgsMessageLog.CRITICAL) # wrongLayers.append(out.description) # elif isinstance(out, OutputHTML): # resultsList.addResult(alg.icon(), out.description, out.value) i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" feedback.reportError(msg) return len(wrongLayers) == 0
def okPressed(self): styles = {} for key in self.valueItems.keys(): styles[key] = str(self.valueItems[key].getValue()) RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles) self.close()
def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parameters={}): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString(l, context, typeHint=details.layerTypeHint) if layer is not None: set_layer_name(layer, details) '''If running a model, the execution will arrive here when an algorithm that is part of that model is executed. We check if its output is a final otuput of the model, and adapt the output name accordingly''' outputName = details.outputName expcontext = QgsExpressionContext() scope = QgsExpressionContextScope() expcontext.appendScope(scope) for out in alg.outputDefinitions(): if out.name() not in parameters: continue outValue = parameters[out.name()] if hasattr(outValue, "sink"): outValue = outValue.sink.valueAsString(expcontext)[0] else: outValue = str(outValue) if outValue == l: outputName = out.name() break style = None if outputName: style = RenderingStyles.getStyle(alg.id(), outputName) if style is None: if layer.type() == QgsMapLayer.RasterLayer: style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE) else: if layer.geometryType() == QgsWkbTypes.PointGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POINT_STYLE) elif layer.geometryType() == QgsWkbTypes.LineGeometry: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_LINE_STYLE) else: style = ProcessingConfig.getSetting(ProcessingConfig.VECTOR_POLYGON_STYLE) if style: layer.loadNamedStyle(style) details.project.addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) if details.postProcessor(): details.postProcessor().postProcessLayer(layer, context, feedback) else: wrongLayers.append(str(l)) except Exception: QgsMessageLog.logMessage(QCoreApplication.translate('Postprocessing', "Error loading result layer:") + "\n" + traceback.format_exc(), 'Processing', Qgis.Critical) wrongLayers.append(str(l)) i += 1 feedback.setProgress(100) if wrongLayers: msg = QCoreApplication.translate('Postprocessing', "The following layers were not correctly generated.") msg += "<ul>" + "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += QCoreApplication.translate('Postprocessing', "You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.") feedback.reportError(msg) return len(wrongLayers) == 0
def handleAlgorithmResults(alg, context, feedback=None, showResults=True): wrongLayers = [] if feedback is None: feedback = QgsProcessingFeedback() feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers')) i = 0 for l, details in context.layersToLoadOnCompletion().items(): if feedback.isCanceled(): return False if len(context.layersToLoadOnCompletion()) > 2: # only show progress feedback if we're loading a bunch of layers feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion()))) try: layer = QgsProcessingUtils.mapLayerFromString(l, context) if layer is not None: layer.setName(details.name) details.project.addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) else: name = details.name if ProcessingConfig.getSetting( ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): name = os.path.basename(l) dataobjects.load(l, name, alg.crs, RenderingStyles.getStyle(alg.id(), l)) except Exception: QgsMessageLog.logMessage("Error loading result layer:\n" + traceback.format_exc(), 'Processing', QgsMessageLog.CRITICAL) #wrongLayers.append(out.description()) wrongLayers.append(l) # for out in alg.outputs: # feedback.setProgress(100 * i / float(len(alg.outputs))) # if out.flags() & QgsProcessingParameterDefinition.FlagHidden or not out.open: # continue # if isinstance(out, (OutputRaster, OutputVector, OutputTable)): # try: # layer = QgsProcessingUtils.mapLayerFromString(out.value, context) # if layer: # layer.setName(out.description) # QgsProject.instance().addMapLayer(context.temporaryLayerStore().takeMapLayer(layer)) # else: # if ProcessingConfig.getSetting( # ProcessingConfig.USE_FILENAME_AS_LAYER_NAME): # name = os.path.basename(out.value) # else: # name = out.description # # isRaster = True if isinstance(out, OutputRaster) else False # dataobjects.load(out.value, name, alg.crs, # RenderingStyles.getStyle(alg.id(), out.name), # isRaster) # except Exception: # QgsMessageLog.logMessage("Error loading result layer:\n" + traceback.format_exc(), 'Processing', QgsMessageLog.CRITICAL) # wrongLayers.append(out.description) # elif isinstance(out, OutputHTML): # resultsList.addResult(alg.icon(), out.description, out.value) i += 1 QApplication.restoreOverrideCursor() if wrongLayers: msg = "The following layers were not correctly generated.<ul>" msg += "".join(["<li>%s</li>" % lay for lay in wrongLayers]) + "</ul>" msg += "You can check the log messages to find more information about the execution of the algorithm" feedback.reportError(msg) return len(wrongLayers) == 0