Skip to content
Permalink
Browse files

Moved sextante into python plugins. Note sextant was brought in at re…

…vision 333 from svn
  • Loading branch information
timlinux committed Aug 4, 2012
1 parent 9f908d6 commit 5c32892e953442fc482d24c0a02deabeb49ccbf3
Showing 2,071 changed files with 85,632 additions and 0 deletions.
@@ -4,3 +4,4 @@ ADD_SUBDIRECTORY(fTools)
ADD_SUBDIRECTORY(GdalTools)
ADD_SUBDIRECTORY(osm)
ADD_SUBDIRECTORY(db_manager)
#ADD_SUBDIRECTORY(sextante)
@@ -0,0 +1,2 @@
*~
*.pyc
@@ -0,0 +1,130 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import os, sys
import inspect
from sextante.core.Sextante import Sextante
from sextante.gui.SextanteToolbox import SextanteToolbox
from sextante.core.QGisLayers import QGisLayers
from sextante.gui.HistoryDialog import HistoryDialog
from sextante.core.SextanteUtils import SextanteUtils
from sextante.gui.ConfigDialog import ConfigDialog
from sextante.modeler.ModelerDialog import ModelerDialog
from sextante.gui.ResultsDialog import ResultsDialog
from sextante.about.AboutDialog import AboutDialog
import subprocess

cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)

class SextantePlugin:

def __init__(self, iface):
self.iface = iface
QGisLayers.setInterface(iface)
Sextante.initialize()
Sextante.setInterface(iface)

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)

def unload(self):
self.toolbox.setVisible(False)
self.menu.deleteLater()
#delete temporary output files
folder = SextanteUtils.tempFolder()
for f in os.listdir(folder):
path = os.path.join(folder,f)
try:
os.unlink(path)
except:
#leave files that could not be deleted
pass


def openToolbox(self):
self.toolbox.setVisible(True)

def openModeler(self):
dlg = ModelerDialog()
dlg.exec_()
if dlg.update:
self.toolbox.updateTree()

def openResults(self):
dlg = ResultsDialog()
dlg.exec_()

def openHistory(self):
dlg = HistoryDialog()
dlg.exec_()

def openConfig(self):
dlg = ConfigDialog(self.toolbox)
dlg.exec_()

def openAbout(self):
dlg = AboutDialog()
dlg.exec_()

def openHelp(self):
filename = os.path.dirname(__file__) + "/help/index.html"
if os.name == "nt":
os.startfile(filename)
elif sys.platform == "darwin":
subprocess.Popen(('open', filename))
else:
subprocess.call(('xdg-open', filename))


@@ -0,0 +1,13 @@
def name():
return "SEXTANTE"
def description():
return "SEXTANTE Geoprocessing Platform for QGIS"
def version():
return "Version 1.0.7"
def icon():
return "icon.png"
def qgisMinimumVersion():
return "1.0"
def classFactory(iface):
from sextante.SextantePlugin import SextantePlugin
return SextantePlugin(iface)
@@ -0,0 +1,37 @@
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import os

class AboutDialog(QtGui.QDialog):

def __init__(self):
QtGui.QDialog.__init__(self)
self.setModal(True)
self.setupUi()

def setupUi(self):
self.resize(600, 500)
self.webView = QtWebKit.QWebView()
self.setWindowTitle("About SEXTANTE")
self.verticalLayout= QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.webView)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Close")
self.closeButton.setMaximumWidth(150)
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.addStretch(1000)
self.horizontalLayout.addWidget(self.closeButton)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
self.verticalLayout.addLayout(self.horizontalLayout)
self.setLayout(self.verticalLayout)
filename = os.path.dirname(__file__) + "/about.htm"
url = QtCore.QUrl(filename)
self.webView.load(url)

