Esempio n. 1
0
    def initGui(self):
        self.toolbox = SextanteToolbox(self.iface)
        self.toolbox.setVisible(False)
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

        self.toolboxAction = QAction(
            QIcon(":/sextante/images/toolbox.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"),
            self.iface.mainWindow())
        QObject.connect(self.toolboxAction, SIGNAL("triggered()"),
                        self.openToolbox)
        self.menu.addAction(self.toolboxAction)

        self.modelerAction = QAction(
            QIcon(":/sextante/images/model.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
            self.iface.mainWindow())
        QObject.connect(self.modelerAction, SIGNAL("triggered()"),
                        self.openModeler)
        self.menu.addAction(self.modelerAction)

        self.historyAction = QAction(
            QIcon(":/sextante/images/history.gif"),
            QCoreApplication.translate("SEXTANTE",
                                       "&SEXTANTE history and log"),
            self.iface.mainWindow())
        QObject.connect(self.historyAction, SIGNAL("triggered()"),
                        self.openHistory)
        self.menu.addAction(self.historyAction)

        self.configAction = QAction(
            QIcon(":/sextante/images/config.png"),
            QCoreApplication.translate("SEXTANTE",
                                       "&SEXTANTE options and configuration"),
            self.iface.mainWindow())
        QObject.connect(self.configAction, SIGNAL("triggered()"),
                        self.openConfig)
        self.menu.addAction(self.configAction)

        self.resultsAction = QAction(
            QIcon(":/sextante/images/results.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
            self.iface.mainWindow())
        QObject.connect(self.resultsAction, SIGNAL("triggered()"),
                        self.openResults)
        self.menu.addAction(self.resultsAction)

        #=======================================================================
        # self.helpAction = QAction(QIcon(":/sextante/images/help.png"),
        #    QCoreApplication.translate("SEXTANTE", "&SEXTANTE help"),
        #    self.iface.mainWindow())
        # QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
        # self.menu.addAction(self.helpAction)
        #=======================================================================

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(menuBar.actions()[-1], self.menu)
Esempio n. 2
0
    def initGui(self):

        # Create action that will start plugin configuration
        self.action = QAction(QIcon(":/plugins/wps/images/wps-add.png"),
                              "WPS-Client", self.iface.mainWindow())
        self.action.triggered.connect(self.run)

        self.actionAbout = QAction("About", self.iface.mainWindow())
        self.actionAbout.triggered.connect(self.doAbout)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action)

        if hasattr(self.iface, "addPluginToWebMenu"):
            self.iface.addPluginToWebMenu("WPS-Client", self.action)
            self.iface.addPluginToWebMenu("WPS-Client", self.actionAbout)
        else:
            self.iface.addPluginToMenu("WPS", self.action)
            self.iface.addPluginToWebMenu("WPS", self.action)

        self.myDockWidget = QgsWpsDockWidget(self.iface)
        self.myDockWidget.setWindowTitle('WPS')
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.myDockWidget)
        self.myDockWidget.show()

        if SEXTANTE_SUPPORT:
            self.provider = WpsAlgorithmProvider(self.myDockWidget)
        else:
            self.provider = None

        if self.provider:
            try:
                Sextante.addProvider(self.provider, True)  #Force tree update
            except TypeError:
                Sextante.addProvider(self.provider)
 def openCommander(self):
     if self.commander is None:
         self.commander = CommanderWindow(self.iface.mainWindow(),
                                          self.iface.mapCanvas())
         Sextante.addAlgListListener(self.commander)
     self.commander.prepareGui()
     self.commander.show()
Esempio n. 4
0
  def initGui(self):
 
    # Create action that will start plugin configuration
     self.action = QAction(QIcon(":/plugins/QgsWPSClient/images/wps-add.png"), "QgsWPSClient", self.iface.mainWindow())
     self.action.triggered.connect(self.run)
     
     self.actionAbout = QAction("About", self.iface.mainWindow())
     self.actionAbout.triggered.connect(self.doAbout)
         
    # Add toolbar button and menu item
     self.iface.addToolBarIcon(self.action)
     
     if hasattr(self.iface,  "addPluginToWebMenu"):
         self.iface.addPluginToWebMenu("QgsWPSClient", self.action)
         self.iface.addPluginToWebMenu("QgsWPSClient", self.actionAbout)
     else:
         self.iface.addPluginToMenu("QgsWPSClient", self.action)
         self.iface.addPluginToWebMenu("QgsWPSClient", self.action)

     
     self.myDockWidget = QgsWpsDockWidget(self.iface)
     self.myDockWidget.setWindowTitle('QgsWPSClient-'+version())
     self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.myDockWidget)
     self.myDockWidget.show()

     if SEXTANTE_SUPPORT:
         self.provider = WpsAlgorithmProvider(self.myDockWidget)
     else:
         self.provider = None

     if self.provider:
        try:
            Sextante.addProvider(self.provider, True) #Force tree update
        except TypeError:
            Sextante.addProvider(self.provider)
