Skip to content
Permalink
Browse files

Merge linfiniti2:/tmp/sextante into sextante-import

  • Loading branch information
timlinux committed Aug 24, 2012
2 parents 17f91e7 + 9f47d96 commit 7ceb4608f1a5b31a1700876886916e810f78899a
Showing with 674 additions and 247 deletions.
  1. +3 −1 python/plugins/sextante/about/about.htm
  2. +2 −4 python/plugins/sextante/algs/AddTableField.py
  3. +2 −4 python/plugins/sextante/algs/AutoincrementalField.py
  4. +2 −4 python/plugins/sextante/algs/EquivalentNumField.py
  5. +2 −5 python/plugins/sextante/algs/Explode.py
  6. +2 −4 python/plugins/sextante/algs/FieldsCalculator.py
  7. +4 −6 python/plugins/sextante/algs/SaveSelectedFeatures.py
  8. +5 −1 python/plugins/sextante/algs/SextanteAlgorithmProvider.py
  9. +15 −2 python/plugins/sextante/core/AlgorithmProvider.py
  10. +16 −5 python/plugins/sextante/core/GeoAlgorithm.py
  11. +5 −8 python/plugins/sextante/core/Sextante.py
  12. +7 −2 python/plugins/sextante/core/SextanteConfig.py
  13. +8 −0 python/plugins/sextante/core/SextanteLog.py
  14. +3 −9 python/plugins/sextante/ftools/Buffer.py
  15. +1 −6 python/plugins/sextante/ftools/Centroids.py
  16. +9 −9 python/plugins/sextante/ftools/ConvexHull.py
  17. +1 −4 python/plugins/sextante/ftools/Delaunay.py
  18. +1 −4 python/plugins/sextante/ftools/Difference.py
  19. +1 −6 python/plugins/sextante/ftools/Dissolve.py
  20. +1 −4 python/plugins/sextante/ftools/ExportGeometryInfo.py
  21. +1 −4 python/plugins/sextante/ftools/ExtentFromLayer.py
  22. +1 −4 python/plugins/sextante/ftools/ExtractNodes.py
  23. +3 −0 python/plugins/sextante/ftools/FToolsAlgorithmProvider.py
  24. +6 −2 python/plugins/sextante/ftools/FixedDistanceBuffer.py
  25. +1 −4 python/plugins/sextante/ftools/Intersection.py
  26. +1 −4 python/plugins/sextante/ftools/LayerFromExtent.py
  27. +1 −8 python/plugins/sextante/ftools/LinesIntersection.py
  28. +1 −4 python/plugins/sextante/ftools/LinesToPolygons.py
  29. +1 −4 python/plugins/sextante/ftools/MeanCoords.py
  30. +1 −5 python/plugins/sextante/ftools/MultipartToSingleparts.py
  31. +1 −8 python/plugins/sextante/ftools/PointsInPolygon.py
  32. +1 −7 python/plugins/sextante/ftools/PolygonsToLines.py
  33. +3 −10 python/plugins/sextante/ftools/SimplifyGeometries.py
  34. +32 −11 python/plugins/sextante/ftools/SinglePartsToMultiparts.py
  35. +1 −9 python/plugins/sextante/ftools/SumLines.py
  36. +1 −4 python/plugins/sextante/ftools/Union.py
  37. +6 −2 python/plugins/sextante/ftools/VariableDistanceBuffer.py
  38. +1 −4 python/plugins/sextante/ftools/VoronoiPolygons.py
  39. +2 −1 python/plugins/sextante/grass/GrassAlgorithm.py
  40. +1 −0 python/plugins/sextante/grass/GrassUtils.py
  41. +84 −33 python/plugins/sextante/gui/AlgorithmExecutionDialog.py
  42. +21 −5 python/plugins/sextante/gui/AlgorithmExecutor.py
  43. +2 −0 python/plugins/sextante/gui/ConfigDialog.py
  44. +48 −13 python/plugins/sextante/gui/OutputSelectionPanel.py
  45. +12 −0 python/plugins/sextante/gui/ParametersPanel.py
  46. +9 −4 python/plugins/sextante/gui/SextantePostprocessing.py
  47. +9 −0 python/plugins/sextante/gui/UnthreadedAlgorithmExecutor.py
  48. +14 −1 python/plugins/sextante/modeler/ModelerAlgorithm.py
  49. +4 −2 python/plugins/sextante/otb/OTBAlgorithm.py
  50. +1 −0 python/plugins/sextante/otb/OTBUtils.py
  51. +33 −1 python/plugins/sextante/outputs/OutputVector.py
  52. +2 −1 python/plugins/sextante/parameters/ParameterString.py
  53. +10 −1 python/plugins/sextante/r/RAlgorithm.py
  54. +3 −1 python/plugins/sextante/r/RUtils.py
  55. +1 −1 python/plugins/sextante/saga/SagaAlgorithm.py
  56. +1 −0 python/plugins/sextante/saga/SagaUtils.py
  57. +1 −1 python/plugins/sextante/tests/runtests.sh
  58. +214 −0 src/sextante/algs/FieldPyculator.py
  59. +49 −0 src/sextante/core/SextanteVectorWriter.py
