Skip to content
Permalink
Browse files

added mmqgis and ftools algorithms

several more changes in qgis interface

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@28 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com
volayaf@gmail.com committed Mar 4, 2012
1 parent 906d67a commit 562ca2036584fc4126870d9325952a127a8e4855
Showing with 2,240 additions and 203 deletions.
  1. +9 −1 src/sextante/core/AlgorithmProvider.py
  2. +1 −1 src/sextante/core/GeoAlgorithm.py
  3. +18 −4 src/sextante/core/Sextante.py
  4. +0 −1 src/sextante/core/SextanteConfig.py
  5. +4 −1 src/sextante/core/SextanteLog.py
  6. +2 −15 src/sextante/core/SextanteResults.py
  7. +0 −2 src/sextante/core/SextanteUtils.py
  8. +34 −32 src/sextante/ftools/{BasicStatisticsAlgorithm.py → BasicStatistics.py}
  9. +148 −0 src/sextante/ftools/Buffer.py
  10. +5 −5 src/sextante/ftools/{CentroidsAlgorithm.py → Centroids.py}
  11. +170 −0 src/sextante/ftools/ConvexHull.py
  12. +5 −5 src/sextante/ftools/{DelaunayAlgorithm.py → Delaunay.py}
  13. +196 −0 src/sextante/ftools/Difference.py
  14. +178 −0 src/sextante/ftools/Dissolve.py
  15. +5 −5 src/sextante/ftools/{ExportGeometryInfoAlgorithm.py → ExportGeometryInfo.py}
  16. +5 −6 src/sextante/ftools/{ExtractNodesAlgorithm.py → ExtractNodes.py}
  17. +34 −14 src/sextante/ftools/FToolsAlgorithmProvider.py
  18. +46 −0 src/sextante/ftools/FixedDistanceBuffer.py
  19. +201 −0 src/sextante/ftools/Intersection.py
  20. +107 −0 src/sextante/ftools/LinesIntersection.py
  21. +6 −5 src/sextante/ftools/{LinesToPolygonsAlgorithm.py → LinesToPolygons.py}
  22. +106 −0 src/sextante/ftools/MeanCoords.py
  23. +70 −0 src/sextante/ftools/NearestNeighbourAnalysis.py
  24. +93 −0 src/sextante/ftools/PointsInPolygon.py
  25. +5 −5 src/sextante/ftools/{PolygonsToLinesAlgorithm.py → PolygonsToLines.py}
  26. +9 −9 src/sextante/ftools/{SimplifyGeometriesAlgorithm.py → SimplifyGeometries.py}
  27. +9 −8 src/sextante/ftools/{SinglePartsToMultipartsAlgorithm.py → SinglePartsToMultiparts.py}
  28. +9 −9 src/sextante/ftools/{SumLinesAlgorithm.py → SumLines.py}
  29. +46 −0 src/sextante/ftools/VariableDistanceBuffer.py
  30. +5 −5 src/sextante/ftools/{VoronoiAlgorithm.py → VoronoiPolygons.py}
  31. +9 −0 src/sextante/ftools/copyright.txt
  32. BIN src/sextante/ftools/icons/analysis.png
  33. BIN src/sextante/ftools/icons/basic_statistics.png
  34. BIN src/sextante/ftools/icons/buffer.png
  35. BIN src/sextante/ftools/icons/centroids.png
  36. BIN src/sextante/ftools/icons/check_geometry.png
  37. BIN src/sextante/ftools/icons/clip.png
  38. BIN src/sextante/ftools/icons/convex_hull.png
  39. BIN src/sextante/ftools/icons/define_projection.png
  40. BIN src/sextante/ftools/icons/difference.png
  41. BIN src/sextante/ftools/icons/dissolve.png
  42. BIN src/sextante/ftools/icons/export_geometry.png
  43. BIN src/sextante/ftools/icons/export_projection.png
  44. BIN src/sextante/ftools/icons/extract_nodes.png
  45. BIN src/sextante/ftools/icons/ftools_logo.png
  46. BIN src/sextante/ftools/icons/geometry.png
  47. BIN src/sextante/ftools/icons/geoprocessing.png
  48. BIN src/sextante/ftools/icons/intersect.png
  49. BIN src/sextante/ftools/icons/intersections.png
  50. BIN src/sextante/ftools/icons/join_attributes.png
  51. BIN src/sextante/ftools/icons/join_location.png
  52. BIN src/sextante/ftools/icons/management.png
  53. BIN src/sextante/ftools/icons/matrix.png
  54. BIN src/sextante/ftools/icons/mean.png
  55. BIN src/sextante/ftools/icons/multi_to_single.png
  56. BIN src/sextante/ftools/icons/neighbour.png
  57. BIN src/sextante/ftools/icons/random_points.png
  58. BIN src/sextante/ftools/icons/random_selection.png
  59. BIN src/sextante/ftools/icons/regular_points.png
  60. BIN src/sextante/ftools/icons/sampling.png
  61. BIN src/sextante/ftools/icons/select_location.png
  62. BIN src/sextante/ftools/icons/simplify.png
  63. BIN src/sextante/ftools/icons/single_to_multi.png
  64. BIN src/sextante/ftools/icons/split_layer.png
  65. BIN src/sextante/ftools/icons/sub_selection.png
  66. BIN src/sextante/ftools/icons/sum_lines.png
  67. BIN src/sextante/ftools/icons/sum_points.png
  68. BIN src/sextante/ftools/icons/sym_difference.png
  69. BIN src/sextante/ftools/icons/to_lines.png
  70. BIN src/sextante/ftools/icons/union.png
  71. BIN src/sextante/ftools/icons/unique.png
  72. BIN src/sextante/ftools/icons/vector_grid.png
  73. BIN src/sextante/ftools/icons/voronoi.png
  74. +1 −0 src/sextante/gui/AlgorithmExecutor.py
  75. +4 −0 src/sextante/gui/BatchProcessingDialog.py
  76. +1 −1 src/sextante/gui/HistoryDialog.py
  77. +1 −1 src/sextante/gui/OutputSelectionPanel.py
  78. +24 −2 src/sextante/gui/ParametersDialog.py
  79. +29 −0 src/sextante/gui/RangePanel.py
  80. +8 −3 src/sextante/gui/ResultsDialog.py
  81. +22 −0 src/sextante/gui/SextantePostprocessing.py
  82. +2 −1 src/sextante/gui/SextanteToolbox.py
  83. BIN src/sextante/images/r.png
  84. +0 −1 src/sextante/mmqgis/scripts/Create_Grid_Layer.py
  85. BIN src/sextante/mmqgis/scripts/{mmqgis_text_to_float.png → Text_to_float.png}
  86. +6 −0 src/sextante/mmqgis/scripts/Text_to_float.py
  87. +5 −0 src/sextante/modeler/CreateNewModelAction.py
  88. +8 −5 src/sextante/modeler/ModelerAlgorithm.py
  89. +4 −1 src/sextante/modeler/ModelerAlgorithmProvider.py
  90. +2 −1 src/sextante/modeler/ModelerDialog.py
  91. +1 −1 src/sextante/modeler/ModelerGraphicItem.py
  92. +10 −1 src/sextante/modeler/ModelerParametersDialog.py
  93. +3 −2 src/sextante/modeler/ModelerUtils.py
  94. +3 −0 src/sextante/modeler/ProviderIcons.py
  95. +4 −1 src/sextante/outputs/Output.py
  96. +2 −2 src/sextante/outputs/OutputFactory.py
  97. +1 −1 src/sextante/parameters/ParameterBoolean.py
  98. +6 −1 src/sextante/parameters/ParameterFactory.py
  99. +7 −1 src/sextante/parameters/ParameterFixedTable.py
  100. +4 −0 src/sextante/parameters/ParameterMultipleInput.py
  101. +6 −1 src/sextante/parameters/ParameterNumber.py
  102. +5 −1 src/sextante/parameters/ParameterRange.py
  103. +1 −1 src/sextante/parameters/ParameterRaster.py
  104. +10 −1 src/sextante/parameters/ParameterSelection.py
  105. +1 −1 src/sextante/parameters/ParameterTable.py
  106. +1 −1 src/sextante/parameters/ParameterVector.py
  107. +248 −0 src/sextante/r/RAlgorithm.py
  108. +42 −0 src/sextante/r/RAlgorithmProvider.py
  109. +93 −0 src/sextante/r/RUtils.py
  110. 0 src/sextante/r/__init__.py
  111. +9 −0 src/sextante/r/scripts/Compute_Ripley-Rasson_spatial_domain.rsx
  112. +6 −0 src/sextante/r/scripts/Create_random_sampling_grid.rsx
  113. +6 −0 src/sextante/r/scripts/Create_regular_sampling_grid.rsx
  114. +7 −0 src/sextante/r/scripts/F_function_-_distance_from_a_point_to nearest event.rsx
  115. +7 −0 src/sextante/r/scripts/G_function_-_distance to nearest event.rsx
  116. +7 −0 src/sextante/r/scripts/K_function_-_Ripley_K.rsx
  117. +5 −0 src/sextante/r/scripts/Kolmogorov-Smirnov_normality_test.rsx
  118. +10 −0 src/sextante/r/scripts/Quadrat_analysis.rsx
  119. +28 −9 src/sextante/saga/SagaAlgorithm.py
  120. +20 −17 src/sextante/saga/SagaAlgorithmProvider.py
  121. +9 −0 src/sextante/saga/SagaAlgorithmProvider.py.py
  122. +1 −1 src/sextante/saga/SagaUtils.py
  123. +5 −0 src/sextante/script/CreateNewScriptAction.py
  124. +13 −9 src/sextante/script/ScriptAlgorithm.py
  125. +4 −0 src/sextante/script/ScriptAlgorithmProvider.py
  126. +3 −2 src/sextante/script/ScriptUtils.py
@@ -1,4 +1,6 @@
from sextante.core.SextanteConfig import Setting, SextanteConfig
import os
from PyQt4 import QtGui
class AlgorithmProvider():

def __init__(self):
@@ -18,10 +20,16 @@ def loadAlgorithms(self):
else:
self._loadAlgorithms()

#method to be overriden. Algorithm loading should take place here
#methods to be overriden.
#==============================

#Algorithm loading should take place here
def _loadAlgorithms(self):
pass

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

def getSupportedOutputRasterLayerExtensions(self):
return ["tif"]

@@ -111,7 +111,7 @@ def getParameterValue(self, name):
if isinstance(param, ParameterNumber):
return float(param.value)
elif isinstance(param, ParameterBoolean):
return param.value == True
return param.value == str(True)
else:
return param.value
return None
@@ -12,13 +12,15 @@
from sextante.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from sextante.mmqgis.MMQGISAlgorithmProvider import MMQGISAlgorithmProvider
from sextante.ftools.FToolsAlgorithmProvider import FToolsAlgorithmProvider
from sextante.core.SextanteResults import SextanteResults
from sextante.gui.SextantePostprocessing import SextantePostprocessing
from sextante.modeler.ProviderIcons import ProviderIcons
from sextante.r.RAlgorithmProvider import RAlgorithmProvider

