def runalgIterating(self):
     try:
         outputs = {}
         #store output values to use them later as basenames for all outputs
         for out in self.algorithm.outputs:
             outputs[out.name] = out.value
         i = 1
         for f in self.filelist:
             self.algorithm.setParameterValue(self.parameterToIterate, f)
             for out in self.algorithm.outputs:
                 filename = outputs[out.name]
                 if filename:
                     filename = filename[:filename.rfind(".")] + "_" + str(
                         i) + filename[filename.rfind("."):]
                 out.value = filename
             self.progress.setText("Executing iteration " + str(i) + "/" +
                                   str(len(self.filelist)) + "...")
             self.progress.setPercentage((i * 100) / len(self.filelist))
             self.runalg()
             Postprocessing.handleAlgorithmResults(self.algorithm,
                                                   self.progress, False)
             self.iterated.emit(i)
             i += 1
         self.algExecuted.emit()
     except BaseException, e:
         self.error.emit(str(e))
         print "Error iterating " + str(e)
Exemple #2
0
 def accept(self):
     keepOpen = ProcessingConfig.getSetting(
             ProcessingConfig.KEEP_DIALOG_OPEN)
     try:
         if self.setParamValues():
             QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
             ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM,
                                  self.alg.getAsCommand())
             ret = UnthreadedAlgorithmExecutor.runalg(self.alg, self)
             QApplication.restoreOverrideCursor()
             if ret:
                 Postprocessing.handleAlgorithmResults(self.alg,
                                                       self,
                                                       not keepOpen)
             self.executed = True
             QDialog.reject(self)
         else:
             QMessageBox.critical(self,
                                  self.tr('Unable to execute algorithm'),
                                  self.tr('Wrong or missing parameter '
                                          'values'))
             return
     except GeoAlgorithmExecutionException, e:
         QApplication.restoreOverrideCursor()
         QMessageBox.critical(self, "Error",e.msg)
         ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, e.msg)
         self.executed = False
         QDialog.reject(self)
 def finish(self, i):
     if not self.stop:
         if self.load[i]:
             Postprocessing.handleAlgorithmResults(self.algs[i], self, False)
         i += 1
         if len(self.algs) == i:
             self.finishAll()
             self.algEx = None
         else:
             self.nextAlg(i)
 def finish(self, i):
     if not self.stop:
         if self.load[i]:
             Postprocessing.handleAlgorithmResults(self.algs[i], self, False)
         i += 1
         if len(self.algs) == i:
             self.finishAll()
             self.algEx = None
         else:
             self.nextAlg(i)
    def accept(self):
        self.canceled = False
        self.algs = []
        self.load = []
        for row in range(self.table.rowCount()):
            alg = self.alg.getCopy()
            col = 0
            for param in alg.parameters:
                if param.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                if not self.setParameterValueFromWidget(param, widget, alg):
                    self.progressLabel.setText('<b>Missing parameter value: '
                            + param.description + ' (row ' + str(row + 1)
                            + ')</b>')
                    self.algs = None
                    return
                col += 1
            for out in alg.outputs:
                if out.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                text = widget.getValue()
                if text.strip() != '':
                    out.value = text
                    col += 1
                else:
                    self.progressLabel.setText(
                            '<b>Wrong or missing parameter value: '
                             + out.description + ' (row ' + str(row + 1)
                             + ')</b>')
                    self.algs = None
                    return
            self.algs.append(alg)
            widget = self.table.cellWidget(row, col)
            self.load.append(widget.currentIndex() == 0)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.table.setEnabled(False)
        self.tabWidget.setCurrentIndex(1)
        self.progress.setMaximum(len(self.algs))
        for (i, alg) in enumerate(self.algs):
            self.setBaseText('Processing algorithm ' + str(i + 1) + '/'
                             + str(len(self.algs)) + '...')
            if UnthreadedAlgorithmExecutor.runalg(alg, self) \
                and not self.canceled:
                if self.load[i]:
                    Postprocessing.handleAlgorithmResults(alg, self, False)
            else:
                QApplication.restoreOverrideCursor()
                return

        self.finishAll()
    def accept(self):
        self.canceled = False
        self.algs = []
        self.load = []
        for row in range(self.table.rowCount()):
            alg = self.alg.getCopy()
            col = 0
            for param in alg.parameters:
                if param.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                if not self.setParameterValueFromWidget(param, widget, alg):
                    self.progressLabel.setText('<b>Missing parameter value: ' +
                                               param.description + ' (row ' +
                                               str(row + 1) + ')</b>')
                    self.algs = None
                    return
                col += 1
            for out in alg.outputs:
                if out.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                text = widget.getValue()
                if text.strip() != '':
                    out.value = text
                    col += 1
                else:
                    self.progressLabel.setText(
                        '<b>Wrong or missing parameter value: ' +
                        out.description + ' (row ' + str(row + 1) + ')</b>')
                    self.algs = None
                    return
            self.algs.append(alg)
            widget = self.table.cellWidget(row, col)
            self.load.append(widget.currentIndex() == 0)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.table.setEnabled(False)
        self.tabWidget.setCurrentIndex(1)
        self.progress.setMaximum(len(self.algs))
        for (i, alg) in enumerate(self.algs):
            self.setBaseText('Processing algorithm ' + str(i + 1) + '/' +
                             str(len(self.algs)) + '...')
            if UnthreadedAlgorithmExecutor.runalg(alg, self) \
                and not self.canceled:
                if self.load[i]:
                    Postprocessing.handleAlgorithmResults(alg, self, False)
            else:
                QApplication.restoreOverrideCursor()
                return

        self.finishAll()
 def finish(self):
     keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
     if self.iterateParam is None:
         Postprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
     self.executed = True
     self.setInfo("Algorithm %s finished" % self.alg.name)
     QApplication.restoreOverrideCursor()
     if not keepOpen:
         self.close()
     else:
         self.resetGUI()
         if self.alg.getHTMLOutputsCount() > 0:
             self.setInfo("HTML output has been generated by this algorithm.\nOpen the results dialog to check it.")
    def accept(self):
        self.algs = []
        self.load = []
        for row in range(self.table.rowCount()):
            alg = self.alg.getCopy()#copy.deepcopy(self.alg)
            col = 0
            for param in alg.parameters:
                if param.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                if not self.setParameterValueFromWidget(param, widget, alg):
                    self.progressLabel.setText("<b>Missing parameter value: " + param.description + " (row " + str(row + 1) + ")</b>")
                    self.algs = None
                    return
                col+=1
            for out in alg.outputs:
                if out.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                text = widget.getValue()
                if text.strip() != "":
                    out.value = text
                    col+=1
                else:
                    self.progressLabel.setText("<b>Wrong or missing parameter value: " + out.description + " (row " + str(row + 1) + ")</b>")
                    self.algs = None
                    return
            self.algs.append(alg)
            widget = self.table.cellWidget(row, col)
            self.load.append(widget.currentIndex() == 0)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.table.setEnabled(False)
        if ProcessingConfig.getSetting(ProcessingConfig.USE_THREADS):
            self.tabWidget.setCurrentIndex(1)
            self.nextAlg(0)
        else:
            i=0
            self.progress.setMaximum(len(self.algs))
            for alg in self.algs:
                self.setBaseText("Processing algorithm " + str(i+1) + "/" + str(len(self.algs)) + "...")
                if UnthreadedAlgorithmExecutor.runalg(alg, self):
                    if self.load[i]:
                        Postprocessing.handleAlgorithmResults(alg, self, False)
                    i+=1
                else:
                    QApplication.restoreOverrideCursor()
                    return

            self.finishAll()
    def accept(self):
        self.algs = []
        self.load = []
        for row in range(self.table.rowCount()):
            alg = self.alg.getCopy()#copy.deepcopy(self.alg)
            col = 0
            for param in alg.parameters:
                if param.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                if not self.setParameterValueFromWidget(param, widget, alg):
                    self.progressLabel.setText("<b>Missing parameter value: " + param.description + " (row " + str(row + 1) + ")</b>")
                    self.algs = None
                    return
                col+=1
            for out in alg.outputs:
                if out.hidden:
                    continue
                widget = self.table.cellWidget(row, col)
                text = widget.getValue()
                if text.strip() != "":
                    out.value = text
                    col+=1
                else:
                    self.progressLabel.setText("<b>Wrong or missing parameter value: " + out.description + " (row " + str(row + 1) + ")</b>")
                    self.algs = None
                    return
            self.algs.append(alg)
            widget = self.table.cellWidget(row, col)
            self.load.append(widget.currentIndex() == 0)

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.table.setEnabled(False)
        if ProcessingConfig.getSetting(ProcessingConfig.USE_THREADS):
            self.tabWidget.setCurrentIndex(1)
            self.nextAlg(0)
        else:
            i=0
            self.progress.setMaximum(len(self.algs))
            for alg in self.algs:
                self.setBaseText("Processing algorithm " + str(i+1) + "/" + str(len(self.algs)) + "...")
                if UnthreadedAlgorithmExecutor.runalg(alg, self):
                    if self.load[i]:
                        Postprocessing.handleAlgorithmResults(alg, self, False)
                    i+=1
                else:
                    QApplication.restoreOverrideCursor()
                    return

            self.finishAll()
 def finish(self):
     keepOpen = ProcessingConfig.getSetting(
         ProcessingConfig.KEEP_DIALOG_OPEN)
     if self.iterateParam is None:
         Postprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
     self.executed = True
     self.setInfo('Algorithm %s finished' % self.alg.name)
     QApplication.restoreOverrideCursor()
     if not keepOpen:
         self.close()
     else:
         self.resetGUI()
         if self.alg.getHTMLOutputsCount() > 0:
             self.setInfo(
                 'HTML output has been generated by this ' +
                 'algorithm.\nOpen the results dialog to check it.')
    def runalgIterating(alg, paramToIter, progress):
        # Generate all single-feature layers
        settings = QSettings()
        systemEncoding = settings.value('/UI/encoding', 'System')
        layerfile = alg.getParameterValue(paramToIter)
        layer = dataobjects.getObjectFromUri(layerfile, False)
        feat = QgsFeature()
        filelist = []
        outputs = {}
        provider = layer.dataProvider()
        features = vector.features(layer)
        for feat in features:
            output = getTempFilename('shp')
            filelist.append(output)
            writer = QgsVectorFileWriter(output, systemEncoding,
                                         provider.fields(),
                                         provider.geometryType(), layer.crs())
            writer.addFeature(feat)
            del writer

        # store output values to use them later as basenames for all outputs
        for out in alg.outputs:
            outputs[out.name] = out.value

        # now run all the algorithms
        i = 1
        for f in filelist:
            alg.setParameterValue(paramToIter, f)
            for out in alg.outputs:
                filename = outputs[out.name]
                if filename:
                    filename = filename[:filename.rfind('.')] + '_' + str(i) \
                        + filename[filename.rfind('.'):]
                out.value = filename
            progress.setText('Executing iteration ' + str(i) + '/' +
                             str(len(filelist)) + '...')
            progress.setPercentage(i * 100 / len(filelist))
            if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
                Postprocessing.handleAlgorithmResults(alg, SilentProgress(),
                                                      False)
                i += 1
            else:
                return False

        return True
    def runalgIterating(alg, paramToIter, progress):
        # Generate all single-feature layers
        settings = QSettings()
        systemEncoding = settings.value('/UI/encoding', 'System')
        layerfile = alg.getParameterValue(paramToIter)
        layer = dataobjects.getObjectFromUri(layerfile, False)
        feat = QgsFeature()
        filelist = []
        outputs = {}
        provider = layer.dataProvider()
        features = vector.features(layer)
        for feat in features:
            output = getTempFilename('shp')
            filelist.append(output)
            writer = QgsVectorFileWriter(output, systemEncoding,
                    provider.fields(), provider.geometryType(), layer.crs())
            writer.addFeature(feat)
            del writer

        # store output values to use them later as basenames for all outputs
        for out in alg.outputs:
            outputs[out.name] = out.value

        # now run all the algorithms
        i = 1
        for f in filelist:
            alg.setParameterValue(paramToIter, f)
            for out in alg.outputs:
                filename = outputs[out.name]
                if filename:
                    filename = filename[:filename.rfind('.')] + '_' + str(i) \
                        + filename[filename.rfind('.'):]
                out.value = filename
            progress.setText('Executing iteration ' + str(i) + '/'
                             + str(len(filelist)) + '...')
            progress.setPercentage(i * 100 / len(filelist))
            if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
                Postprocessing.handleAlgorithmResults(alg, SilentProgress(),
                        False)
                i += 1
            else:
                return False

        return True
 def runalgIterating(self):
     try:
         outputs = {}
         #store output values to use them later as basenames for all outputs
         for out in self.algorithm.outputs:
             outputs[out.name] = out.value
         i = 1
         for f in self.filelist:
             self.algorithm.setParameterValue(self.parameterToIterate, f)
             for out in self.algorithm.outputs:
                 filename = outputs[out.name]
                 if filename:
                     filename = filename[:filename.rfind(".")] + "_" + str(i) + filename[filename.rfind("."):]
                 out.value = filename
             self.progress.setText("Executing iteration " + str(i) + "/" + str(len(self.filelist)) + "...")
             self.progress.setPercentage((i * 100) / len(self.filelist))
             self.runalg()
             Postprocessing.handleAlgorithmResults(self.algorithm, self.progress, False)
             self.iterated.emit(i)
             i += 1
         self.algExecuted.emit()
     except BaseException, e:
         self.error.emit(str(e))
         print "Error iterating " + str(e)