@@ -9,9 +9,11 @@ <h2>SEXTANTE for QGIS</h2>
<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>Alexander Bruy</li>
<li>Carson Farmer (fTools algorithms)</li>
<li>Julien Malik (Orfeo Toolbox connectors)</li>
<li>Evgeniy Nikulin (Original Field Pyculator code)</li>
<li>Michael Nimm (mmqgis algorithms)</li>
<li>Camilo Polymeris (Threading). Developed as part of Google Summer of Code 2012</li>
</ul>
</p>
@@ -34,16 +34,14 @@ def defineCharacteristics(self):
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)
output = self.getOutputFromName(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() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -16,16 +16,14 @@ 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)
output = self.getOutputFromName(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() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -19,16 +19,14 @@ def getIcon(self):

def processAlgorithm(self, progress):
field_index = self.getParameterValue(self.FIELD)
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(self.OUTPUT)
output = self.getOutputFromName(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() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -17,16 +17,13 @@ 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()
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = QgsVectorFileWriter( output, systemEncoding,
fields, QGis.WKBLineString, vprovider.crs() )
writer = output.getVectorWriter(fields, QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -32,16 +32,14 @@ def defineCharacteristics(self):
def processAlgorithm(self, progress):
fieldname = self.getParameterValue(self.FIELD_NAME)
formula = self.getParameterValue(self.FORMULA)
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(self.OUTPUT_LAYER)
output = self.getOutputFromName(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, QVariant.Double)
writer = QgsVectorFileWriter( output, systemEncoding,fields, vprovider.geometryType(), vprovider.crs() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -50,7 +50,7 @@ def processAlgorithm(self, progress):
#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)
output = self.getOutputFromName(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))
@@ -60,12 +60,10 @@ def processAlgorithm(self, progress):
#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()
#To do so, we call the getVectorWriter method in the Output object.
#That will give as a SextanteVectorWriter, that we can later use to add features.
provider = vectorLayer.dataProvider()
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), provider.geometryType(), provider.crs() )
writer = output.getVectorWriter( provider.fields(), provider.geometryType(), provider.crs() )

#Now we take the selected features and add them to the output layer
selection = vectorLayer.selectedFeatures()
@@ -6,13 +6,14 @@
from sextante.algs.SaveSelectedFeatures import SaveSelectedFeatures
from sextante.algs.Explode import Explode
from sextante.algs.AutoincrementalField import AutoincrementalField
from sextante.algs.FieldPyculator import FieldsPyculator

class SextanteAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.alglist = [AddTableField(), FieldsCalculator(), SaveSelectedFeatures(),
AutoincrementalField(), Explode()]
AutoincrementalField(), Explode(), FieldsPyculator()]

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
@@ -33,3 +34,6 @@ def getIcon(self):

def _loadAlgorithms(self):
self.algs = self.alglist

def supportsNonFileBasedOutput(self):
return True
@@ -1,6 +1,7 @@
from sextante.core.SextanteConfig import Setting, SextanteConfig
import os
from PyQt4 import QtGui
from qgis.core import *

