Beispiel #1
0
 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
Beispiel #2
0
 def loadHTMLResults(self, alg, i):
     for out in alg.outputs:
         if out.hidden or not out.open:
             continue
         if isinstance(out, OutputHTML):
             ProcessingResults.addResult(out.description + '[' + str(i)
                     + ']', out.value)
Beispiel #3
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, e:
                wrongLayers.append(out.description)
        elif isinstance(out, OutputHTML):
            ProcessingResults.addResult(out.description, out.value)
            htmlResults = True
 def loadHTMLResults(self, alg, i):
     for out in alg.outputs:
         if out.hidden or not out.open:
             continue
         if isinstance(out, OutputHTML):
             ProcessingResults.addResult(
                 out.description + '[' + str(i) + ']', out.value)
Beispiel #5
0
 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
                     QGisLayers.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name))
             except Exception, e:
                 wrongLayers.append(out)
                 #QMessageBox.critical(None, "Error", str(e))
         elif isinstance(out, OutputHTML):
             ProcessingResults.addResult(out.description, out.value)
             htmlResults = True
    def loadHTMLResults(self, alg, num):
        for out in alg.outputs:
            if out.hidden or not out.open:
                continue

            if isinstance(out, OutputHTML):
                ProcessingResults.addResult("{} [{}]".format(out.description, num), out.value)
Beispiel #7
0
    def loadHTMLResults(self, alg, num):
        for out in alg.outputs:
            if out.flags() & QgsProcessingParameterDefinition.FlagHidden or not out.open:
                continue

            if isinstance(out, OutputHTML):
                ProcessingResults.addResult(
                    '{} [{}]'.format(out.description(), num), out.value)
    def loadHTMLResults(self, alg, num):
        for out in alg.outputs:
            if out.hidden or not out.open:
                continue

            if isinstance(out, OutputHTML):
                ProcessingResults.addResult(
                    '{} [{}]'.format(out.description, num), out.value)
Beispiel #9
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 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, OutputFile) and out.ext == 'csv':
            try:
                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):
            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
Beispiel #10
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, 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
Beispiel #12
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 createSummaryTable(self):
     createTable = False
     for out in self.algs[0].outputs:
         if isinstance(out, (OutputNumber,OutputString)):
             createTable = True
             break
     if not createTable:
         return
     outputFile = getTempFilename("html")
     f = open(outputFile, "w")
     for alg in self.algs:
         f.write("<hr>\n")
         for out in alg.outputs:
             if isinstance(out, (OutputNumber,OutputString)):
                 f.write("<p>" + out.description + ": " + str(out.value) + "</p>\n")
     f.write("<hr>\n")
     f.close()
     ProcessingResults.addResult(self.algs[0].name + "[summary]", outputFile)
 def createSummaryTable(self):
     createTable = False
     for out in self.algs[0].outputs:
         if isinstance(out, (OutputNumber,OutputString)):
             createTable = True
             break
     if not createTable:
         return
     outputFile = ProcessingUtils.getTempFilename("html")
     f = open(outputFile, "w")
     for alg in self.algs:
         f.write("<hr>\n")
         for out in alg.outputs:
             if isinstance(out, (OutputNumber,OutputString)):
                 f.write("<p>" + out.description + ": " + str(out.value) + "</p>\n")
     f.write("<hr>\n")
     f.close()
     ProcessingResults.addResult(self.algs[0].name + "[summary]", outputFile)
Beispiel #15
0
 def fillTree(self):
     elements = ProcessingResults.getResults()
     if len(elements) == 0:
         self.lastUrl = None
         return
     for element in elements:
         item = TreeResultItem(element)
         item.setIcon(0, self.keyIcon)
         self.tree.addTopLevelItem(item)
     self.lastUrl = QUrl(elements[-1].filename)
Beispiel #16
0
 def fillTree(self):
     elements = ProcessingResults.getResults()
     if len(elements) == 0:
         self.lastUrl = None
         return
     for element in elements:
         item = TreeResultItem(element)
         item.setIcon(0, self.keyIcon)
         self.tree.addTopLevelItem(item)
     self.lastUrl = elements[-1].filename
 def createSummaryTable(self):
     createTable = False
     for out in self.algs[0].outputs:
         if isinstance(out, (OutputNumber, OutputString)):
             createTable = True
             break
     if not createTable:
         return
     outputFile = getTempFilename('html')
     f = open(outputFile, 'w')
     for alg in self.algs:
         f.write('<hr>\n')
         for out in alg.outputs:
             if isinstance(out, (OutputNumber, OutputString)):
                 f.write('<p>' + out.description + ': ' + str(out.value) +
                         '</p>\n')
     f.write('<hr>\n')
     f.close()
     ProcessingResults.addResult(self.algs[0].name + '[summary]',
                                 outputFile)
Beispiel #18
0
 def createSummaryTable(self):
     createTable = False
     for out in self.algs[0].outputs:
         if isinstance(out, (OutputNumber, OutputString)):
             createTable = True
             break
     if not createTable:
         return
     outputFile = getTempFilename('html')
     f = open(outputFile, 'w')
     for alg in self.algs:
         f.write('<hr>\n')
         for out in alg.outputs:
             if isinstance(out, (OutputNumber, OutputString)):
                 f.write('<p>' + out.description + ': ' + str(out.value)
                         + '</p>\n')
     f.write('<hr>\n')
     f.close()
     ProcessingResults.addResult(self.algs[0].name + '[summary]',
                                 outputFile)
    def createSummaryTable(self):
        createTable = False

        for out in self.algs[0].outputs:
            if isinstance(out, (OutputNumber, OutputString)):
                createTable = True
                break

        if not createTable:
            return

        outputFile = getTempFilename("html")
        with codecs.open(outputFile, "w", encoding="utf-8") as f:
            for alg in self.algs:
                f.write("<hr>\n")
                for out in alg.outputs:
                    if isinstance(out, (OutputNumber, OutputString)):
                        f.write("<p>{}: {}</p>\n".format(out.description, out.value))
            f.write("<hr>\n")

        ProcessingResults.addResult("{} [summary]".format(self.algs[0].name), outputFile)
Beispiel #20
0
    def createSummaryTable(self):
        createTable = False

        for out in self.algs[0].outputs:
            if isinstance(out, (OutputNumber, OutputString)):
                createTable = True
                break

        if not createTable:
            return

        outputFile = getTempFilename('html')
        with codecs.open(outputFile, 'w', encoding='utf-8') as f:
            for alg in self.algs:
                f.write('<hr>\n')
                for out in alg.outputs:
                    if isinstance(out, (OutputNumber, OutputString)):
                        f.write('<p>{}: {}</p>\n'.format(out.description, out.value))
            f.write('<hr>\n')

        ProcessingResults.addResult(
            '{} [summary]'.format(self.algs[0].name), outputFile)