77 changes: 77 additions & 0 deletions python/plugins/sextante/algs/RasterLayerHistogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
RasterLayerHistogram.py
---------------------
Date : January 2013
Copyright : (C) 2013 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'January 2013'
__copyright__ = '(C) 2013, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from sextante.outputs.OutputTable import OutputTable
import matplotlib.pyplot as plt
import matplotlib.pylab as lab
from PyQt4.QtCore import *
from qgis.core import *
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.outputs.OutputHTML import OutputHTML
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.tools import raster

class RasterLayerHistogram(GeoAlgorithm):

INPUT = "INPUT"
PLOT = "PLOT"
TABLE = "TABLE"
BINS = "BINS"


def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
outputplot = self.getOutputValue(self.PLOT)
outputtable = self.getOutputFromName(self.TABLE)
values = raster.scanraster(layer, progress)
nbins = self.getParameterValue(self.BINS)
#ALERT:this is potentially blocking if the layer is too big
plt.close()
valueslist = []
for v in values:
if v is not None:
valueslist.append(v)
n, bins, values = plt.hist(valueslist, nbins)
fields = [QgsField("CENTER_VALUE", QVariant.Double), QgsField("NUM_ELEM", QVariant.Double)]
writer = outputtable.getTableWriter(fields)
for i in xrange(len(values)):
writer.addRecord([str(bins[i]) + "-" + str(bins[i+1]) , n[i]])
plotFilename = outputplot +".png"
lab.savefig(plotFilename)
f = open(outputplot, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()

def defineCharacteristics(self):
self.name = "Raster layer histogram"
self.group = "Graphics"
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addParameter(ParameterNumber(self.BINS, "Number of bins", 2, None, 10))
self.addOutput(OutputHTML(self.PLOT, "Output plot"))
self.addOutput(OutputTable(self.TABLE, "Output table"))

120 changes: 120 additions & 0 deletions python/plugins/sextante/algs/RasterLayerStatistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
RasterLayerStatistics.py
---------------------
Date : January 2013
Copyright : (C) 2013 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'January 2013'
__copyright__ = '(C) 2013, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import math
from PyQt4.QtCore import *
from qgis.core import *
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.tools import raster
from sextante.outputs.OutputNumber import OutputNumber
from sextante.outputs.OutputHTML import OutputHTML

class RasterLayerStatistics(GeoAlgorithm):

INPUT = "INPUT"

MIN = "MIN"
MAX = "MAX"
SUM = "SUM"
MEAN = "MEAN"
COUNT = "COUNT"
NO_DATA_COUNT = "NO_DATA_COUNT"
STD_DEV = "STD_DEV"
OUTPUT_HTML_FILE = "OUTPUT_HTML_FILE"

def processAlgorithm(self, progress):
outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
values = raster.scanraster(layer, progress)

n = 0
nodata = 0
mean = 0
M2 = 0
sum = 0
minvalue = None
maxvalue = None

for v in values:
if v is not None:
sum += v
n = n + 1
delta = v - mean
mean = mean + delta/n
M2 = M2 + delta*(v - mean)
if minvalue is None:
minvalue = v
maxvalue = v
else:
minvalue = min(v, minvalue)
maxvalue = max(v, maxvalue)
else:
nodata += 1

variance = M2/(n - 1)
stddev = math.sqrt(variance)

data = []
data.append("Valid cells: " + unicode(n))
data.append("No-data cells: " + unicode(nodata))
data.append("Minimum value: " + unicode(minvalue))
data.append("Maximum value: " + unicode(maxvalue))
data.append("Sum: " + unicode(sum))
data.append("Mean value: " + unicode(mean))
data.append("Standard deviation: " + unicode(stddev))

self.createHTML(outputFile, data)

self.setOutputValue(self.COUNT, n)
self.setOutputValue(self.NO_DATA_COUNT, nodata)
self.setOutputValue(self.MIN, minvalue)
self.setOutputValue(self.MAX, maxvalue)
self.setOutputValue(self.SUM, sum)
self.setOutputValue(self.MEAN, mean)
self.setOutputValue(self.STD_DEV, stddev)


def defineCharacteristics(self):
self.name = "Raster layer statistics"
self.group = "Raster tools"
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE, "Statistics"))
self.addOutput(OutputNumber(self.MIN, "Minimum value"))
self.addOutput(OutputNumber(self.MAX, "Maximum value"))
self.addOutput(OutputNumber(self.SUM, "Sum"))
self.addOutput(OutputNumber(self.MEAN, "Mean value"))
self.addOutput(OutputNumber(self.COUNT, "valid cells count"))
self.addOutput(OutputNumber(self.COUNT, "No-data cells count"))
self.addOutput(OutputNumber(self.STD_DEV, "Standard deviation"))

