Skip to content

Commit 792a252

Browse files
committedJun 27, 2017
Fix script algorithm centroids tests
1 parent 96c5453 commit 792a252

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed
 

‎python/plugins/processing/tests/testdata/script_algorithm_tests.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
tests:
44

5-
# - algorithm: script:centroids
6-
# name: Centroids script test
7-
# params:
8-
# INPUT_LAYER:
9-
# name: polys.gml
10-
# type: vector
11-
# results:
12-
# OUTPUT_LAYER:
13-
# name: expected/centroid_polys.gml
14-
# type: vector
15-
# compare:
16-
# geometry:
17-
# precision: 7
5+
- algorithm: script:centroids
6+
name: Centroids script test
7+
params:
8+
INPUT_LAYER:
9+
name: polys.gml
10+
type: vector
11+
results:
12+
OUTPUT_LAYER:
13+
name: expected/centroid_polys.gml
14+
type: vector
15+
compare:
16+
geometry:
17+
precision: 7
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
##Centroids=name
22
##Geometry=group
3-
##INPUT_LAYER=vector
4-
##OUTPUT_LAYER=output vector
3+
4+
#inputs
5+
6+
##INPUT_LAYER=source
7+
##OUTPUT_LAYER=sink point
8+
9+
#outputs
10+
11+
##OUTPUT_LAYER=output outputVector
512

613
from qgis.core import QgsWkbTypes, QgsProcessingUtils
714

8-
layer = QgsProcessingUtils.mapLayerFromString(INPUT_LAYER, context)
9-
fields = layer.fields()
15+
fields = INPUT_LAYER.fields()
1016

11-
writer, writer_dest = QgsProcessingUtils.createFeatureSink(OUTPUT_LAYER, context, fields, QgsWkbTypes.Point, layer.crs(), {'fileEncoding': 'utf-8'})
17+
(sink, OUTPUT_LAYER) = self.parameterAsSink(parameters, 'OUTPUT_LAYER', context,
18+
fields, QgsWkbTypes.Point, INPUT_LAYER.sourceCrs())
1219

13-
features = QgsProcessingUtils.getFeatures(layer, context)
14-
count = QgsProcessingUtils.featureCount(layer, context)
20+
features = INPUT_LAYER.getFeatures()
21+
count = INPUT_LAYER.featureCount()
1522
if count == 0:
1623
raise GeoAlgorithmExecutionException('Input layer contains no features.')
1724

@@ -23,5 +30,5 @@
2330
outputGeometry = f.geometry().centroid()
2431
outputFeature.setGeometry(outputGeometry)
2532

26-
writer.addFeature(outputFeature)
33+
sink.addFeature(outputFeature)
2734
feedback.setProgress(int(count * total))

0 commit comments

Comments
 (0)