Skip to content

Commit 40095a9

Browse files
committedApr 1, 2013
[sextante] more tests. Added extra model and script
1 parent bce0a4c commit 40095a9

File tree

5 files changed

+113
-8
lines changed

5 files changed

+113
-8
lines changed
 
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
NAME:Model with algorithms not in running order
2+
GROUP:[Test algorithms]
3+
PARAMETER:ParameterRaster|RASTERLAYER_RASTER|raster|False
4+
120.0,60.0
5+
VALUE:HARDCODEDPARAMVALUE_MINSLOPE_1===0.01
6+
VALUE:HARDCODEDPARAMVALUE_Method_0===0
7+
VALUE:HARDCODEDPARAMVALUE_STEP_0===1
8+
VALUE:HARDCODEDPARAMVALUE_DOLINEAR _0===True
9+
VALUE:HARDCODEDPARAMVALUE_LINEARTHRS_0===500.0
10+
VALUE:HARDCODEDPARAMVALUE_CONVERGENCE_0===1.0
11+
ALGORITHM:saga:catchmentareaparallel
12+
154.0,415.0
13+
None
14+
1|RESULT
15+
None
16+
None
17+
None
18+
None
19+
-1|HARDCODEDPARAMVALUE_STEP_0
20+
-1|HARDCODEDPARAMVALUE_Method_0
21+
-1|HARDCODEDPARAMVALUE_DOLINEAR _0
22+
-1|HARDCODEDPARAMVALUE_LINEARTHRS_0
23+
None
24+
None
25+
-1|HARDCODEDPARAMVALUE_CONVERGENCE_0
26+
None
27+
None
28+
None
29+
None
30+
None
31+
None
32+
None
33+
None
34+
ALGORITHM:saga:fillsinksplanchondarboux2001
35+
340.0,260.0
36+
None
37+
-1|RASTERLAYER_RASTER
38+
-1|HARDCODEDPARAMVALUE_MINSLOPE_1
39+
None

‎python/plugins/sextante/script/scripts/Save_selected_features.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from qgis.core import *
3333
from PyQt4.QtCore import *
3434
from PyQt4.QtGui import *
35-
from sextante.core.QGisLayers import QGisLayers
3635
from sextante.core.SextanteVectorWriter import SextanteVectorWriter
3736

3837
#Here we define the input and outputs
@@ -46,15 +45,15 @@
4645

4746
#input layers values are always a string with its location.
4847
#That string can be converted into a QGIS object (a QgsVectorLayer in this case))
49-
#using the Sextante.getObjectFromUri() method
50-
vectorLayer = QGisLayers.getObjectFromUri(input)
48+
#using the sextante.getobject() method
49+
vectorLayer = sextante.getobject(input)
5150

5251
#And now we can process
5352

5453
#First we create the output layer.
5554
#To do so, we create a SextanteVectorWriter, that we can later use to add features.
5655
provider = vectorLayer.dataProvider()
57-
writer = SextanteVectorWriter(output, None, provider.fields(), provider.geometryType(), vectorLayer.crs() )
56+
writer = SextanteVectorWriter(output, None, provider.fields(), provider.geometryType(), vectorLayer.crs())
5857

5958
#Now we take the selected features and add them to the output layer
6059
selection = vectorLayer.selectedFeatures()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##input=vector
2+
##output=output vector
3+
from sextante.core.SextanteVectorWriter import SextanteVectorWriter
4+
from qgis.core import *
5+
from PyQt4.QtCore import *
6+
7+
inputLayer = sextante.getobject(input)
8+
features = sextante.getfeatures(inputLayer)
9+
fields = inputLayer.pendingFields().toList()
10+
outputLayer = SextanteVectorWriter(output, None, fields, QGis.WKBPoint, inputLayer.crs())
11+
count = 0
12+
mean = [0 for field in fields]
13+
x = 0
14+
y = 0
15+
for ft in features:
16+
c = ft.geometry().centroid().asPoint()
17+
x += c.x()
18+
y += c.y()
19+
attrs = ft.attributes()
20+
for f in range(len(fields)):
21+
try:
22+
mean[f] += float(attrs[f].toDouble()[0])
23+
except:
24+
pass
25+
count += 1
26+
if count != 0:
27+
mean = [value / count for value in mean]
28+
x /= count
29+
y /= count
30+
outFeat = QgsFeature()
31+
meanPoint = QgsPoint(x, y)
32+
outFeat.setGeometry(QgsGeometry.fromPoint(meanPoint))
33+
outFeat.setAttributes([QVariant(v) for v in mean])
34+
outputLayer.addFeature(outFeat)
35+

