Skip to content
Permalink
Browse files

reorganize imports

add List Unique Values tool


git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@310 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
alexander.bruy@gmail.com
alexander.bruy@gmail.com committed Jul 26, 2012
1 parent 3acf6cd commit 488c9396bd80265ea65b9f16a4ef4e29804e7051
@@ -1,49 +1,67 @@
from sextante.core.AlgorithmProvider import AlgorithmProvider

import os

from PyQt4 import QtGui
from sextante.ftools.Centroids import Centroids

from sextante.core.AlgorithmProvider import AlgorithmProvider

# analysis tools
from sextante.ftools.SumLines import SumLines
from sextante.ftools.MeanCoords import MeanCoords
from sextante.ftools.UniqueValues import UniqueValues
from sextante.ftools.BasicStatistics import BasicStatistics
from sextante.ftools.PointsInPolygon import PointsInPolygon
from sextante.ftools.LinesIntersection import LinesIntersection
from sextante.ftools.NearestNeighbourAnalysis import NearestNeighbourAnalysis

# data management tools

# geometry tools
from sextante.ftools.Delaunay import Delaunay
from sextante.ftools.SimplifyGeometries import SimplifyGeometries
from sextante.ftools.VoronoiPolygons import VoronoiPolygons
from sextante.ftools.ExportGeometryInfo import ExportGeometryInfo
from sextante.ftools.Centroids import Centroids
from sextante.ftools.ExtractNodes import ExtractNodes
from sextante.ftools.VoronoiPolygons import VoronoiPolygons
from sextante.ftools.LinesToPolygons import LinesToPolygons
from sextante.ftools.PolygonsToLines import PolygonsToLines
from sextante.ftools.SimplifyGeometries import SimplifyGeometries
from sextante.ftools.ExportGeometryInfo import ExportGeometryInfo
from sextante.ftools.MultipartToSingleparts import MultipartToSingleparts
from sextante.ftools.SinglePartsToMultiparts import SinglePartsToMultiparts
from sextante.ftools.BasicStatistics import BasicStatistics
from sextante.ftools.PointsInPolygon import PointsInPolygon
from sextante.ftools.SumLines import SumLines
from sextante.ftools.MeanCoords import MeanCoords
from sextante.ftools.NearestNeighbourAnalysis import NearestNeighbourAnalysis
from sextante.ftools.LinesIntersection import LinesIntersection
from sextante.ftools.ConvexHull import ConvexHull
from sextante.ftools.FixedDistanceBuffer import FixedDistanceBuffer
from sextante.ftools.VariableDistanceBuffer import VariableDistanceBuffer

# geoprocessing tools
from sextante.ftools.Clip import Clip
from sextante.ftools.Union import Union
from sextante.ftools.Dissolve import Dissolve
from sextante.ftools.ConvexHull import ConvexHull
from sextante.ftools.Difference import Difference
from sextante.ftools.Intersection import Intersection
from sextante.ftools.Union import Union
from sextante.ftools.Clip import Clip
from sextante.ftools.FixedDistanceBuffer import FixedDistanceBuffer
from sextante.ftools.VariableDistanceBuffer import VariableDistanceBuffer

# research tools
from sextante.ftools.ExtentFromLayer import ExtentFromLayer
from sextante.ftools.RandomSelection import RandomSelection
from sextante.ftools.SelectByLocation import SelectByLocation
from sextante.ftools.RandomSelectionWithinSubsets import RandomSelectionWithinSubsets
from sextante.ftools.MultipartToSingleparts import MultipartTosingleparts

class FToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.alglist = [SinglePartsToMultiparts(), PolygonsToLines(),
LinesToPolygons(), ExportGeometryInfo(), ExtractNodes(),
Centroids(), SimplifyGeometries(), Delaunay(), VoronoiPolygons(),
SumLines(), BasicStatistics(), PointsInPolygon(),
NearestNeighbourAnalysis(), MeanCoords(), LinesIntersection(),
ConvexHull(), FixedDistanceBuffer(), VariableDistanceBuffer(),
Dissolve(), Difference(), Intersection(), Union(), Clip(), ExtentFromLayer(),
RandomSelection(), RandomSelectionWithinSubsets(), SelectByLocation(),
MultipartTosingleparts()]
self.alglist = [SumLines(), PointsInPolygon(), BasicStatistics(),
NearestNeighbourAnalysis(), MeanCoords(), LinesIntersection(),
UniqueValues(),
# data management
# geometry
ExportGeometryInfo(), Centroids(), Delaunay(), VoronoiPolygons(),
SimplifyGeometries(), MultipartToSingleparts(), SinglePartsToMultiparts(),
PolygonsToLines(), LinesToPolygons(), ExtractNodes(),
# geoprocessing
ConvexHull(), FixedDistanceBuffer(), VariableDistanceBuffer(),
Dissolve(), Difference(), Intersection(), Union(), Clip(),
# research
ExtentFromLayer(), RandomSelection(), RandomSelectionWithinSubsets(),
SelectByLocation()
]

def getDescription(self):
return "fTools (Vector analysis)"
@@ -57,6 +75,5 @@ def getIcon(self):
def _loadAlgorithms(self):
self.algs = self.alglist


def getSupportedOutputTableExtensions(self):
return ["csv"]
@@ -9,7 +9,7 @@
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.outputs.OutputVector import OutputVector

class MultipartTosingleparts(GeoAlgorithm):
class MultipartToSingleparts(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
@@ -0,0 +1,53 @@
import os.path

from PyQt4 import QtGui

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField

from sextante.outputs.OutputHTML import OutputHTML
from sextante.outputs.OutputNumber import OutputNumber

from sextante.ftools import ftools_utils

class UniqueValues(GeoAlgorithm):

INPUT_LAYER = "INPUT_LAYER"
FIELD_NAME = "FIELD_NAME"
TOTAL_VALUES = "TOTAL_VALUES"
OUTPUT = "OUTPUT"

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

def defineCharacteristics(self):
self.name = "List unique values"
self.group = "Analysis tools"
self.addParameter(ParameterVector(UniqueValues.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(UniqueValues.FIELD_NAME, "Targer field", UniqueValues.INPUT_LAYER, ParameterTableField.DATA_TYPE_ANY))
self.addOutput(OutputHTML(UniqueValues.OUTPUT, "Unique values"))
self.addOutput(OutputNumber(UniqueValues.TOTAL_VALUES, "Total unique values"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(UniqueValues.INPUT_LAYER))
fieldName = self.getParameterValue(UniqueValues.FIELD_NAME)

outputFile = self.getOutputValue(UniqueValues.OUTPUT)

values = layer.uniqueValues(layer.fieldNameIndex(fieldName))
self.createHTML(outputFile, values)
self.setOutputValue(UniqueValues.TOTAL_VALUES, len(values))

def createHTML(self, outputFile, algData):
f = open(outputFile, "w")
f.write("<p>Total unique values: " + str(len(algData)) + "</p>")
f.write("<p>Unique values:</p>")
f.write("<ul>")
for s in algData:
f.write("<li>" + unicode(s.toString()) + "</li>")
f.write("</ul>")
f.close()

0 comments on commit 488c939

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