Skip to content
Permalink
Browse files
Severql bug fixes qnd smqll improvements in qgis bindings
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@43 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Mar 17, 2012
1 parent 1865097 commit e4554d5c53d9f25e8d6990fc859ebce5586070dc
Showing with 574 additions and 300 deletions.
  1. +4 −1 .pydevproject
  2. +27 −0 src/sextante/SextantePlugin.py
  3. +28 −0 src/sextante/about/AboutDialog.py
  4. 0 src/sextante/about/__init__.py
  5. +13 −0 src/sextante/about/about.htm
  6. BIN src/sextante/about/sextante_logo.png
  7. +14 −6 src/sextante/core/GeoAlgorithm.py
  8. +1 −2 src/sextante/core/Sextante.py
  9. +1 −1 src/sextante/core/SextanteLog.py
  10. +77 −0 src/sextante/ftools/ExtentFromLayer.py
  11. +6 −1 src/sextante/ftools/FToolsAlgorithmProvider.py
  12. +1 −1 src/sextante/ftools/PointsInPolygon.py
  13. +46 −0 src/sextante/ftools/RandomSelection.py
  14. +78 −0 src/sextante/ftools/RandomSelectionWithinSubsets.py
  15. +85 −0 src/sextante/ftools/SelectByLocation.py
  16. +1 −1 src/sextante/ftools/SimplifyGeometries.py
  17. +25 −9 src/sextante/gui/FixedTableDialog.py
  18. +2 −4 src/sextante/gui/FixedTablePanel.py
  19. +38 −41 src/sextante/gui/MultipleInputDialog.py
  20. +16 −3 src/sextante/gui/ParametersDialog.py
  21. +3 −0 src/sextante/gui/SextantePostprocessing.py
  22. BIN src/sextante/images/help.png
  23. BIN src/sextante/images/info.png
  24. +1 −1 src/sextante/metadata.txt
  25. +11 −10 src/sextante/modeler/ModelerAlgorithm.py
  26. +2 −2 src/sextante/modeler/ModelerParameterDefinitionDialog.py
  27. +18 −7 src/sextante/modeler/ModelerParametersDialog.py
  28. +4 −1 src/sextante/outputs/OutputFactory.py
  29. +6 −0 src/sextante/outputs/OutputVector.py
  30. +5 −1 src/sextante/parameters/ParameterBoolean.py
  31. +2 −1 src/sextante/parameters/ParameterFixedTable.py
  32. +10 −4 src/sextante/parameters/ParameterNumber.py
  33. +1 −1 src/sextante/parameters/ParameterTable.py
  34. +2 −1 src/sextante/parameters/ParameterVector.py
  35. +14 −6 src/sextante/r/RAlgorithm.py
  36. +5 −1 src/sextante/r/RUtils.py
  37. +18 −11 src/sextante/saga/SagaAlgorithm.py
  38. +7 −1 src/sextante/saga/SagaUtils.py
  39. +1 −1 src/sextante/saga/description/alg_221.txt
  40. +1 −1 src/sextante/saga/description/alg_82.txt
  41. +0 −122 src/sextante/untitled.ui
  42. +0 −58 src/sextante/untitled.ui.py
@@ -2,6 +2,9 @@
<?eclipse-pydev version="1.0"?>

<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/sextante/src</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
@@ -13,6 +13,8 @@
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:
@@ -63,6 +65,20 @@ def initGui(self):
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)
@@ -102,4 +118,15 @@ def openConfig(self):
dlg = ConfigDialog(self.toolbox)
dlg.exec_()

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

def openHelp(self):
filename = os.path.dirname(__file__) + "/manual.pdf"
if os.name == "nt":
os.startfile(filename)
else:
subprocess.call(('xdg-open', filename))


@@ -0,0 +1,28 @@
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.setObjectName("AboutDialog")
self.resize(500, 400)
self.webView = QtWebKit.QWebView()
self.webView.setObjectName("webView")
self.setWindowTitle("About SEXTANTE")
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.horizontalLayout.addWidget(self.webView)
self.setLayout(self.horizontalLayout)
filename = os.path.dirname(__file__) + "/about.htm"
url = QtCore.QUrl(filename)
self.webView.load(url)

Empty file.
@@ -0,0 +1,13 @@
<!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 Spatial Data Analysis Library</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>You are currently using SEXTANTE v1.0</p>
<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.
@@ -78,6 +78,12 @@ def setOutputValue(self, outputName, value):
if out.name == outputName:
out.value = value

def getOutputValuesAsDictionary(self):
d = {}
for out in self.outputs:
d[out.name] = out.value
return d