def createHTML(self, outputFile, algData):
f = open(outputFile, "w")
for s in algData:
f.write("<p>" + str(s) + "</p>")
f.close()
4 changes: 0 additions & 4 deletions python/plugins/sextante/algs/SaveSelectedFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def defineCharacteristics(self):
# we add a vector layer as output
self.addOutput(OutputVector(self.OUTPUT_LAYER, "Output layer with selected features"))

#===========================================================================
# def getIcon(self):
# return QIcon(os.path.dirname(__file__) + "/../images/qgis.png")
#===========================================================================

def processAlgorithm(self, progress):
'''Here is where the processing itself takes place'''
Expand Down
82 changes: 82 additions & 0 deletions python/plugins/sextante/algs/StatisticsByCategories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
StatisticsByCategories.py
---------------------
Date : September 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
import math

__author__ = 'Victor Olaya'
__date__ = 'September 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from qgis.core import *
from scipy import stats
from sextante.outputs.OutputTable import OutputTable
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField

class StatisticsByCategories(GeoAlgorithm):

INPUT_LAYER = "INPUT_LAYER"
VALUES_FIELD_NAME = "VALUES_FIELD_NAME"
CATEGORIES_FIELD_NAME = "CATEGORIES_FIELD_NAME"
OUTPUT = "OUTPUT"

def defineCharacteristics(self):
self.name = "Statistics by categories"
self.group = "Vector table tools"

self.addParameter(ParameterVector(self.INPUT_LAYER, "Input vector layer", ParameterVector.VECTOR_TYPE_ANY, False))
self.addParameter(ParameterTableField(self.VALUES_FIELD_NAME, "Field to calculate statistics on",
self.INPUT_LAYER, ParameterTableField.DATA_TYPE_NUMBER))
self.addParameter(ParameterTableField(self.CATEGORIES_FIELD_NAME, "Field with categories",
self.INPUT_LAYER, ParameterTableField.DATA_TYPE_ANY))