‎python/plugins/sextante/tests/ModelerAlgorithmTest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ def test_modelerfieldautoextent(self):
108108
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
109109
self.assertEqual(strhash,2026100494)
110110

111+
def test_modelernotinorder(self):
112+
outputs=sextante.runalg("modeler:notinorder",raster(),None)
113+
output=outputs['CAREA_ALG0']
114+
self.assertTrue(os.path.isfile(output))
115+
dataset=gdal.Open(output, GA_ReadOnly)
116+
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
117+
self.assertEqual(strhash,-1557050506)
111118

112119

113120
def suite():

‎python/plugins/sextante/tests/SagaTest.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,37 @@
22
import unittest
33
from sextante.tests.TestData import points, points2, polygons, polygons2, lines, union,\
44
table, polygonsGeoJson
5+
table, polygonsGeoJson, raster
56
from sextante.core.QGisLayers import QGisLayers
67
from sextante.core.SextanteUtils import SextanteUtils
8+
from osgeo.gdalconst import GA_ReadOnly
9+
import os
10+
from osgeo import gdal
711

812
class SagaTest(unittest.TestCase):
913
'''tests for saga algorithms'''
1014

15+
def test_sagametricconversions(self):
16+
outputs=sextante.runalg("saga:metricconversions",raster(),0,None)
17+
output=outputs['CONV']
18+
self.assertTrue(os.path.isfile(output))
19+
dataset=gdal.Open(output, GA_ReadOnly)
20+
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
21+
self.assertEqual(strhash,-2137931723)
22+
23+
def test_sagasortgrid(self):
24+
outputs=sextante.runalg("saga:sortgrid",raster(),True,None)
25+
output=outputs['OUTPUT']
26+
self.assertTrue(os.path.isfile(output))
27+
dataset=gdal.Open(output, GA_ReadOnly)
28+
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
29+
self.assertEqual(strhash,1320073153)
1130

12-
'''the following tests are not meant to test the algorithms themselves,
13-
but the algorithm provider, testing things such as the file conversion,
31+
'''the following tests are not meant to test the algorithms themselves,
32+
but the algorithm provider, testing things such as the file conversion,
1433
the selection awareness of SAGA process, etc'''
1534

16-
def test_SagaVvectorAlgorithmWithSelection(self):
35+
def test_SagaVectorAlgorithmWithSelection(self):
1736
layer = sextante.getobject(polygons2());
1837
feature = layer.getFeatures().next()
1938
selected = [feature.id()]
@@ -63,7 +82,13 @@ def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self):
6382
self.assertEqual(expectedvalues, values)
6483
wkt='POINT(270787.49991451 4458955.46775295)'
6584
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
66-
85+
def test_SagaRasterAlgorithmWithUnsupportedOutputFormat(self):
86+
outputs=sextante.runalg("saga:convergenceindex",raster(),0,0,None)
87+
output=outputs['RESULT']
88+
self.assertTrue(os.path.isfile(output))
89+
dataset=gdal.Open(output, GA_ReadOnly)
90+
strhash=hash(str(dataset.ReadAsArray(0).tolist()))
91+
self.assertEqual(strhash,485390137)
6792

6893

6994

0 commit comments

Comments
 (0)
Please sign in to comment.