def canBeExecuted(self, layersCount):
return True

@@ -108,12 +114,14 @@ def getParameterFromName(self, name):
def getParameterValue(self, name):
for param in self.parameters:
if param.name == name:
if isinstance(param, ParameterNumber):
return float(param.value)
elif isinstance(param, ParameterBoolean):
return param.value == str(True)
else:
return param.value
#===============================================================
# if isinstance(param, ParameterNumber):
# return float(param.value)
# elif isinstance(param, ParameterBoolean):
# return param.value == str(True)
# else:
#===============================================================
return param.value
return None

def getOutputValue(self, name):
@@ -201,7 +201,7 @@ def runalg(name, *args):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
return alg.getOuputsValuesAsMap()
return alg.getOutputValuesAsDictionary()
except GeoAlgorithmExecutionException, e:
print "*****Error executing algorithm*****"
print e.msg
@@ -218,7 +218,6 @@ def loadFromAlg(layersdict):
def getObject(string):
QGisLayers.getObjectFromUri(string)


@staticmethod
def runandload(name, *args):
#a quick fix to call algorithms from the history dialog
@@ -28,7 +28,7 @@ def addToLog(msgtype, msg):
if isinstance(msg, list):
text=""
for i in range(0, len(msg)):
text+=msg[i] + "|"
text+=msg[i].strip("\n") + "|"
text = text[:-1]
else:
text = str(msg).replace("\n", "|")
@@ -0,0 +1,77 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector

class ExtentFromLayer(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"

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

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(ExtentFromLayer.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(ExtentFromLayer.INPUT))
fields = {
0 : QgsField( "MINX", QVariant.Double ),
1 : QgsField( "MINY", QVariant.Double ),
2 : QgsField( "MAXX", QVariant.Double ),
3 : QgsField( "MAXY", QVariant.Double ),
4 : QgsField( "CNTX", QVariant.Double ),
5 : QgsField( "CNTY", QVariant.Double ),
6 : QgsField( "AREA", QVariant.Double ),
7 : QgsField( "PERIM", QVariant.Double ),
8 : QgsField( "HEIGHT", QVariant.Double ),
9 : QgsField( "WIDTH", QVariant.Double ) }

writer = QgsVectorFileWriter(output, systemEncoding, fields, QGis.WKBPolygon, vlayer.crs() )
rect = vlayer.extent()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + ( width / 2.0 )
cnty = miny + ( height / 2.0 )
area = width * height
perim = ( 2 * width ) + (2 * height )
rect = [
QgsPoint( minx, miny ),
QgsPoint( minx, maxy ),
QgsPoint( maxx, maxy ),
QgsPoint( maxx, miny ),
QgsPoint( minx, miny ) ]
geometry = QgsGeometry().fromPolygon( [ rect ] )
feat = QgsFeature()
feat.setGeometry( geometry )
feat.setAttributeMap( {
0 : QVariant( minx ),
1 : QVariant( miny ),
2 : QVariant( maxx ),
3 : QVariant( maxy ),
4 : QVariant( cntx ),
5 : QVariant( cnty ),
6 : QVariant( area ),
7 : QVariant( perim ),
8 : QVariant( height ),
9 : QVariant( width ) } )
writer.addFeature( feat )
del writer


def defineCharacteristics(self):
self.name = "Extent from layer"
self.group = "Research tools"
self.addParameter(ParameterVector(ExtentFromLayer.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addOutput(OutputVector(ExtentFromLayer.OUTPUT, "Extent layer"))
#=========================================================
@@ -25,6 +25,10 @@
from sextante.ftools.Intersection import Intersection
from sextante.ftools.Union import Union
from sextante.ftools.Clip import Clip
from sextante.ftools.ExtentFromLayer import ExtentFromLayer
from sextante.ftools.RandomSelection import RandomSelection
from sextante.ftools.SelectByLocation import SelectByLocation
from sextante.ftools.RandomSelectionWithinSubsets import RandomSelectionWithinSubsets

class FToolsAlgorithmProvider(AlgorithmProvider):

@@ -41,7 +45,8 @@ def _loadAlgorithms(self):
SumLines(), BasicStatistics(), PointsInPolygon(),
NearestNeighbourAnalysis(), MeanCoords(), LinesIntersection(),
ConvexHull(), FixedDistanceBuffer(), VariableDistanceBuffer(),
Dissolve(), Difference(), Intersection(), Union(), Clip()]
Dissolve(), Difference(), Intersection(), Union(), Clip(), ExtentFromLayer(),
RandomSelection(), RandomSelectionWithinSubsets(), SelectByLocation()]
for alg in self.algs:
alg.provider = self

@@ -42,7 +42,7 @@ def processAlgorithm(self, progress):
index = polyProvider.fieldNameIndex(unicode(inField))
if index == -1:
index = polyProvider.fieldCount()
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("point count field"))
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, "point count field")
fieldList[index] = field
sRs = polyProvider.crs()
check = QFile(self.shapefileName)
@@ -0,0 +1,46 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterNumber import ParameterNumber
import random