class Sextante:

iface = None
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider(),
MMQGISAlgorithmProvider(), FToolsAlgorithmProvider()]
MMQGISAlgorithmProvider(), FToolsAlgorithmProvider(), RAlgorithmProvider()]
algs = {}
actions = {}
contextMenuActions = []
@@ -28,6 +30,13 @@ class Sextante:
def setInterface(iface):
Sextante.iface = iface

@staticmethod
def getProviderFromName(name):
for provider in Sextante.providers:
if provider.getName() == name:
return provider
return Sextante.modeler

@staticmethod
def getInterface():
return Sextante.iface
@@ -40,7 +49,7 @@ def initialize():
Sextante.loadAlgorithms()
Sextante.loadActions()
Sextante.loadContextMenuActions()
SextanteConfig.loadSettings()
#SextanteConfig.loadSettings()


@staticmethod
@@ -79,6 +88,11 @@ def loadAlgorithms():
for alg in providerAlgs:
algs[alg.commandLineName()] = alg
Sextante.algs[provider.getName()] = algs
icons = {}
for provider in Sextante.providers:
icons[provider.getName()] = provider.getIcon()
icons[Sextante.modeler.getName()] = Sextante.modeler.getIcon()
ProviderIcons.providerIcons = icons



@@ -214,7 +228,7 @@ def runandload(name, *args):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
SextanteResults.handleAlgorithmResults(alg)
SextantePostprocessing.handleAlgorithmResults(alg)
except GeoAlgorithmExecutionException, e:
QMessageBox.critical(None, "Error", e.msg)

@@ -66,7 +66,6 @@ def getSetting(name):
return None



class Setting():

def __init__(self, group, name, description, default):
@@ -10,7 +10,10 @@ class SextanteLog():

@staticmethod
def startLogging():
logfile = open(SextanteLog.logFilename(), "w")
if os.path.isfile(SextanteLog.logFilename()):
logfile = open(SextanteLog.logFilename(), "a")
else:
logfile = open(SextanteLog.logFilename(), "w")
logfile.write("Started logging at " + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "\n")
logfile.close()

@@ -1,7 +1,3 @@
from sextante.core.QGisLayers import QGisLayers
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputTable import OutputTable
class SextanteResults():

results = []
@@ -14,21 +10,12 @@ def addResult(name, result):
def getResults():
return SextanteResults.results

@staticmethod
def handleAlgorithmResults(alg):
for out in alg.outputs:
if isinstance(out, (OutputRaster, OutputVector)):
QGisLayers.load(out.value, out.description, alg.crs)
elif isinstance(out, OutputTable):
pass #TODO*****
else:
SextanteResults.addResult(out.description, out.value)

class Result():

def __init__(self, name, value):
def __init__(self, name, filename):
self.name = name
self.value = value
self.filename = filename



@@ -32,8 +32,6 @@ def setTempOutput(out, alg):
SextanteUtils.NUM_EXPORTED += 1




def mkdir(newdir):
if os.path.isdir(newdir):
pass
@@ -7,28 +7,39 @@
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.outputs.OutputVector import OutputVector
from sextante.ftools import ftools_utils
import math
from sextante.outputs.OutputHTML import OutputHTML
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.parameters.ParameterBoolean import ParameterBoolean

class BasicStatisticsAlgorithm(GeoAlgorithm):
class BasicStatistics(GeoAlgorithm):

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

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


def createHTML(self, outputFile, lstStats):
f = open(outputFile, "w")
for s in lstStats:
f.write("<p>" + str(s) + "</p>")
f.close()


