2012-10-05 23:28:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2013-08-12 20:44:27 +02:00
|
|
|
Postprocessing.py
|
2012-10-05 23:28:47 +02:00
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2012-10-05 23:28:47 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-03-30 18:55:46 +01:00
|
|
|
import os
|
|
|
|
from PyQt4.QtGui import *
|
2014-10-03 21:56:24 +03:00
|
|
|
from PyQt4.QtCore import *
|
2013-03-30 18:55:46 +01:00
|
|
|
from qgis.core import *
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.gui.SilentProgress import SilentProgress
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.core.ProcessingConfig import ProcessingConfig
|
|
|
|
from processing.gui.ResultsDialog import ResultsDialog
|
|
|
|
from processing.gui.RenderingStyles import RenderingStyles
|
|
|
|
from processing.gui.CouldNotLoadResultsDialog import CouldNotLoadResultsDialog
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.outputs import OutputRaster
|
|
|
|
from processing.core.outputs import OutputVector
|
|
|
|
from processing.core.outputs import OutputTable
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core.ProcessingResults import ProcessingResults
|
2014-07-14 14:19:09 +02:00
|
|
|
from processing.core.outputs import OutputHTML
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.tools import dataobjects
|
|
|
|
|
2014-07-14 14:19:09 +02:00
|
|
|
def handleAlgorithmResults(alg, progress=None, showResults=True):
|
2014-06-08 23:12:13 +02:00
|
|
|
wrongLayers = []
|
|
|
|
htmlResults = False
|
2014-07-14 14:19:09 +02:00
|
|
|
if progress is None:
|
|
|
|
progress = SilentProgress()
|
2014-10-03 21:56:24 +03:00
|
|
|
progress.setText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers'))
|
2014-06-08 23:12:13 +02:00
|
|
|
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)
|
2012-09-15 18:25:25 +03:00
|
|
|
else:
|
2014-06-08 23:12:13 +02:00
|
|
|
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
|
|
|
|
i += 1
|
|
|
|
if wrongLayers:
|
|
|
|
QApplication.restoreOverrideCursor()
|
|
|
|
dlg = CouldNotLoadResultsDialog(wrongLayers, alg)
|
|
|
|
dlg.exec_()
|
2013-03-31 21:18:27 +02:00
|
|
|
|
2014-06-08 23:12:13 +02:00
|
|
|
if showResults and htmlResults and not wrongLayers:
|
|
|
|
QApplication.restoreOverrideCursor()
|
|
|
|
dlg = ResultsDialog()
|
|
|
|
dlg.exec_()
|