class RandomSelection(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
METHOD = "METHOD"
NUMBER = "NUMBER"
PERCENTAGE = "PERCENTAGE"

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

def processAlgorithm(self, progress):
filename = self.getParameterValue(RandomSelection.INPUT)
layer = QGisLayers.getObjectFromUri(filename)
method = self.getParameterValue(self.METHOD)
if method == 0:
value = int(self.getParameterValue(self.NUMBER))
else:
value = self.getParameterValue(self.PERCENTAGE)
value = int(round((value / 100.0000), 4) * layer.featureCount())
selran = random.sample(xrange(0, layer.featureCount()), value)
layer.setSelectedFeatures(selran)
self.setOutputValue(self.OUTPUT, filename)


def defineCharacteristics(self):
self.name = "Random selection"
self.group = "Research tools"
self.addParameter(ParameterVector(RandomSelection.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterSelection(RandomSelection.METHOD, "Method", ["Number of selected features", "Percentage of selected features"]))
self.addParameter(ParameterNumber(RandomSelection.NUMBER, "Number of selected features", 1, None, 10))
self.addParameter(ParameterNumber(RandomSelection.PERCENTAGE, "Percentage of selected features", 0, 100, 50))
self.addOutput(OutputVector(RandomSelection.OUTPUT, "Selection", True))
@@ -0,0 +1,78 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm
import os.path
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputVector import OutputVector
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterNumber import ParameterNumber
import random
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.ftools import ftools_utils

class RandomSelectionWithinSubsets(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
METHOD = "METHOD"
NUMBER = "NUMBER"
PERCENTAGE = "PERCENTAGE"
FIELD = "FIELD"

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

def processAlgorithm(self, progress):
method = self.getParameterValue(self.METHOD)
field = self.getParameterValue(RandomSelectionWithinSubsets.FIELD)
filename = self.getParameterValue(RandomSelectionWithinSubsets.INPUT)
vlayer = QGisLayers.getObjectFromUri(filename)
vlayer.removeSelection(True)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select(allAttrs)
index = vprovider.fieldNameIndex(field)
unique = ftools_utils.getUniqueValues(vprovider, int(index))
inFeat = QgsFeature()
selran = []
nFeat = vprovider.featureCount() * len(unique)
nElement = 0
if not len(unique) == vlayer.featureCount():
for i in unique:
vprovider.rewind()
FIDs= []
while vprovider.nextFeature(inFeat):
atMap = inFeat.attributeMap()
if atMap[index] == QVariant(i):
FID = inFeat.id()
FIDs.append(FID)
nElement += 1
progress.setPercentage(nElement/nFeat * 100)
if method == 0:
value = int(self.getParameterValue(self.NUMBER))
else:
value = self.getParameterValue(self.PERCENTAGE)
value = int(round((value / 100.0000) * len(FIDs), 0))
if value >= len(FIDs):
selFeat = FIDs
else:
selFeat = random.sample(FIDs, value)
selran.extend(selFeat)
vlayer.setSelectedFeatures(selran)
else:
vlayer.setSelectedFeatures(range(0, vlayer.featureCount()))
self.setOutputValue(RandomSelectionWithinSubsets.OUTPUT, filename)


def defineCharacteristics(self):
self.name = "Random selection within subsets"
self.group = "Research tools"
self.addParameter(ParameterVector(RandomSelectionWithinSubsets.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(RandomSelectionWithinSubsets.FIELD, "ID Field", RandomSelectionWithinSubsets.INPUT))
self.addParameter(ParameterSelection(RandomSelectionWithinSubsets.METHOD, "Method", ["Number of selected features", "Percentage of selected features"]))
self.addParameter(ParameterNumber(RandomSelectionWithinSubsets.NUMBER, "Number of selected features", 1, None, 10))
self.addParameter(ParameterNumber(RandomSelectionWithinSubsets.PERCENTAGE, "Percentage of selected features", 0, 100, 50))
self.addOutput(OutputVector(RandomSelectionWithinSubsets.OUTPUT, "Selection", True))

0 comments on commit e4554d5

Please sign in to comment.