def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(CentroidsAlgorithm.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(CentroidsAlgorithm.INPUT))
outputFile = self.getOutputValue(BasicStatistics.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(BasicStatistics.INPUT))
attfield = self.getParameterValue(BasicStatistics.FIELD)
useSelection = self.getParameterValue(BasicStatistics.USE_SELECTION)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
index = vprovider.fieldNameIndex( myField )
index = vprovider.fieldNameIndex(attfield)
feat = QgsFeature()
sumVal = 0.0
meanVal = 0.0
@@ -37,15 +48,12 @@ def processAlgorithm(self, progress):
first = True
nElement = 0
# determine selected field type
if ftools_utils.getFieldType( vlayer, myField ) in ('String', 'varchar', 'char', 'text'):
if ftools_utils.getFieldType( vlayer, attfield ) in ('String', 'varchar', 'char', 'text'):
fillVal = 0
emptyVal = 0
if self.mySelection: # only selected features
if useSelection: # only selected features
selection = vlayer.selectedFeatures()
nFeat = vlayer.selectedFeatureCount()
if nFeat > 0:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for f in selection:
atMap = f.attributeMap()
lenVal = float( len( atMap[ index ].toString() ) )
@@ -63,12 +71,10 @@ def processAlgorithm(self, progress):
values.append( lenVal )
sumVal = sumVal + lenVal
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
progress.setPercentage(int(nElement/nFeat * 100))
else: # there is no selection, process the whole layer
nFeat = vprovider.featureCount()
if nFeat > 0:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
vprovider.select( allAttrs )
while vprovider.nextFeature( feat ):
atMap = feat.attributeMap()
@@ -87,7 +93,7 @@ def processAlgorithm(self, progress):
values.append( lenVal )
sumVal = sumVal + lenVal
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
progress.setPercentage(int(nElement/nFeat * 100))
nVal= float( len( values ) )
if nVal > 0:
meanVal = sumVal / nVal
@@ -98,23 +104,20 @@ def processAlgorithm(self, progress):
lstStats.append( "Filled:" + unicode( fillVal ) )
lstStats.append( "Empty:" + unicode( emptyVal ) )
lstStats.append( "N:" + unicode( nVal ) )
return ( lstStats, [] )
self.createHTML(outputFile, lstStats)
else:
return ( ["Error:No features selected!"], [] )
raise GeoAlgorithmExecutionException("Error:No features selected!")
else: # numeric field
stdVal = 0.00
cvVal = 0.00
rangeVal = 0.00
medianVal = 0.00
maxVal = 0.00
minVal = 0.00
if self.mySelection: # only selected features
if useSelection: # only selected features
selection = vlayer.selectedFeatures()
nFeat = vlayer.selectedFeatureCount()
uniqueVal = ftools_utils.getUniqueValuesCount( vlayer, index, True )
if nFeat > 0:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for f in selection:
atMap = f.attributeMap()
value = float( atMap[ index ].toDouble()[ 0 ] )
@@ -128,13 +131,11 @@ def processAlgorithm(self, progress):
values.append( value )
sumVal = sumVal + value
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
progress.setPercentage(int(nElement/nFeat * 100))
else: # there is no selection, process the whole layer
nFeat = vprovider.featureCount()
uniqueVal = ftools_utils.getUniqueValuesCount( vlayer, index, False )
if nFeat > 0:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
vprovider.select( allAttrs )
while vprovider.nextFeature( feat ):
atMap = feat.attributeMap()
@@ -149,7 +150,6 @@ def processAlgorithm(self, progress):
values.append( value )
sumVal = sumVal + value
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
nVal= float( len( values ) )
if nVal > 0.00:
rangeVal = maxVal - minVal
@@ -177,12 +177,14 @@ def processAlgorithm(self, progress):
lstStats.append( "Number of unique values:" + unicode( uniqueVal ) )
lstStats.append( "Range:" + unicode( rangeVal ) )
lstStats.append( "Median:" + unicode( medianVal ) )
return ( lstStats, [] )
self.createHTML(outputFile, lstStats)
else:
return ( ["Error:No features selected!"], [] )
raise GeoAlgorithmExecutionException("Error:No features selected!")

def defineCharacteristics(self):
self.name = "Basic statistics"
self.group = "Analysis tools"
self.addParameter(ParameterVector(BasicStatisticsAlgorithm.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_POLYGON))
self.addOutput(OutputVector(BasicStatisticsAlgorithm.OUTPUT, "Statistics"))
self.addParameter(ParameterVector(BasicStatistics.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(BasicStatistics.FIELD, "Field", BasicStatistics.INPUT))
self.addParameter(ParameterBoolean(BasicStatistics.USE_SELECTION, "Use selection", False))
self.addOutput(OutputHTML(BasicStatistics.OUTPUT, "Statistics"))

0 comments on commit 562ca20

Please sign in to comment.