self.addOutput(OutputTable(self.OUTPUT, "Statistics for numeric field"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
valuesFieldName = self.getParameterValue(self.VALUES_FIELD_NAME)
categoriesFieldName = self.getParameterValue(self.CATEGORIES_FIELD_NAME)

output = self.getOutputFromName(self.OUTPUT)
valuesField = layer.fieldNameIndex(valuesFieldName)
categoriesField = layer.fieldNameIndex(categoriesFieldName)

features = QGisLayers.features(layer)
nFeat = len(features)
values = {}
for feat in features:
attrs = feat.attributes()
value = float(attrs[valuesField].toDouble()[0])
cat = unicode(attrs[categoriesField].toString())
if cat not in values:
values[cat] = []
values[cat].append(value)

fields = [QgsField("category", QVariant.String), QgsField("mean", QVariant.Double), QgsField("variance", QVariant.Double)]
writer = output.getTableWriter(fields)
for cat, value in values.items():
n, min_max, mean, var, skew, kurt = stats.describe(value)
record = [cat, mean, math.sqrt(var)]
writer.addRecord(record)


68 changes: 68 additions & 0 deletions python/plugins/sextante/algs/VectorLayerHistogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
EquivalentNumField.py
---------------------
Date : January 2013
Copyright : (C) 2013 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'January 2013'
__copyright__ = '(C) 2013, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import matplotlib.pyplot as plt
import matplotlib.pylab as lab
from PyQt4.QtCore import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.outputs.OutputHTML import OutputHTML
from sextante.tools import *
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterNumber import ParameterNumber

class VectorLayerHistogram(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
FIELD = "FIELD"
BINS = "BINS"


def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
fieldname = self.getParameterValue(self.FIELD)
output = self.getOutputValue(self.OUTPUT)
values = vector.getAttributeValues(layer, fieldname)
plt.close()
bins = self.getParameterValue(self.BINS)
plt.hist(values[fieldname], bins)
plotFilename = output +".png"
lab.savefig(plotFilename)
f = open(output, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()

def defineCharacteristics(self):
self.name = "Vector layer histogram"
self.group = "Graphics"
self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(self.FIELD, "Attribute", self.INPUT,ParameterTableField.DATA_TYPE_NUMBER))
self.addParameter(ParameterNumber(self.BINS, "number of bins", 2, None, 10))
self.addOutput(OutputHTML(self.OUTPUT, "Output"))

69 changes: 69 additions & 0 deletions python/plugins/sextante/algs/VectorLayerScatterplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
EquivalentNumField.py
---------------------
Date : January 2013
Copyright : (C) 2013 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
from sextante.parameters.ParameterNumber import ParameterNumber

__author__ = 'Victor Olaya'
__date__ = 'January 2013'
__copyright__ = '(C) 2013, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import matplotlib.pyplot as plt
import matplotlib.pylab as lab
from PyQt4.QtCore import *
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.outputs.OutputHTML import OutputHTML
from sextante.tools import *
from sextante.core.QGisLayers import QGisLayers

class VectorLayerScatterplot(GeoAlgorithm):

INPUT = "INPUT"
OUTPUT = "OUTPUT"
XFIELD = "XFIELD"
YFIELD = "YFIELD"


def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
xfieldname = self.getParameterValue(self.YFIELD)
yfieldname = self.getParameterValue(self.XFIELD)
output = self.getOutputValue(self.OUTPUT)
values = vector.getAttributeValues(layer, xfieldname, yfieldname)
plt.close()

plt.scatter(values[xfieldname], values[yfieldname])
plotFilename = output +".png"
lab.savefig(plotFilename)
f = open(output, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()

def defineCharacteristics(self):
self.name = "Vector layer scatterplot"
self.group = "Graphics"
self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
self.addParameter(ParameterTableField(self.XFIELD, "X attribute", self.INPUT,ParameterTableField.DATA_TYPE_NUMBER))
self.addParameter(ParameterTableField(self.YFIELD, "Y attribute", self.INPUT,ParameterTableField.DATA_TYPE_NUMBER))
self.addOutput(OutputHTML(self.OUTPUT, "Output"))

45 changes: 19 additions & 26 deletions python/plugins/sextante/algs/ftools/BasicStatisticsNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path
import math

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

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

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

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

Expand All @@ -48,17 +40,18 @@ class BasicStatisticsNumbers(GeoAlgorithm):
INPUT_LAYER = "INPUT_LAYER"
FIELD_NAME = "FIELD_NAME"
OUTPUT_HTML_FILE = "OUTPUT_HTML_FILE"

CV = "CV"
MIN = "MIN"
MAX = "MAX"
SUM = "SUM"
MEAN = "MEAN"
COUNT = "COUNT"
COUNT = "COUNT"
STD_DEV = "STD_DEV"
RANGE = "RANGE"
MEDIAN = "MEDIAN"
UNIQUE = "UNIQUE"
STD_DEV = "STD_DEV"


#===========================================================================
# def getIcon(self):
Expand All @@ -70,7 +63,8 @@ def defineCharacteristics(self):
self.group = "Vector table tools"

self.addParameter(ParameterVector(self.INPUT_LAYER, "Input vector layer", ParameterVector.VECTOR_TYPE_ANY, False))
self.addParameter(ParameterTableField(self.FIELD_NAME, "Field to calculate statistics on", self.INPUT_LAYER, ParameterTableField.DATA_TYPE_NUMBER))
self.addParameter(ParameterTableField(self.FIELD_NAME, "Field to calculate statistics on",
self.INPUT_LAYER, ParameterTableField.DATA_TYPE_NUMBER))

self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE, "Statistics for numeric field"))

Expand Down Expand Up @@ -111,7 +105,6 @@ def processAlgorithm(self, progress):
current = 0
for ft in features:
value = float(ft.attributes()[index].toDouble()[0])

if isFirst:
minValue = value
maxValue = value
Expand All @@ -133,21 +126,21 @@ def processAlgorithm(self, progress):
uniqueValue = utils.getUniqueValuesCount(layer, index)

if count > 0:
meanValue = sumValue / count
if meanValue != 0.00:
for v in values:
stdDevValue += ((v - meanValue) * (v - meanValue))
stdDevValue = math.sqrt(stdDevValue / count)
cvValue = stdDevValue / meanValue
meanValue = sumValue / count
if meanValue != 0.00:
for v in values:
stdDevValue += ((v - meanValue) * (v - meanValue))
stdDevValue = math.sqrt(stdDevValue / count)
cvValue = stdDevValue / meanValue

if count > 1:
tmp = values
tmp.sort()
# calculate median
if (count % 2) == 0:
medianValue = 0.5 * (tmp[(count - 1) / 2] + tmp[count / 2])
else:
medianValue = tmp[(count + 1) / 2 - 1]
tmp = values
tmp.sort()
# calculate median
if (count % 2) == 0:
medianValue = 0.5 * (tmp[(count - 1) / 2] + tmp[count / 2])
else:
medianValue = tmp[(count + 1) / 2 - 1]

data = []
data.append("Count: " + unicode(count))
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,55 @@

#Algorithm body
#==================================
from sextante.core.QGisLayers import QGisLayers
from qgis.core import *
from PyQt4.QtCore import *
from sextante.core.SextanteVectorWriter import SextanteVectorWriter

# "input" contains the location of the selected layer.
# We get the actual object, so we can get its bounds
layer = QGisLayers.getObjectFromUri(input)
layer = getobject(input)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
fields = provider.fields()
fields[len(fields)] = QgsField("UNIQ_COUNT", QVariant.Int)
fields.append(QgsField("UNIQ_COUNT", QVariant.Int))
writer = SextanteVectorWriter(output, None, fields, provider.geometryType(), provider.crs() )

# Fields are defined by their names, but QGIS needs the index for the attributes map
class_field_index = provider.fieldNameIndex(class_field)
value_field_index = provider.fieldNameIndex(value_field)
class_field_index = layer.fieldNameIndex(class_field)
value_field_index = layer.fieldNameIndex(value_field)

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = provider.featureCount()
nElement = 0
classes = {}

#Iterate over input layer to count unique values in each class
while provider.nextFeature(inFeat):
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = inFeat.attributeMap()
clazz = atMap[class_field_index].toString()
value = atMap[value_field_index].toString()
if clazz not in classes:
classes[clazz] = []
if value not in classes[clazz]:
classes[clazz].append(value)

feats = getfeatures(layer)
nFeat = len(feates)
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
attrs = inFeat.attributes()
clazz = attrs[class_field_index].toString()
value = attrs[value_field_index].toString()
if clazz not in classes:
classes[clazz] = []
if value not in classes[clazz]:
classes[clazz].append(value)

# Create output vector layer with additional attribute
while provider.nextFeature(inFeat):
print int((500 * nElement)/nFeat)
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
clazz = atMap[class_field_index].toString()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(provider.fields()), QVariant(len(classes[clazz])))
writer.addFeature( outFeat )
feats = getfeatures(layer)
nElement = 0
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
attrs = inFeat.attributes()
clazz = attrs[class_field_index].toString()
attrs.append(QVariant(len(classes[clazz])))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)