class AlgorithmProvider():
'''this is the base class for algorithms providers.
@@ -67,7 +68,19 @@ def getSupportedOutputRasterLayerExtensions(self):
return ["tif"]

def getSupportedOutputVectorLayerExtensions(self):
return ["shp"]
formats = QgsVectorFileWriter.supportedFiltersAndFormats()
extensions = ["shp"]#shp is the default, should be the first
for extension in formats.keys():
extension = str(extension)
extension = extension[extension.find('*.') + 2:]
extension = extension[:extension.find(" ")]
if extension.lower() != "shp":
extensions.append(extension)
return extensions
#return ["shp"]

def getSupportedOutputTableExtensions(self):
return ["dbf"]
return ["dbf"]

def supportsNonFileBasedOutput(self):
return False
@@ -4,6 +4,8 @@
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from PyQt4 import QtGui
from PyQt4.QtCore import *
from qgis.core import *
import os.path
from sextante.core.SextanteUtils import SextanteUtils
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
@@ -117,20 +119,27 @@ def execute(self, progress):
except GeoAlgorithmExecutionException, gaee:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, gaee.msg)
raise gaee
except Exception, e:
except:
#if something goes wrong and is not caught in the algorithm,
#we catch it here and wrap it
lines = []
lines.append(str(e))
lines.append(traceback.format_exc().replace("\n", "|"))
lines = ["Uncaught error while executing algorithm"]
errstring = traceback.format_exc()
newline = errstring.find("\n")
if newline != -1:
lines.append(errstring[:newline])
else:
lines.append(errstring)
lines.append(errstring.replace("\n", "|"))
SextanteLog.addToLog(SextanteLog.LOG_ERROR, lines)
raise GeoAlgorithmExecutionException(str(e))
raise GeoAlgorithmExecutionException(errstring)

def checkOutputFileExtensions(self):
'''Checks if the values of outputs are correct and have one of the supported output extensions.
If not, it adds the first one of the supported extensions, which is assumed to be the default one'''
for out in self.outputs:
if (not out.hidden) and out.value != None:
if not os.path.isabs(out.value):
continue
if isinstance(out, OutputRaster):
exts = self.provider.getSupportedOutputRasterLayerExtensions()
elif isinstance(out, OutputVector):
@@ -263,3 +272,5 @@ def getAsCommand(self):
s+=out.getValueAsCommandLineParameter() + ","
s= s[:-1] + ")"
return s


@@ -287,24 +287,21 @@ def runAlgorithm(algOrName, onFinish, *args):

msg = alg.checkParameterValuesBeforeExecuting()
if msg:
try:
QMessageBox.critical(None, "Unable to execute algorithm", msg)
return
except:
print ("Unable to execute algorithm\n" + msg)
return

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

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if SextanteConfig.getSetting(SextanteConfig.USE_THREADS) and onFinish:
if SextanteConfig.getSetting(SextanteConfig.USE_THREADS):
algEx = AlgorithmExecutor(alg)
progress = QProgressDialog()
progress.setWindowTitle(alg.name)
progress.setLabelText("Executing %s..." % alg.name)
def finish():
QApplication.restoreOverrideCursor()
onFinish(alg)
if onFinish is not None:
onFinish(alg)
progress.close()
def error(msg):
QApplication.restoreOverrideCursor()
@@ -323,8 +320,8 @@ def cancel():
algEx.start()
algEx.wait()
else:
UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress())
if onFinish:
ret = UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress())
if onFinish is not None and ret:
onFinish(alg)
QApplication.restoreOverrideCursor()
return alg
@@ -15,6 +15,8 @@ class SextanteConfig():
USE_FILENAME_AS_LAYER_NAME = "USE_FILENAME_AS_LAYER_NAME"
KEEP_DIALOG_OPEN = "KEEP_DIALOG_OPEN"
USE_THREADS = "USE_THREADS"
SHOW_DEBUG_IN_DIALOG = "SHOW_DEBUG_IN_DIALOG"
RECENT_ALGORITHMS = "RECENT_ALGORITHMS"

settings = {}
settingIcons= {}
@@ -24,6 +26,7 @@ def initialize():
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")
SextanteConfig.settingIcons["General"] = icon
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_THREADS, "Run algorithms in a new thread (still unstable)", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.SHOW_DEBUG_IN_DIALOG, "Show debug information and commands executed in the execution dialog's Log panel (threaded execution only)", True))
SextanteConfig.addSetting(Setting("General", SextanteConfig.KEEP_DIALOG_OPEN, "Keep dialog open after running an algorithm", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_SELECTED, "Use only selected features in external applications", True))
SextanteConfig.addSetting(Setting("General", SextanteConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
@@ -35,6 +38,7 @@ def initialize():
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_POINT_STYLE,"Style for point layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_LINE_STYLE,"Style for line layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_POLYGON_STYLE,"Style for polygon layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.RECENT_ALGORITHMS,"Recent algs","", hidden=True))

@staticmethod
def setGroupIcon(group, icon):
@@ -112,12 +116,13 @@ def setSettingValue(name, value):

class Setting():
'''A simple config parameter that will appear on the SEXTANTE config dialog'''
def __init__(self, group, name, description, default):
def __init__(self, group, name, description, default, hidden = False):
self.group=group
self.name = name
self.description = description
self.default = default
self.value = default
self.hidden = hidden

def __str__(self):
return self.name + "=" + str(self.value)
return self.name + "=" + str(self.value)
@@ -1,6 +1,7 @@
import datetime
import os
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig
import codecs
from PyQt4 import QtGui
class SextanteLog():
@@ -47,6 +48,8 @@ def addToLog(msgtype, msg):
algname = algname[:algname.index("\"")]
if algname not in SextanteLog.recentAlgs:
SextanteLog.recentAlgs.append(algname)
recentAlgsString = ';'.join(SextanteLog.recentAlgs[-6:])
SextanteConfig.setSettingValue(SextanteConfig.RECENT_ALGORITHMS, recentAlgsString)
except:
pass

@@ -86,6 +89,11 @@ def getLogEntries():

@staticmethod
def getRecentAlgorithms():
recentAlgsSetting = SextanteConfig.getSetting(SextanteConfig.RECENT_ALGORITHMS)
try:
SextanteLog.recentAlgs = recentAlgsSetting.split(';')
except:
pass
return SextanteLog.recentAlgs


@@ -4,9 +4,7 @@
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog

def buffering(progress, output, distance, field, useSelection, useField, layer, dissolve, segments ):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
def buffering(progress, writer, distance, field, useSelection, useField, layer, dissolve, segments ):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = layer.dataProvider()
@@ -15,10 +13,6 @@ def buffering(progress, output, distance, field, useSelection, useField, layer,
fields = vproviderA.fields()
if useField:
field = vproviderA.fieldNameIndex(field)
writer = QgsVectorFileWriter(output, systemEncoding, fields, QGis.WKBPolygon, vproviderA.crs() )
# check if writer was created properly, if not, return with error
if writer.hasError():
raise GeoAlgorithmExecutionException("Could not create output file");
outFeat = QgsFeature()
inFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -64,9 +58,9 @@ def buffering(progress, output, distance, field, useSelection, useField, layer,
for inFeat in selectionA:
atMap = inFeat.attributeMap()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
value = atMap[ field ].toDouble()[ 0 ]
else:
value = self.myParam
value = distance
inGeom = QgsGeometry( inFeat.geometry() )
try:
outGeom = inGeom.buffer( float( value ), segments )
@@ -28,14 +28,9 @@ def defineCharacteristics(self):
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(Centroids.INPUT_LAYER))

outFileName = self.getOutputValue(Centroids.OUTPUT_LAYER)

provider = layer.dataProvider()

settings = QSettings()
encoding = settings.value( "/UI/encoding", "System" ).toString()

writer = QgsVectorFileWriter(outFileName, encoding, provider.fields(),
writer = self.getOutputFromName(Centroids.OUTPUT_LAYER).getVectorWriter(provider.fields(),
QGis.WKBPoint, provider.crs())

allAttrs = provider.attributeIndexes()

0 comments on commit 7ceb460

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