Esempio n. 5
0
    def initGui(self):
        self.toolbox = SextanteToolbox(self.iface)
        self.toolbox.setVisible(False)
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle("Analysis")

        icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png")
        self.toolboxAction = QAction(icon, \
            "&SEXTANTE Toolbox", self.iface.mainWindow())
        QObject.connect(self.toolboxAction, SIGNAL("triggered()"),
                        self.openToolbox)
        self.menu.addAction(self.toolboxAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/model.png")
        self.modelerAction = QAction(icon, \
            "&SEXTANTE Modeler", self.iface.mainWindow())
        QObject.connect(self.modelerAction, SIGNAL("triggered()"),
                        self.openModeler)
        self.menu.addAction(self.modelerAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/history.gif")
        self.historyAction = QAction(icon, \
            "&SEXTANTE History and log", self.iface.mainWindow())
        QObject.connect(self.historyAction, SIGNAL("triggered()"),
                        self.openHistory)
        self.menu.addAction(self.historyAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/config.png")
        self.configAction = QAction(icon, \
            "&SEXTANTE options and configuration", self.iface.mainWindow())
        QObject.connect(self.configAction, SIGNAL("triggered()"),
                        self.openConfig)
        self.menu.addAction(self.configAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/results.png")
        self.resultsAction = QAction(icon, \
            "&SEXTANTE results viewer", self.iface.mainWindow())
        QObject.connect(self.resultsAction, SIGNAL("triggered()"),
                        self.openResults)
        self.menu.addAction(self.resultsAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/help.png")
        self.helpAction = QAction(icon, \
            "&SEXTANTE help", self.iface.mainWindow())
        QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
        self.menu.addAction(self.helpAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/info.png")
        self.aboutAction = QAction(icon, \
            "&About SEXTANTE", self.iface.mainWindow())
        QObject.connect(self.aboutAction, SIGNAL("triggered()"),
                        self.openAbout)
        self.menu.addAction(self.aboutAction)

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(menuBar.actions()[-1], self.menu)
Esempio n. 6
0
    def initGui(self):
        self.toolbox = SextanteToolbox(self.iface)
        self.toolbox.setVisible(False)
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

        self.toolboxAction = QAction(
            QIcon(":/sextante/images/toolbox.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.toolboxAction, SIGNAL("triggered()"), self.openToolbox)
        self.menu.addAction(self.toolboxAction)

        self.modelerAction = QAction(
            QIcon(":/sextante/images/model.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.modelerAction, SIGNAL("triggered()"), self.openModeler)
        self.menu.addAction(self.modelerAction)

        self.historyAction = QAction(
            QIcon(":/sextante/images/history.gif"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE history and log"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory)
        self.menu.addAction(self.historyAction)

        self.configAction = QAction(
            QIcon(":/sextante/images/config.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE options and configuration"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig)
        self.menu.addAction(self.configAction)

        self.resultsAction = QAction(
            QIcon(":/sextante/images/results.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults)
        self.menu.addAction(self.resultsAction)

        self.helpAction = QAction(
            QIcon(":/sextante/images/help.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE help"),
            self.iface.mainWindow(),
        )
        QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
        self.menu.addAction(self.helpAction)

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(menuBar.actions()[-1], self.menu)
Esempio n. 7
0
def createTest(text):
    s = ""
    tokens =  text[len("sextante.runalg("):-1].split(",")
    cmdname = tokens[0][1:-1];
    methodname = "test_" + cmdname.replace(":","")
    s += "def " + methodname + "(self):\n"
    alg = Sextante.getAlgorithm(cmdname)
    execcommand = "sextante.runalg("
    i = 0
    for token in tokens:
        if i < alg.getVisibleParametersCount() + 1:                            
            if os.path.exists(token[1:-1]):
                token = os.path.basename(token[1:-1])[:-4]           
            execcommand += token + "(),"
        else:
            execcommand += "None,"
        i+=1
    s += "\toutputs=" + execcommand[:-1] + ")\n"

    i = -1 * len(alg.outputs)
    for out in alg.outputs:        
        filename = tokens[i][1:-1]
        if (filename == str(None)):
            raise Exception("Cannot create unit test for that algorithm execution.\nThe output cannot be a temporary file")        
        s+="\toutput=outputs['" + out.name + "']\n"
        if isinstance(out, (OutputNumber, OutputString)):
            s+="self.assertTrue(" + str(out) + ", output)\n"
        if isinstance(out, OutputRaster):
            dataset = gdal.Open(filename, GA_ReadOnly)
            array = dataset.ReadAsArray(1)
            s+="\tself.assertTrue(os.path.isfile(output))\n"
            s+="\tself.assertEqual(hashraster(output)," + str(hash(array)) + ")\n"
        if isinstance(out, OutputVector):
            layer = Sextante.getObject(filename)
            fields = layer.pendingFields()
            s+="\tlayer=QGisLayers.getObjectFromUri(output, True)\n"
            s+="\tfields=layer.pendingFields()\n"
            s+="\texpectednames=[" + ",".join(["'" + str(f.name()) + "'" for f in fields]) + "]\n"
            s+="\texpectedtypes=[" + ",".join(["'" + str(f.typeName()) +"'" for f in fields]) + "]\n"
            s+="\tnames=[str(f.name()) for f in fields]\n"
            s+="\ttypes=[str(f.typeName()) for f in fields]\n"
            s+="\tself.assertEqual(expectednames, names)\n"
            s+="\tself.assertEqual(expectedtypes, types)\n"
            features = QGisLayers.features(layer)
            numfeat = len(features)
            s+="\tfeatures=sextante.getfeatures(layer)\n"
            s+="\tself.assertEqual(" + str(numfeat) + ", len(features))\n"
            if numfeat > 0:
                feature = features.next()
                attrs = feature.attributes()
                s+="\tfeature=features.next()\n"
                s+="\tattrs=feature.attributes()\n"
                s+="\texpectedvalues=[" + ",".join(['"' + str(attr.toString()) + '"' for attr in attrs]) + "]\n"
                s+="\tvalues=[str(attr.toString()) for attr in attrs]\n"
                s+="\tself.assertEqual(expectedvalues, values)\n"

    dlg = ShowTestDialog(s)
    dlg.exec_()
    def initGui(self):
        self.commander = None
        self.toolbox = SextanteToolbox(self.iface)
        self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
        self.toolbox.hide()
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

        self.toolboxAction = self.toolbox.toggleViewAction()
        self.toolboxAction.setIcon(QIcon(":/sextante/images/toolbox.png"))
        self.toolboxAction.setText(
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"))
        self.menu.addAction(self.toolboxAction)

        self.modelerAction = QAction(
            QIcon(":/sextante/images/model.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
            self.iface.mainWindow())
        self.modelerAction.triggered.connect(self.openModeler)
        self.menu.addAction(self.modelerAction)

        self.historyAction = QAction(
            QIcon(":/sextante/images/history.gif"),
            QCoreApplication.translate("SEXTANTE",
                                       "&SEXTANTE history and log"),
            self.iface.mainWindow())
        self.historyAction.triggered.connect(self.openHistory)
        self.menu.addAction(self.historyAction)

        self.configAction = QAction(
            QIcon(":/sextante/images/config.png"),
            QCoreApplication.translate("SEXTANTE",
                                       "&SEXTANTE options and configuration"),
            self.iface.mainWindow())
        self.configAction.triggered.connect(self.openConfig)
        self.menu.addAction(self.configAction)

        self.resultsAction = QAction(
            QIcon(":/sextante/images/results.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
            self.iface.mainWindow())
        self.resultsAction.triggered.connect(self.openResults)
        self.menu.addAction(self.resultsAction)

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(self.iface.firstRightStandardMenu().menuAction(),
                           self.menu)

        self.commanderAction = QAction(
            QIcon(":/sextante/images/toolbox.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE commander"),
            self.iface.mainWindow())
        self.commanderAction.triggered.connect(self.openCommander)
        self.menu.addAction(self.commanderAction)
        self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")
Esempio n. 9
0
    def fillTreeUsingProviders(self):
        self.algorithmTree.clear()
        text = unicode(self.searchBox.text())
        for providerName in Sextante.algs.keys():
            groups = {}
            provider = Sextante.algs[providerName]
            name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
            if not SextanteConfig.getSetting(name):
                continue
            algs = provider.values()
            # add algorithms
            for alg in algs:
                if not alg.showInToolbox:
                    continue
                if text == "" or text.lower() in alg.name.lower():
                    if alg.group in groups:
                        groupItem = groups[alg.group]
                    else:
                        groupItem = QTreeWidgetItem()
                        groupItem.setText(0, alg.group)
                        groupItem.setToolTip(0, alg.group)
                        groups[alg.group] = groupItem
                    algItem = TreeAlgorithmItem(alg)
                    groupItem.addChild(algItem)

            actions = Sextante.actions[providerName]
            for action in actions:
                if text == "" or text.lower() in action.name.lower():
                    if action.group in groups:
                        groupItem = groups[action.group]
                    else:
                        groupItem = QTreeWidgetItem()
                        groupItem.setText(0, action.group)
                        groups[action.group] = groupItem
                    algItem = TreeActionItem(action)
                    groupItem.addChild(algItem)

            if len(groups) > 0:
                providerItem = QTreeWidgetItem()
                providerItem.setText(
                    0,
                    Sextante.getProviderFromName(providerName).getDescription()
                    + " ["
                    + str(len(provider))
                    + " geoalgorithms]",
                )
                providerItem.setIcon(0, Sextante.getProviderFromName(providerName).getIcon())
                providerItem.setToolTip(0, providerItem.text(0))
                for groupItem in groups.values():
                    providerItem.addChild(groupItem)
                self.algorithmTree.addTopLevelItem(providerItem)
                providerItem.setExpanded(text != "")
                for groupItem in groups.values():
                    groupItem.setExpanded(text != "")
Esempio n. 10
0
    def fillTreeUsingProviders(self):
        self.algorithmTree.clear()
        text = unicode(self.searchBox.text())
        for providerName in Sextante.algs.keys():
            groups = {}
            provider = Sextante.algs[providerName]
            name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
            if not SextanteConfig.getSetting(name):
                continue
            algs = provider.values()
            #add algorithms
            for alg in algs:
                if not alg.showInToolbox:
                    continue
                if text == "" or text.lower() in alg.name.lower():
                    if alg.group in groups:
                        groupItem = groups[alg.group]
                    else:
                        groupItem = QTreeWidgetItem()
                        groupItem.setText(0, alg.group)
                        groupItem.setToolTip(0, alg.group)
                        groups[alg.group] = groupItem
                    algItem = TreeAlgorithmItem(alg)
                    groupItem.addChild(algItem)

            actions = Sextante.actions[providerName]
            for action in actions:
                if text == "" or text.lower() in action.name.lower():
                    if action.group in groups:
                        groupItem = groups[action.group]
                    else:
                        groupItem = QTreeWidgetItem()
                        groupItem.setText(0, action.group)
                        groups[action.group] = groupItem
                    algItem = TreeActionItem(action)
                    groupItem.addChild(algItem)

            if len(groups) > 0:
                providerItem = QTreeWidgetItem()
                providerItem.setText(
                    0,
                    Sextante.getProviderFromName(
                        providerName).getDescription() + " [" +
                    str(len(provider)) + " geoalgorithms]")
                providerItem.setIcon(
                    0,
                    Sextante.getProviderFromName(providerName).getIcon())
                providerItem.setToolTip(0, providerItem.text(0))
                for groupItem in groups.values():
                    providerItem.addChild(groupItem)
                self.algorithmTree.addTopLevelItem(providerItem)
                providerItem.setExpanded(text != "")
                for groupItem in groups.values():
                    groupItem.setExpanded(text != "")
Esempio n. 11
0
def createTest(item):            
    s = ""                
    tokens = item.entry.text[len("sextante.runalg("):-1].split(",")                
    cmdname = tokens[0][1:-1];
    methodname = "test_" + cmdname.replace(":","")
    s += "def " + methodname + "():\n"
    alg = Sextante.getAlgorithm(cmdname)
    execcommand = "sextante.runalg("
    i = 0
    for token in tokens:
        if i < alg.getVisibleParametersCount():
            execcommand+=token + ","
        else:
            execcommand+="None,"
        i+=1                
    s += "\toutputs=" + execcommand[:-1] + ")\n"
                
    i = -1 * len(alg.outputs)
    for out in alg.outputs:
        filename = tokens[i][1:-1]                    
        s+="\toutput=outputs['" + out.name + "']\n"
        if isinstance(out, (OutputNumber, OutputString)):
            s+="self.assertTrue(" + str(out) + ", output)\n"
        if isinstance(out, OutputRaster):                   
            dataset = gdal.Open(filename, GA_ReadOnly)
            array = dataset.ReadAsArray(1)
            s+="\tself.assertTrue(os.path.isfile(output))\n"
            s+="\tself.assertEqual(hashraster(output)," + str(hash(array)) + ")\n"
        if isinstance(out, OutputVector):
            layer = Sextante.getObject(filename)
            fields = layer.pendingFields()
            s+="\tlayer=sextante.getobject(output)\n"
            s+="\tfields=layer.pendingFields()\n"
            s+="\texpectednames=[" + ",".join([str(f.name()) for f in fields]) + "]\n"
            s+="\texpectedtypes=[" + ",".join([str(f.typeName()) for f in fields]) + "]\n"
            s+="\tnames=[str(f.name()) for f in fields]\n"
            s+="\ttypes=[str(f.typeName()) for f in fields]\n"
            s+="\tself.assertEqual(exceptednames, names)\n"
            s+="\tself.assertEqual(exceptedtypes, types)\n"
            features = QGisLayers.features(layer)
            numfeat = len(features)
            s+="\tfeatures=sextante.getfeatures(layer))\n"
            s+="\tself.assertEqual(" + str(numfeat) + ", len(features)\n"
            if numfeat > 0:
                feature = features.next()
                attrs = feature.attributes()
                s+="\tfeature=features.next()\n"
                s+="\tattrs=feature.attributes()\n"
                s+="\texpectedvalues=[" + ",".join([str(attr.toString()) for attr in attrs]) + "]\n"
                s+="\tvalues=[str(attr.toString()) for attr in attrs]\n"
                s+="\tself.assertEqual(exceptedtypes, types)\n"
    
    dlg = ShowTestDialog(s)
    dlg.exec_()
Esempio n. 12
0
    def initGui(self):
        self.toolbox = SextanteToolbox(self.iface)
        self.toolbox.setVisible(False)
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle("Analysis")

        icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png")
        self.toolboxAction = QAction(icon, \
            "&SEXTANTE Toolbox", self.iface.mainWindow())
        QObject.connect(self.toolboxAction, SIGNAL("triggered()"), self.openToolbox)
        self.menu.addAction(self.toolboxAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/model.png")
        self.modelerAction = QAction(icon, \
            "&SEXTANTE Modeler", self.iface.mainWindow())
        QObject.connect(self.modelerAction, SIGNAL("triggered()"), self.openModeler)
        self.menu.addAction(self.modelerAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/history.gif")
        self.historyAction = QAction(icon, \
            "&SEXTANTE History and log", self.iface.mainWindow())
        QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory)
        self.menu.addAction(self.historyAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/config.png")
        self.configAction = QAction(icon, \
            "&SEXTANTE options and configuration", self.iface.mainWindow())
        QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig)
        self.menu.addAction(self.configAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/results.png")
        self.resultsAction = QAction(icon, \
            "&SEXTANTE results viewer", self.iface.mainWindow())
        QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults)
        self.menu.addAction(self.resultsAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/help.png")
        self.helpAction = QAction(icon, \
            "&SEXTANTE help", self.iface.mainWindow())
        QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
        self.menu.addAction(self.helpAction)

        icon = QIcon(os.path.dirname(__file__) + "/images/info.png")
        self.aboutAction = QAction(icon, \
            "&About SEXTANTE", self.iface.mainWindow())
        QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.openAbout)
        self.menu.addAction(self.aboutAction)

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(menuBar.actions()[-1], self.menu)
Esempio n. 13
0
    def initGui(self):
        self.commander = None
        self.toolbox = SextanteToolbox(self.iface)
        self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
        self.toolbox.hide()
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

        self.toolboxAction = self.toolbox.toggleViewAction()
        self.toolboxAction.setIcon(QIcon(":/sextante/images/toolbox.png"))
        self.toolboxAction.setText(QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"))
        self.menu.addAction(self.toolboxAction)

        self.modelerAction = QAction(QIcon(":/sextante/images/model.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
            self.iface.mainWindow())
        self.modelerAction.triggered.connect(self.openModeler)
        self.menu.addAction(self.modelerAction)

        self.historyAction = QAction(QIcon(":/sextante/images/history.gif"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE history and log"),
            self.iface.mainWindow())
        self.historyAction.triggered.connect(self.openHistory)
        self.menu.addAction(self.historyAction)

        self.configAction = QAction(QIcon(":/sextante/images/config.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE options and configuration"),
            self.iface.mainWindow())
        self.configAction.triggered.connect(self.openConfig)
        self.menu.addAction(self.configAction)

        self.resultsAction = QAction(QIcon(":/sextante/images/results.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
            self.iface.mainWindow())
        self.resultsAction.triggered.connect(self.openResults)
        self.menu.addAction(self.resultsAction)

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(self.iface.firstRightStandardMenu().menuAction(), self.menu)

        self.commanderAction = QAction(QIcon(":/sextante/images/toolbox.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE commander"),
            self.iface.mainWindow())
        self.commanderAction.triggered.connect(self.openCommander)
        self.menu.addAction(self.commanderAction)
        self.iface.registerMainWindowAction(self.commanderAction, "Ctrl+Alt+M")
Esempio n. 14
0
    def initGui(self):
        self.toolbox = SextanteToolbox(self.iface)
        self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
        self.toolbox.hide()
        Sextante.addAlgListListener(self.toolbox)

        self.menu = QMenu(self.iface.mainWindow())
        self.menu.setTitle(QCoreApplication.translate("SEXTANTE", "Analysis"))

        self.toolboxAction = self.toolbox.toggleViewAction()
        self.toolboxAction.setIcon(QIcon(":/sextante/images/toolbox.png"))
        self.toolboxAction.setText(QCoreApplication.translate("SEXTANTE", "&SEXTANTE toolbox"))
        self.menu.addAction(self.toolboxAction)

        self.modelerAction = QAction(QIcon(":/sextante/images/model.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE modeler"),
            self.iface.mainWindow())
        self.modelerAction.triggered.connect(self.openModeler)
        self.menu.addAction(self.modelerAction)

        self.historyAction = QAction(QIcon(":/sextante/images/history.gif"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE history and log"),
            self.iface.mainWindow())
        self.historyAction.triggered.connect(self.openHistory)
        self.menu.addAction(self.historyAction)

        self.configAction = QAction(QIcon(":/sextante/images/config.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE options and configuration"),
            self.iface.mainWindow())
        self.configAction.triggered.connect(self.openConfig)
        self.menu.addAction(self.configAction)

        self.resultsAction = QAction(QIcon(":/sextante/images/results.png"),
            QCoreApplication.translate("SEXTANTE", "&SEXTANTE results viewer"),
            self.iface.mainWindow())
        self.resultsAction.triggered.connect(self.openResults)
        self.menu.addAction(self.resultsAction)

        #=======================================================================
        # self.helpAction = QAction(QIcon(":/sextante/images/help.png"),
        #    QCoreApplication.translate("SEXTANTE", "&SEXTANTE help"),
        #    self.iface.mainWindow())
        # self.helpAction.triggered.connect(self.openHelp)
        # self.menu.addAction(self.helpAction)
        #=======================================================================

        menuBar = self.iface.mainWindow().menuBar()
        menuBar.insertMenu(menuBar.actions()[-1], self.menu)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()
		savename = self.getOutputValue(self.SAVENAME)

		index = self.getParameterValue(self.NEWTYPE)

		splitnodes = 0
		if index == 0:
			newtype = QGis.WKBPoint
		elif index == 1:
			newtype = QGis.WKBPoint
			splitnodes = 1
		elif index == 2:
			newtype = QGis.WKBLineString
		elif index == 3:
			newtype = QGis.WKBMultiLineString
		elif index == 4:
			newtype = QGis.WKBPolygon
		else:
			newtype = QGis.WKBPoint

		message = mmqgisx_geometry_convert(qgis, layername, newtype, splitnodes, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		outfilename = self.getOutputValue(self.OUTFILENAME)
		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()

		if self.getParameterValue(self.FIELDDELIMITER) == 1:
			field_delimiter = "|"
		elif self.getParameterValue(self.FIELDDELIMITER) == 2:
			field_delimiter = " "
		else:
			field_delimiter = ","

		if self.getParameterValue(self.LINETERMINATOR) == 1:
			line_terminator = "\n"
		else:
			line_terminator = "\r\n"

		message = mmqgisx_attribute_export(qgis, outfilename, layername, None, 
			field_delimiter, line_terminator)

		if message:
			raise GeoAlgorithmExecutionException(message)
Esempio n. 17
0
def alghelp(name):
    alg = Sextante.getAlgorithm(name)
    if alg != None:
        print(str(alg))
        algoptions(name)
    else:
        print "Algorithm not found"
Esempio n. 18
0
    def processAlgorithm(self, progress):
        '''Here is where the processing itself takes place'''

        #the first thing to do is retrieve the values of the parameters
        #entered by the user
        inputFilename = self.getParameterValue(self.INPUT_LAYER)
        output = self.getOutputValue(self.OUTPUT_LAYER)

        #input layers values are always a string with its location.
        #That string can be converted into a QGIS object (a QgsVectorLayer in this case))
        #using the Sextante.getObject() method
        vectorLayer = Sextante.getObject(inputFilename)

        #And now we can process

        #First we create the output layer.
        #The output value entered by the user is a string containing a filename,
        #so we can use it directly
        settings = QSettings()
        systemEncoding = settings.value("/UI/encoding", "System").toString()
        provider = vectorLayer.dataProvider()
        writer = QgsVectorFileWriter(output, systemEncoding, provider.fields(),
                                     provider.geometryType(), provider.crs())

        #Now we take the selected features and add them to the output layer
        selection = vectorLayer.selectedFeatures()
        for feat in selection:
            writer.addFeature(feat)
        del writer
Esempio n. 19
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante

        qgis = Sextante.getInterface()

        table = QGisLayers.getObjectFromUri(self.getParameterValue(self.CSVNAME))
        csvname = table.name()

        params = [
            self.getParameterValue(self.ADDRESS),
            self.getParameterValue(self.CITY),
            self.getParameterValue(self.STATE),
            self.getParameterValue(self.COUNTRY),
        ]

        keys = []
        for param in params:
            if not (param in keys):
                keys.append(param)

        shapefilename = self.getOutputValue(self.SHAPEFILENAME)
        notfoundfile = self.getOutputValue(self.NOTFOUNDFILE)

        message = mmqgisx_geocode_google(qgis, csvname, shapefilename, notfoundfile, keys, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 20
0
    def processAlgorithm(self, progress):
        '''Here is where the processing itself takes place'''

        #the first thing to do is retrieve the values of the parameters
        #entered by the user
        inputFilename = self.getParameterValue(self.INPUT_LAYER)
        output = self.getOutputValue(self.OUTPUT_LAYER)

        #input layers values are always a string with its location.
        #That string can be converted into a QGIS object (a QgsVectorLayer in this case))
        #using the Sextante.getObject() method
        vectorLayer = Sextante.getObject(inputFilename)

        #And now we can process

        #First we create the output layer.
        #The output value entered by the user is a string containing a filename,
        #so we can use it directly
        settings = QSettings()
        systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
        provider = vectorLayer.dataProvider()
        writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), provider.geometryType(), provider.crs() )

        #Now we take the selected features and add them to the output layer
        selection = vectorLayer.selectedFeatures()
        for feat in selection:
            writer.addFeature(feat)
        del writer
Esempio n. 21
0
    def addRecentAlgorithms(self, updating):
        showRecent = SextanteConfig.getSetting(
            SextanteConfig.SHOW_RECENT_ALGORITHMS)
        if showRecent:
            recent = SextanteLog.getRecentAlgorithms()
            if len(recent) != 0:
                found = False
                if updating:
                    recentItem = self.algorithmTree.topLevelItem(0)
                    treeWidget = recentItem.treeWidget()
                    treeWidget.takeTopLevelItem(
                        treeWidget.indexOfTopLevelItem(recentItem))
                    #self.algorithmTree.removeItemWidget(first, 0)

                recentItem = QTreeWidgetItem()
                recentItem.setText(0, self.tr("Recently used algorithms"))
                for algname in recent:
                    alg = Sextante.getAlgorithm(algname)
                    if alg is not None:
                        algItem = TreeAlgorithmItem(alg)
                        recentItem.addChild(algItem)
                        found = True
                if found:
                    self.algorithmTree.insertTopLevelItem(0, recentItem)
                    recentItem.setExpanded(True)

            self.algorithmTree.setWordWrap(True)
Esempio n. 22
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        table = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.CSVNAME))
        csvname = table.name()

        params = [
            self.getParameterValue(self.ADDRESS),
            self.getParameterValue(self.CITY),
            self.getParameterValue(self.STATE),
            self.getParameterValue(self.COUNTRY)
        ]

        keys = []
        for param in params:
            if not (param in keys):
                keys.append(param)

        shapefilename = self.getOutputValue(self.SHAPEFILENAME)
        notfoundfile = self.getOutputValue(self.NOTFOUNDFILE)

        message = mmqgisx_geocode_google(qgis, csvname, shapefilename,
                                         notfoundfile, keys, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 23
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()

        table = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.INFILENAME))
        infilename = table.name()

        joinfield = self.getParameterValue(self.JOINFIELD)
        joinattribute = self.getParameterValue(self.JOINATTRIBUTE)

        outfilename = self.getOutputValue(self.OUTFILENAME)
        notfoundname = self.getOutputValue(self.NOTFOUNDNAME)

        message = mmqgisx_attribute_join(qgis, layername, infilename,
                                         joinfield, joinattribute, outfilename,
                                         notfoundname, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 24
0
    def fillTree(self):
        useCategories = SextanteConfig.getSetting(SextanteConfig.USE_CATEGORIES)
        if useCategories:
            self.fillTreeUsingCategories()
        else:
            self.fillTreeUsingProviders()

        self.algorithmTree.sortItems(0, Qt.AscendingOrder)

        showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
        if showRecent:
            recent = SextanteLog.getRecentAlgorithms()
            if len(recent) != 0:
                found = False
                recentItem = QTreeWidgetItem()
                recentItem.setText(0, self.tr("Recently used algorithms"))
                for algname in recent:
                    alg = Sextante.getAlgorithm(algname)
                    if alg is not None:
                        algItem = TreeAlgorithmItem(alg)
                        recentItem.addChild(algItem)
                        found = True
                if found:
                    self.algorithmTree.insertTopLevelItem(0, recentItem)
                    recentItem.setExpanded(True)

            self.algorithmTree.setWordWrap(True)
Esempio n. 25
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()

        node_filename = self.getOutputValue(self.NODEFILENAME)
        attribute_filename = self.getOutputValue(self.ATTRIBUTEFILENAME)
        print "Layer: " + str(layername)
        print "Nodes: " + str(node_filename)
        print "Attributes: " + str(attribute_filename)

        if self.getParameterValue(self.FIELDDELIMITER) == 1:
            field_delimiter = "|"
        elif self.getParameterValue(self.FIELDDELIMITER) == 2:
            field_delimiter = " "
        else:
            field_delimiter = ","

        if self.getParameterValue(self.LINETERMINATOR) == 1:
            line_terminator = "\n"
        else:
            line_terminator = "\r\n"

        message = mmqgisx_geometry_export_to_csv(qgis, layername,
                                                 node_filename,
                                                 attribute_filename,
                                                 field_delimiter,
                                                 line_terminator)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 26
0
 def executeAlgorithm(self):
     item = self.algorithmTree.currentItem()
     if isinstance(item, TreeAlgorithmItem):
         alg = Sextante.getAlgorithm(item.alg.commandLineName())
         message = alg.checkBeforeOpeningParametersDialog()
         if message:
             dlg = MissingDependencyDialog(message)
             dlg.exec_()
             #QMessageBox.warning(self, self.tr("Warning"), message)
             return
         alg = alg.getCopy()
         dlg = alg.getCustomParametersDialog()
         if not dlg:
             dlg = ParametersDialog(alg)
         canvas = QGisLayers.iface.mapCanvas()
         prevMapTool = canvas.mapTool()
         dlg.show()
         dlg.exec_()
         if canvas.mapTool()!=prevMapTool:
             try:
                 canvas.mapTool().reset()
             except:
                 pass
             canvas.setMapTool(prevMapTool)
         if dlg.executed:
             showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
             if showRecent:
                 self.addRecentAlgorithms(True)
     if isinstance(item, TreeActionItem):
         action = item.action
         action.setData(self)
         action.execute()
Esempio n. 27
0
 def executeAlgorithm(self):
     item = self.algorithmTree.currentItem()
     if isinstance(item, TreeAlgorithmItem):
         alg = Sextante.getAlgorithm(item.alg.commandLineName())
         message = alg.checkBeforeOpeningParametersDialog()
         if message:
             QtGui.QMessageBox.warning(self, "Warning", message)
             return
         alg = alg.getCopy()  #copy.deepcopy(alg)
         dlg = alg.getCustomParametersDialog()
         if not dlg:
             dlg = ParametersDialog(alg)
         canvas = QGisLayers.iface.mapCanvas()
         prevMapTool = canvas.mapTool()
         dlg.show()
         dlg.exec_()
         if canvas.mapTool() != prevMapTool:
             try:
                 canvas.mapTool().reset()
             except:
                 pass
             canvas.setMapTool(prevMapTool)
         if dlg.executed:
             showRecent = SextanteConfig.getSetting(
                 SextanteConfig.SHOW_RECENT_ALGORITHMS)
             if showRecent:
                 self.fillTree()
     if isinstance(item, TreeActionItem):
         action = item.action
         action.setData(self)
         action.execute()
Esempio n. 28
0
    def addRecentAlgorithms(self, updating):
        showRecent = SextanteConfig.getSetting(SextanteConfig.SHOW_RECENT_ALGORITHMS)
        if showRecent:
            recent = SextanteLog.getRecentAlgorithms()
            if len(recent) != 0:
                found = False
                if updating:
                    recentItem = self.algorithmTree.topLevelItem(0)
                    treeWidget = recentItem.treeWidget()
                    treeWidget.takeTopLevelItem(treeWidget.indexOfTopLevelItem(recentItem))
                    #self.algorithmTree.removeItemWidget(first, 0)

                recentItem = QTreeWidgetItem()
                recentItem.setText(0, self.tr("Recently used algorithms"))
                for algname in recent:
                    alg = Sextante.getAlgorithm(algname)
                    if alg is not None:
                        algItem = TreeAlgorithmItem(alg)
                        recentItem.addChild(algItem)
                        found = True
                if found:
                    self.algorithmTree.insertTopLevelItem(0, recentItem)
                    recentItem.setExpanded(True)

            self.algorithmTree.setWordWrap(True)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()

		node_filename = self.getOutputValue(self.NODEFILENAME)
		attribute_filename = self.getOutputValue(self.ATTRIBUTEFILENAME)
		print "Layer: " + str(layername)
		print "Nodes: " + str(node_filename)
		print "Attributes: " + str(attribute_filename)

		if self.getParameterValue(self.FIELDDELIMITER) == 1:
			field_delimiter = "|"
		elif self.getParameterValue(self.FIELDDELIMITER) == 2:
			field_delimiter = " "
		else:
			field_delimiter = ","

		if self.getParameterValue(self.LINETERMINATOR) == 1:
			line_terminator = "\n"
		else:
			line_terminator = "\r\n"

		message = mmqgisx_geometry_export_to_csv(qgis, layername, node_filename, attribute_filename,
			field_delimiter, line_terminator)

		if message:
			raise GeoAlgorithmExecutionException(message)
def alghelp(name):
    alg = Sextante.getAlgorithm(name)
    if alg != None:
        print(str(alg))
        algoptions(name)
    else:
        print "Algorithm not found"
Esempio n. 31
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        outfilename = self.getOutputValue(self.OUTFILENAME)
        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()

        if self.getParameterValue(self.FIELDDELIMITER) == 1:
            field_delimiter = "|"
        elif self.getParameterValue(self.FIELDDELIMITER) == 2:
            field_delimiter = " "
        else:
            field_delimiter = ","

        if self.getParameterValue(self.LINETERMINATOR) == 1:
            line_terminator = "\n"
        else:
            line_terminator = "\r\n"

        message = mmqgisx_attribute_export(qgis, outfilename, layername, None,
                                           field_delimiter, line_terminator)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 32
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()
        savename = self.getOutputValue(self.SAVENAME)

        index = self.getParameterValue(self.NEWTYPE)

        splitnodes = 0
        if index == 0:
            newtype = QGis.WKBPoint
        elif index == 1:
            newtype = QGis.WKBPoint
            splitnodes = 1
        elif index == 2:
            newtype = QGis.WKBLineString
        elif index == 3:
            newtype = QGis.WKBMultiLineString
        elif index == 4:
            newtype = QGis.WKBPolygon
        else:
            newtype = QGis.WKBPoint

        message = mmqgisx_geometry_convert(qgis, layername, newtype,
                                           splitnodes, savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 33
0
  def unload(self):
     if hasattr(self.iface,  "addPluginToWebMenu"):
         self.iface.removePluginWebMenu("QgsWPSClient", self.action)
         self.iface.removePluginWebMenu("QgsWPSClient", self.actionAbout)
     else:
         self.iface.removePluginToMenu("QgsWPSClient", self.action)      
         self.iface.removePluginToMenu("QgsWPSClient", self.actionAbout)
         
     self.iface.removeToolBarIcon(self.action)
    
     if self.myDockWidget:
         self.myDockWidget.close()
        
     self.myDockWidget = None

     if self.provider:
        Sextante.removeProvider(self.provider)
Esempio n. 34
0
    def unload(self):
        if hasattr(self.iface, "addPluginToWebMenu"):
            self.iface.removePluginWebMenu("WPS-Client", self.action)
            self.iface.removePluginWebMenu("WPS-Client", self.actionAbout)
        else:
            self.iface.removePluginToMenu("WPS", self.action)
            self.iface.removePluginToMenu("WPS", self.actionAbout)

        self.iface.removeToolBarIcon(self.action)

        if self.myDockWidget:
            self.myDockWidget.close()

        self.myDockWidget = None

        if self.provider:
            Sextante.removeProvider(self.provider)
Esempio n. 35
0
def testAlg(algname, *args):

    #test simple execution
    alg = Sextante.runAlgorithm(algname, None, *args)
    assert alg is not None

    out = alg.getOutputValuesAsDictionary()

    return out
Esempio n. 36
0
 def runalg_none(self):
     result = Sextante.runalg(self.alg, *self.args)
     print bcolors.ENDC
     self.assertIsNotNone(result, self.msg)
     if not result:
         return
     for p in result.values():
         if isinstance(p, str):
             self.assertTrue(os.path.exists(p), "Output %s exists" % p)
Esempio n. 37
0
 def setSessionProjectionFromProject(self, commands):
     if not GrassUtils.projectionSet:
         from sextante.core.Sextante import Sextante
         qgis = Sextante.getInterface()
         proj4 = qgis.mapCanvas().mapRenderer().destinationCrs().toProj4()
         command = "g.proj"
         command +=" -c"
         command +=" proj4=\""+proj4+"\""
         commands.append(command)
         GrassUtils.projectionSet = True
Esempio n. 38
0
 def setSessionProjectionFromProject(self, commands):
     if not GrassUtils.projectionSet:
         from sextante.core.Sextante import Sextante
         qgis = Sextante.getInterface()
         proj4 = qgis.mapCanvas().mapRenderer().destinationCrs().toProj4()
         command = "g.proj"
         command += " -c"
         command += " proj4=\"" + proj4 + "\""
         commands.append(command)
         GrassUtils.projectionSet = True
    def processAlgorithm(self, progress):
        # get the lib
        liblwgeom = self.getLwgeomLibrary()

        # retrieve the values of the parameters entered by the user
        inputFilename = self.getParameterValue(self.INPUT_LAYER)
        output = self.getOutputValue(self.OUTPUT_LAYER)

        # input layers vales are always a string with its location.
        # That string can be converted into a QGIS object (a QgsVectorLayer in this case))
        # using the Sextante.getObject() method
        inputLayer = Sextante.getObject(inputFilename)

        # create the output layer
        provider = inputLayer.dataProvider()
        encoding = provider.encoding()
        geomType = self.inputToOutputGeomType(inputLayer)
        writer = QgsVectorFileWriter( output, encoding, provider.fields(), geomType, provider.crs() )

        # Now we take the features and add them to the output layer, 
        # first check for selected features
        selection = inputLayer.selectedFeatures()
        if len(selection) > 0:
            count = len(selection)
            idx = 0

            for feat in selection:
                # run lwgeom algorithm on the feature geometry
                if not self.runLwgeom( feat.geometry(), lib=liblwgeom ):
                    SextanteLog.addToLog( SextanteLog.LOG_ERROR, u"FAILURE: previous failure info: layer %s, feature #%s" % (inputLayer.source(), feat.id()) )
                writer.addFeature(feat)

                progress.setPercentage( idx*100/count )
                idx += 1

        else:
            count = inputLayer.featureCount()
            idx = 0

            # no features selected on the layer, process all the features
            inputLayer.select( inputLayer.pendingAllAttributesList(), QgsRectangle(), True )
            feat = QgsFeature()
            while inputLayer.nextFeature( feat ):
                # run lwgeom algorithm on the feature geometry
                if not self.runLwgeom( feat.geometry(), lib=liblwgeom ):
                    SextanteLog.addToLog( SextanteLog.LOG_ERROR, u"FAILURE: previous failure info: layer %s, feature #%s" % (inputLayer.source(), feat.id()) )
                writer.addFeature(feat)

                progress.setPercentage( idx*100/count )
                idx += 1

        del writer
        progress.setPercentage( 100 )
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))

		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_voronoi_diagram(qgis, layer, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
Esempio n. 41
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))

        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_voronoi_diagram(qgis, layer, savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 42
0
def algoptions(name):
    alg = Sextante.getAlgorithm(name)
    if alg != None:
        s =""
        for param in alg.parameters:
            if isinstance(param, ParameterSelection):
                s+=param.name + "(" + param.description + ")\n"
                i=0
                for option in param.options:
                    s+= "\t" + str(i) + " - " + str(option) + "\n"
                    i+=1
        print(s)
    else:
        print "Algorithm not found"
def algoptions(name):
    alg = Sextante.getAlgorithm(name)
    if alg != None:
        s = ""
        for param in alg.parameters:
            if isinstance(param, ParameterSelection):
                s += param.name + "(" + param.description + ")\n"
                i = 0
                for option in param.options:
                    s += "\t" + str(i) + " - " + str(option) + "\n"
                    i += 1
        print(s)
    else:
        print "Algorithm not found"
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()

		attribute = self.getParameterValue(self.ATTRIBUTE)
		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_text_to_float(qgis, layername, [ attribute ], savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()
		hspacing = self.getParameterValue(self.HSPACING)
		vspacing = self.getParameterValue(self.VSPACING)
		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_gridify_layer(qgis, layername, hspacing, vspacing, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
 def run(self):
     s = unicode(self.combo.currentText())
     if s.startswith("SEXTANTE algorithm: "):
         algName = s[len("SEXTANTE algorithm: "):]
         alg = Sextante.getAlgorithmFromFullName(algName)
         if alg is not None:
             self.close()
             self.runAlgorithm(alg)
     elif s.startswith("Command: "):
         command = s[len("Command: "):]
         try:
             self.runCommand(command)
             self.close()
         except Exception, e:
             self.label.setVisible(True)
             self.label.setText("Error:" +  unicode(e) )
Esempio n. 47
0
 def run(self):
     s = unicode(self.combo.currentText())
     if s.startswith("SEXTANTE algorithm: "):
         algName = s[len("SEXTANTE algorithm: "):]
         alg = Sextante.getAlgorithmFromFullName(algName)
         if alg is not None:
             self.close()
             self.runAlgorithm(alg)                
     elif s.startswith("Command: "):
         command = s[len("Command: "):]            
         try:
             self.runCommand(command)
             self.close()
         except Exception, e:
             self.label.setVisible(True)                
             self.label.setText("Error:" +  unicode(e) )                
Esempio n. 48
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()
        hspacing = self.getParameterValue(self.HSPACING)
        vspacing = self.getParameterValue(self.VSPACING)
        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_gridify_layer(qgis, layername, hspacing, vspacing,
                                        savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		hublayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.HUBNAME))		
		spokelayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.SPOKENAME))
		
		hubattribute = self.getParameterValue(self.HUBATTRIBUTE)
		spokeattribute = self.getParameterValue(self.SPOKEATTRIBUTE)

		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_hub_lines(qgis, hublayer, hubattribute, spokelayer, spokeattribute, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
Esempio n. 50
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()

        attribute = self.getParameterValue(self.ATTRIBUTE)
        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_text_to_float(qgis, layername, [attribute], savename,
                                        False)

        if message:
            raise GeoAlgorithmExecutionException(message)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layersource = QGisLayers.getObjectFromUri(self.getParameterValue(self.SOURCENAME))	
		layerdest = QGisLayers.getObjectFromUri(self.getParameterValue(self.DESTNAME))		

		nameattribute = self.getParameterValue(self.NAMEATTRIBUTE)
		units = self.unitlist[self.getParameterValue(self.UNITS)]
		addlines = self.getParameterValue(self.SHAPETYPE)
		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_hub_distance(qgis, layersource, layerdest, nameattribute, units, addlines, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
	def processAlgorithm(self, progress):
		# Include must be done here to avoid cyclic import
		from sextante.core.Sextante import Sextante
		qgis = Sextante.getInterface()

		layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
		layername = layer.name()

		attribute = self.getParameterValue(self.ATTRIBUTE)
		comparison = self.comparisons [ self.getParameterValue(self.COMPARISON) ]
		# print str(self.getParameterValue(self.COMPARISON)) + ": " + str(comparison)
		comparisonvalue = self.getParameterValue(self.COMPARISONVALUE)
		savename = self.getOutputValue(self.SAVENAME)

		message = mmqgisx_select(qgis, layername, attribute, comparisonvalue, comparison, savename, False)

		if message:
			raise GeoAlgorithmExecutionException(message)
Esempio n. 53
0
def testAlg(algname, *args):
    
    #test simple execution
    alg = Sextante.runAlgorithm(algname, None, *args)
    assert alg is not None
        
    out = alg.getOutputValuesAsDictionary()
    
    return out
    
    #test execution in a model
    
    #===========================================================================
    # model = ModelerAlgorithm()
    # model.addAlgorithm(alg, parametersMap, valuesMap, outputsMap, dependencies)
    #===========================================================================
    
    #test 
 def fillCombo(self):
     self.combo.clear()
     #add algorithms
     for providerName in Sextante.algs.keys():
         provider = Sextante.algs[providerName]
         algs = provider.values()
         for alg in algs:
             self.combo.addItem("SEXTANTE algorithm: " + alg.name)
     #add functions
     for command in dir(self.commands):
         if isinstance(self.commands.__dict__.get(command), types.FunctionType):
             self.combo.addItem("Command: " + command);
     #add menu entries
     menuActions = []
     actions = Sextante.getInterface().mainWindow().menuBar().actions()
     for action in actions:
         menuActions.extend(self.getActions(action))
     for action in menuActions:
         self.combo.addItem("Menu action: " + unicode(action.text()))
Esempio n. 55
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.LAYERNAME))
        layername = layer.name()

        attribute = self.getParameterValue(self.ATTRIBUTE)
        comparison = self.comparisons[self.getParameterValue(self.COMPARISON)]
        # print str(self.getParameterValue(self.COMPARISON)) + ": " + str(comparison)
        comparisonvalue = self.getParameterValue(self.COMPARISONVALUE)
        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_select(qgis, layername, attribute, comparisonvalue,
                                 comparison, savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 56
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        hublayer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.HUBNAME))
        spokelayer = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.SPOKENAME))

        hubattribute = self.getParameterValue(self.HUBATTRIBUTE)
        spokeattribute = self.getParameterValue(self.SPOKEATTRIBUTE)

        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_hub_lines(qgis, hublayer, hubattribute, spokelayer,
                                    spokeattribute, savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 57
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        savename = self.getOutputValue(self.SAVENAME)
        hspacing = self.getParameterValue(self.HSPACING)
        vspacing = self.getParameterValue(self.VSPACING)
        width = self.getParameterValue(self.WIDTH)
        height = self.getParameterValue(self.HEIGHT)
        centerx = self.getParameterValue(self.CENTERX)
        centery = self.getParameterValue(self.CENTERY)
        originx = centerx - (width / 2.0)
        originy = centery - (height / 2.0)
        gridtype = self.gridtype_options[self.getParameterValue(self.GRIDTYPE)]

        message = mmqgisx_grid(qgis, savename, hspacing, vspacing, width,
                               height, originx, originy, gridtype, 0)

        if message:
            raise GeoAlgorithmExecutionException(message)
Esempio n. 58
0
    def processAlgorithm(self, progress):
        # Include must be done here to avoid cyclic import
        from sextante.core.Sextante import Sextante
        qgis = Sextante.getInterface()

        layersource = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.SOURCENAME))
        layerdest = QGisLayers.getObjectFromUri(
            self.getParameterValue(self.DESTNAME))

        nameattribute = self.getParameterValue(self.NAMEATTRIBUTE)
        units = self.unitlist[self.getParameterValue(self.UNITS)]
        addlines = self.getParameterValue(self.SHAPETYPE)
        savename = self.getOutputValue(self.SAVENAME)

        message = mmqgisx_hub_distance(qgis, layersource, layerdest,
                                       nameattribute, units, addlines,
                                       savename, False)

        if message:
            raise GeoAlgorithmExecutionException(message)