del writer
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@

#Algorithm body
#==================================
from sextante.core.QGisLayers import QGisLayers
from qgis.core import *
from PyQt4.QtCore import *
from sextante.core.SextanteVectorWriter import SextanteVectorWriter

# "input" contains the location of the selected layer.
# We get the actual object,
layer = QGisLayers.getObjectFromUri(input)
layer = getobject(input)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
fields = provider.fields()
writers = {}

# Fields are defined by their names, but QGIS needs the index for the attributes map
class_field_index = provider.fieldNameIndex(class_field)
class_field_index = layer.fieldNameIndex(class_field)

inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = provider.featureCount()
nElement = 0
writers = {}

while provider.nextFeature(inFeat):
feats = getfeatures(layer)
nFeat = len(feats)
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
atMap = inFeat.attributeMap()
atMap = inFeat.attributes()
clazz = atMap[class_field_index].toString()
if clazz not in writers:
outputFile = output + "_" + str(len(writers)) + ".shp"
writers[clazz] = SextanteVectorWriter(outputFile, None, fields, provider.geometryType(), provider.crs() )
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
outFeat.setAttributeMap(atMap)
outFeat.setAttributes(atMap)
writers[clazz].addFeature(outFeat)


Expand Down
2 changes: 2 additions & 0 deletions python/plugins/sextante/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from sextante.tools.vector import getAttributeValues
from sextante.tools.raster import scanraster
17 changes: 17 additions & 0 deletions python/plugins/sextante/tools/raster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from osgeo import gdal
from gdalconst import *
import struct

