-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
committed
Jul 26, 2012
1 parent
3acf6cd
commit 488c939
Showing
3 changed files
with
99 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |