コード例 #1
0
 def preprocess(self, layer):    
     '''
     Preprocesses the layer with the corresponding preprocess hook and returns the path to the 
     resulting layer. If no preprocessing is performed, it returns the input layer itself
     '''    
     if not processingOk:
         return layer
     
     if layer.type() == layer.RasterLayer:                        
         try:
             hookFile = str(QSettings().value("/OpenGeo/Settings/GeoServer/PreuploadRasterHook", ""))
             alg = self.getAlgorithmFromHookFile(hookFile)                
             if (len(alg.parameters) == 1 and isinstance(alg.parameters[0], ParameterRaster) 
                 and len(alg.outputs) == 1 and isinstance(alg.outputs[0], OutputRaster)):
                 alg.parameters[0].setValue(layer)
                 if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
                     return load(alg.outputs[0].value)
                 return layer
         except:
             return layer                                    
     elif layer.type() == layer.VectorLayer: 
         try:
             hookFile = str(QSettings().value("/OpenGeo/Settings/GeoServer/PreuploadVectorHook", ""))
             alg = self.getAlgorithmFromHookFile(hookFile)                
             if (len(alg.parameters) == 1 and isinstance(alg.parameters[0], ParameterVector) 
                 and len(alg.outputs) == 1 and isinstance(alg.outputs[0], OutputVector)):
                 alg.parameters[0].setValue(layer)
                 if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
                     return load(alg.outputs[0].value)
                 return layer
         except:
             return layer
コード例 #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)
コード例 #3
0
    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)) + '...')
            # make sure the log tab is visible before executing the algorithm
            try:
                self.repaint()
            except:
                pass
            if UnthreadedAlgorithmExecutor.runalg(alg, self) \
                and not self.canceled:
                if self.load[i]:
                    handleAlgorithmResults(alg, self, False)
            else:
                QApplication.restoreOverrideCursor()
                return

        self.finishAll()
コード例 #4
0
    def preprocess(self, layer):
        '''
        Preprocesses the layer with the corresponding preprocess hook and returns the path to the 
        resulting layer. If no preprocessing is performed, it returns the input layer itself
        '''
        if not processingOk:
            return layer

        if layer.type() == layer.RasterLayer:
            try:
                hookFile = str(QSettings().value(
                    "/OpenGeo/Settings/GeoServer/PreuploadRasterHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1
                        and isinstance(alg.parameters[0], ParameterRaster)
                        and len(alg.outputs) == 1
                        and isinstance(alg.outputs[0], OutputRaster)):
                    alg.parameters[0].setValue(layer)
                    if UnthreadedAlgorithmExecutor.runalg(
                            alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
        elif layer.type() == layer.VectorLayer:
            try:
                hookFile = str(QSettings().value(
                    "/OpenGeo/Settings/GeoServer/PreuploadVectorHook", ""))
                alg = self.getAlgorithmFromHookFile(hookFile)
                if (len(alg.parameters) == 1
                        and isinstance(alg.parameters[0], ParameterVector)
                        and len(alg.outputs) == 1
                        and isinstance(alg.outputs[0], OutputVector)):
                    alg.parameters[0].setValue(layer)
                    if UnthreadedAlgorithmExecutor.runalg(
                            alg, SilentProgress()):
                        return load(alg.outputs[0].value)
                    return layer
            except:
                return layer
コード例 #5
0
    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()
コード例 #6
0
    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()
コード例 #7
0
ファイル: Processing.py プロジェクト: ColeCummins/QGIS
    def runAlgorithm(algOrName, onFinish, *args):
        if isinstance(algOrName, GeoAlgorithm):
            alg = algOrName
        else:
            alg = Processing.getAlgorithm(algOrName)
        if alg is None:
            print 'Error: Algorithm not found\n'
            return
        if len(args) != alg.getVisibleParametersCount() \
                    + alg.getVisibleOutputsCount():
            print 'Error: Wrong number of parameters'
            processing.alghelp(algOrName)
            return

        alg = alg.getCopy()
        if isinstance(args, dict):
            # Set params by name
            for (name, value) in args.items():
                if alg.getParameterFromName(name).setValue(value):
                    continue
                if alg.getOutputFromName(name).setValue(value):
                    continue
                print 'Error: Wrong parameter value %s for parameter %s.' \
                    % (value, name)
                return
        else:
            i = 0
            for param in alg.parameters:
                if not param.hidden:
                    if not param.setValue(args[i]):
                        print 'Error: Wrong parameter value: ' \
                            + unicode(args[i])
                        return
                    i = i + 1

            for output in alg.outputs:
                if not output.hidden:
                    if not output.setValue(args[i]):
                        print 'Error: Wrong output value: ' + unicode(args[i])
                        return
                    i = i + 1

        msg = alg.checkParameterValuesBeforeExecuting()
        if msg:
            print 'Unable to execute algorithm\n' + msg
            return

        if not alg.checkInputCRS():
            print 'Warning: Not all input layers use the same CRS.\n' \
                + 'This can cause unexpected results.'

        ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, alg.getAsCommand())

        # Don't set the wait cursor twice, because then when you
        # restore it, it will still be a wait cursor.
        cursor = QApplication.overrideCursor()
        if cursor is None or cursor == 0:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        elif cursor.shape() != Qt.WaitCursor:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        progress = MessageBarProgress()
        ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
        if onFinish is not None and ret:
            onFinish(alg, progress)
        QApplication.restoreOverrideCursor()
        progress.close()
        return alg
コード例 #8
0
ファイル: Processing.py プロジェクト: alextheleritis/QGIS
    def runAlgorithm(algOrName, onFinish, *args):
        if isinstance(algOrName, GeoAlgorithm):
            alg = algOrName
        else:
            alg = Processing.getAlgorithm(algOrName)
        if alg == None:
            print("Error: Algorithm not found\n")
            return
        if len(args) != alg.getVisibleParametersCount() + alg.getVisibleOutputsCount():
            print ("Error: Wrong number of parameters")
            processing.alghelp(algOrName)
            return

        alg = alg.getCopy()
        if isinstance(args, dict):
            # set params by name
            for name, value in args.items():
                if alg.getParameterFromName(name).setValue(value):
                    continue;
                if alg.getOutputFromName(name).setValue(value):
                    continue;
                print ("Error: Wrong parameter value %s for parameter %s." % (value, name))
                return
        else:
            i = 0
            for param in alg.parameters:
                if not param.hidden:
                    if not param.setValue(args[i]):
                        print ("Error: Wrong parameter value: " + unicode(args[i]))
                        return
                    i = i +1

            for output in alg.outputs:
                if not output.hidden:
                    if not output.setValue(args[i]):
                        print ("Error: Wrong output value: " + unicode(args[i]))
                        return
                    i = i +1

        msg = alg.checkParameterValuesBeforeExecuting()
        if msg:
            print ("Unable to execute algorithm\n" + msg)
            return

        if not alg.checkInputCRS():
            print ("Warning: Not all input layers use the same CRS.\n" +
                   "This can cause unexpected results.")

        ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, alg.getAsCommand())

        # don't set the wait cursor twice, because then when you restore it
        # it will still be a wait cursor
        cursor = QApplication.overrideCursor()
        if cursor == None or cursor == 0:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        elif cursor.shape() != Qt.WaitCursor:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        useThreads = ProcessingConfig.getSetting(ProcessingConfig.USE_THREADS)

        #this is doing strange things, so temporarily the thread execution is disabled from the console
        useThreads = False

        if useThreads:
            algEx = AlgorithmExecutor(alg)
            progress = QProgressDialog()
            progress.setWindowTitle(alg.name)
            progress.setLabelText("Executing %s..." % alg.name)
            def finish():
                QApplication.restoreOverrideCursor()
                if onFinish is not None:
                    onFinish(alg, SilentProgress())
                progress.close()
            def error(msg):
                QApplication.restoreOverrideCursor()
                print msg
                ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, msg)
            def cancel():
                try:
                    algEx.finished.disconnect()
                    algEx.terminate()
                    QApplication.restoreOverrideCursor()
                    progress.close()
                except:
                    pass
            algEx.error.connect(error)
            algEx.finished.connect(finish)
            algEx.start()
            algEx.wait()
        else:
            progress = SilentProgress()
            ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
            if onFinish is not None and ret:
                onFinish(alg, progress)
            QApplication.restoreOverrideCursor()
        return alg