def scanraster(layer, progress):
filename = unicode(layer.source())
dataset = gdal.Open(filename, GA_ReadOnly)
band = dataset.GetRasterBand(1)
nodata = band.GetNoDataValue()
for y in xrange(band.YSize):
progress.setPercentage(y / float(band.YSize) * 100)
scanline = band.ReadRaster(0, y, band.XSize, 1,band.XSize, 1, band.DataType)
values = struct.unpack('f' * band.XSize, scanline)
for value in values:
if value == nodata:
value = None
yield value
21 changes: 21 additions & 0 deletions python/plugins/sextante/tools/vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sextante.core.QGisLayers import QGisLayers


def getAttributeValues(layer, *attributeNames):
ret = {}
for name in attributeNames:
values = []
features = QGisLayers.features(layer)
index = layer.fieldNameIndex(name)
if index == -1:
raise ValueError('Wrong field name')
for feature in features:
try:
v = float(feature.attributes()[index].toString())
values.append(v)
except:
values.append(None)
ret[name] = values;
return ret


2 changes: 1 addition & 1 deletion python/plugins/sextante/ui/ui_DlgHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class Ui_DlgHistory(object):
def setupUi(self, DlgHistory):
DlgHistory.setObjectName(_fromUtf8("DlgHistory"))
DlgHistory.resize(532, 377)
DlgHistory.resize(800, 600)
self.verticalLayout = QtGui.QVBoxLayout(DlgHistory)
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/ui/ui_SextanteToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setupUi(self, SextanteToolbox):

def retranslateUi(self, SextanteToolbox):
SextanteToolbox.setWindowTitle(QtGui.QApplication.translate("SextanteToolbox", "SEXTANTE Toolbox", None, QtGui.QApplication.UnicodeUTF8))
self.externalAppsButton.setText(QtGui.QApplication.translate("SextanteToolbox", "Click here to configure\n"
"additional algorithm providers", None, QtGui.QApplication.UnicodeUTF8))
self.externalAppsButton.setText(QtGui.QApplication.translate("SextanteToolbox", "Click here to learn\n"
"more about SEXTANTE!", None, QtGui.QApplication.UnicodeUTF8))
self.searchBox.setToolTip(QtGui.QApplication.translate("SextanteToolbox", "Enter algorithm name to filter list", None, QtGui.QApplication.UnicodeUTF8))