def closeWindow(self):
self.close()
Empty file.
@@ -0,0 +1,22 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<title>SEXTANTE</title>
</head>
<body>
<img src="sextante_logo.png" />
<h2>SEXTANTE for QGIS</h2>
<p>SEXTANTE, a geoprocessing platform for QGIS</p>
<p>A development by Victor Olaya (volayaf@gmail.com).</p>
<p>Portions of this software contributed by:
<ul>
<li>Michael Nimm (mmqgis algorithms)</li>
<li>Carson Farmer (fTools algorithms)</li>
<li>Julien Malik (Orfeo Toolbox connectors)</li>
<li>Camilo Polymeris (Threading). Developed as part of Google Summer of Code 2012</li>
</ul>
</p>
<p>You are currently using SEXTANTE v1.0.7</p>
<p>This software is distributed under the terms of the GNU GPL License v2.
<p>For more information, please visit our website at <a href="http://sextantegis.com">http://sextantegis.com</a></p>
</body>
</html>
Binary file not shown.
@@ -0,0 +1,62 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterVector import ParameterVector
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.parameters.ParameterString import ParameterString
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.core.QGisLayers import QGisLayers
import os
from PyQt4 import QtGui


class AddTableField(GeoAlgorithm):

OUTPUT_LAYER = "OUTPUT_LAYER"
INPUT_LAYER = "INPUT_LAYER"
FIELD_NAME = "FIELD_NAME"
FIELD_TYPE = "FIELD_TYPE"
TYPE_NAMES = ["Integer", "Float", "String"]
TYPES = [QVariant.Int, QVariant.Double, QVariant.String]

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/toolbox.png")

def defineCharacteristics(self):
self.name = "Add field to attributes table"
self.group = "Algorithms for vector layers"
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY, False))
self.addParameter(ParameterString(self.FIELD_NAME, "Field name"))
self.addParameter(ParameterSelection(self.FIELD_TYPE, "Field type", self.TYPE_NAMES))
self.addOutput(OutputVector(self.OUTPUT_LAYER, "Output layer"))

def processAlgorithm(self, progress):
fieldtype = self.getParameterValue(self.FIELD_TYPE)
fieldname = self.getParameterValue(self.FIELD_NAME)
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(self.OUTPUT_LAYER)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, self.TYPES[fieldtype])
writer = QgsVectorFileWriter( output, systemEncoding,fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant() )
writer.addFeature( outFeat )
del writer

@@ -0,0 +1,50 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
from PyQt4.QtCore import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector
import os
from PyQt4 import QtGui

class AutoincrementalField(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/toolbox.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(self.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField("AUTO", QVariant.Int)
writer = QgsVectorFileWriter( output, systemEncoding,fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant(nElement) )
writer.addFeature( outFeat )
del writer

def defineCharacteristics(self):
self.name = "Add autoincremental field"
self.group = "Algorithms for vector layers"
self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addOutput(OutputVector(self.OUTPUT, "Output layer"))

@@ -0,0 +1,62 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
from PyQt4.QtCore import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector
import os
from PyQt4 import QtGui
from sextante.parameters.ParameterTableField import ParameterTableField

class AutoincrementalField(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
FIELD = "FIELD"

def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/toolbox.png")

def processAlgorithm(self, progress):
field_index = self.getParameterValue(self.FIELD)
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(self.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField("NUM_FIELD", QVariant.Int)
writer = QgsVectorFileWriter( output, systemEncoding,fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
classes = {}
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = inFeat.attributeMap()
clazz = atMap[field_index]
if not clazz in classes.keys:
classes[clazz] = len(classes.keys())
while vprovider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant(nElement) )
writer.addFeature( outFeat )
del writer

def defineCharacteristics(self):
self.name = "Add autoincremental field"
self.group = "Algorithms for vector layers"
self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(self.FIELD, "Unique ID Field", self.INPUT))
self.addOutput(OutputVector(self.OUTPUT, "Output layer"))

0 comments on commit 5c32892

Please sign in to comment.
You can’t perform that action at this time.