コード例 #9
0
    def accept(self):
        checkCRS = ProcessingConfig.getSetting(
                ProcessingConfig.WARN_UNMATCHING_CRS)
        keepOpen = ProcessingConfig.getSetting(
                ProcessingConfig.KEEP_DIALOG_OPEN)
        self.showDebug = ProcessingConfig.getSetting(
                ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
        try:
            self.setParamValues()
            if checkCRS and not self.alg.checkInputCRS():
                reply = QMessageBox.question(self, "Unmatching CRS's",
                        'Layers do not all use the same CRS.\n'
                        + 'This can cause unexpected results.\n'
                        + 'Do you want to continue?',
                        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                        QtGui.QMessageBox.No)
                if reply == QtGui.QMessageBox.No:
                    return
            msg = self.alg.checkParameterValuesBeforeExecuting()
            if msg:
                QMessageBox.critical(self, 'Unable to execute algorithm', msg)
                return
            self.runButton.setEnabled(False)
            self.buttonBox.button(
                    QtGui.QDialogButtonBox.Close).setEnabled(False)
            buttons = self.paramTable.iterateButtons
            self.iterateParam = None

            for i in range(len(buttons.values())):
                button = buttons.values()[i]
                if button.isChecked():
                    self.iterateParam = buttons.keys()[i]
                    break

            self.tabWidget.setCurrentIndex(1)  # Log tab
            self.progress.setMaximum(0)
            self.progressLabel.setText('Processing algorithm...')
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

            self.setInfo('<b>Algorithm %s starting...</b>' % self.alg.name)
            if self.iterateParam:
                if UnthreadedAlgorithmExecutor.runalgIterating(self.alg,
                        self.iterateParam, self):
                    self.finish()
                else:
                    QApplication.restoreOverrideCursor()
                    if not keepOpen:
                        self.close()
                    else:
                        self.resetGUI()
            else:
                command = self.alg.getAsCommand()
                if command:
                    ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM,
                            command)
                if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
                    self.finish()
                else:
                    QApplication.restoreOverrideCursor()
                    if not keepOpen:
                        self.close()
                    else:
                        self.resetGUI()
        except AlgorithmExecutionDialog.InvalidParameterValue, ex:
            try:
                self.buttonBox.accepted.connect(lambda :
                        ex.widget.setPalette(QPalette()))
                palette = ex.widget.palette()
                palette.setColor(QPalette.Base, QColor(255, 255, 0))
                ex.widget.setPalette(palette)
                self.progressLabel.setText('<b>Missing parameter value: '
                        + ex.parameter.description + '</b>')
                return
            except:
                QMessageBox.critical(self, 'Unable to execute algorithm',
                                     'Wrong or missing parameter values')
コード例 #10
0
ファイル: Processing.py プロジェクト: pdesgagnes/QGIS
    def runAlgorithm(algOrName, onFinish, *args):
        if isinstance(algOrName, GeoAlgorithm):
            alg = algOrName
        else:
            alg = Processing.getAlgorithm(algOrName)
        if alg is None:
            print 'Error: Algorithm not found\n'
            return
        if len(args) != alg.getVisibleParametersCount() \
                    + alg.getVisibleOutputsCount():
            print 'Error: Wrong number of parameters'
            processing.alghelp(algOrName)
            return

        alg = alg.getCopy()
        if isinstance(args, dict):
            # Set params by name
            for (name, value) in args.items():
                if alg.getParameterFromName(name).setValue(value):
                    continue
                if alg.getOutputFromName(name).setValue(value):
                    continue
                print 'Error: Wrong parameter value %s for parameter %s.' \
                    % (value, name)
                return
        else:
            i = 0
            for param in alg.parameters:
                if not param.hidden:
                    if not param.setValue(args[i]):
                        print 'Error: Wrong parameter value: ' \
                            + unicode(args[i])
                        return
                    i = i + 1

            for output in alg.outputs:
                if not output.hidden:
                    if not output.setValue(args[i]):
                        print 'Error: Wrong output value: ' + unicode(args[i])
                        return
                    i = i + 1

        msg = alg.checkParameterValuesBeforeExecuting()
        if msg:
            print 'Unable to execute algorithm\n' + msg
            return

        if not alg.checkInputCRS():
            print 'Warning: Not all input layers use the same CRS.\n' \
                + 'This can cause unexpected results.'

        ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, alg.getAsCommand())

        # Don't set the wait cursor twice, because then when you
        # restore it, it will still be a wait cursor.
        cursor = QApplication.overrideCursor()
        if cursor is None or cursor == 0:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        elif cursor.shape() != Qt.WaitCursor:
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        progress = SilentProgress()
        if iface is not None :
            progress = MessageBarProgress()
        ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
        if onFinish is not None and ret:
            onFinish(alg, progress)
        QApplication.restoreOverrideCursor()
        progress.close()
        return alg
コード例 #11
0
    def accept(self):
        checkCRS = ProcessingConfig.getSetting(
            ProcessingConfig.WARN_UNMATCHING_CRS)
        keepOpen = ProcessingConfig.getSetting(
            ProcessingConfig.KEEP_DIALOG_OPEN)
        try:
            self.setParamValues()
            if checkCRS and not self.alg.checkInputCRS():
                reply = QMessageBox.question(
                    self, "Unmatching CRS's",
                    'Layers do not all use the same CRS.\n' +
                    'This can cause unexpected results.\n' +
                    'Do you want to continue?',
                    QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                    QtGui.QMessageBox.No)
                if reply == QtGui.QMessageBox.No:
                    return
            msg = self.alg.checkParameterValuesBeforeExecuting()
            if msg:
                QMessageBox.critical(self, 'Unable to execute algorithm', msg)
                return
            self.runButton.setEnabled(False)
            self.buttonBox.button(
                QtGui.QDialogButtonBox.Close).setEnabled(False)
            buttons = self.paramTable.iterateButtons
            self.iterateParam = None

            for i in range(len(buttons.values())):
                button = buttons.values()[i]
                if button.isChecked():
                    self.iterateParam = buttons.keys()[i]
                    break

            self.tabWidget.setCurrentIndex(1)  # Log tab
            self.progress.setMaximum(0)
            self.progressLabel.setText('Processing algorithm...')
            QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

            self.setInfo('<b>Algorithm %s starting...</b>' % self.alg.name)
            if self.iterateParam:
                if UnthreadedAlgorithmExecutor.runalgIterating(
                        self.alg, self.iterateParam, self):
                    self.finish()
                else:
                    QApplication.restoreOverrideCursor()
                    if not keepOpen:
                        self.close()
                    else:
                        self.resetGUI()
            else:
                command = self.alg.getAsCommand()
                if command:
                    ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM,
                                           command)
                if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
                    self.finish()
                else:
                    QApplication.restoreOverrideCursor()
                    if not keepOpen:
                        self.close()
                    else:
                        self.resetGUI()
        except AlgorithmExecutionDialog.InvalidParameterValue, ex:
            try:
                self.buttonBox.accepted.connect(
                    lambda: ex.widget.setPalette(QPalette()))
                palette = ex.widget.palette()
                palette.setColor(QPalette.Base, QColor(255, 255, 0))
                ex.widget.setPalette(palette)
                self.progressLabel.setText('<b>Missing parameter value: ' +
                                           ex.parameter.description + '</b>')
                return
            except:
                QMessageBox.critical(self, 'Unable to execute algorithm',
                                     'Wrong or missing parameter values')