Skip to content
Permalink
Browse files

Fix script algorithm centroids tests

  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent 96c5453 commit 792a252ef8d8654816422fd5d7884650a93fe75c
@@ -2,16 +2,16 @@

tests:

# - algorithm: script:centroids
# name: Centroids script test
# params:
# INPUT_LAYER:
# name: polys.gml
# type: vector
# results:
# OUTPUT_LAYER:
# name: expected/centroid_polys.gml
# type: vector
# compare:
# geometry:
# precision: 7
- algorithm: script:centroids
name: Centroids script test
params:
INPUT_LAYER:
name: polys.gml
type: vector
results:
OUTPUT_LAYER:
name: expected/centroid_polys.gml
type: vector
compare:
geometry:
precision: 7
@@ -1,17 +1,24 @@
##Centroids=name
##Geometry=group
##INPUT_LAYER=vector
##OUTPUT_LAYER=output vector

#inputs

##INPUT_LAYER=source
##OUTPUT_LAYER=sink point

#outputs

##OUTPUT_LAYER=output outputVector

from qgis.core import QgsWkbTypes, QgsProcessingUtils

layer = QgsProcessingUtils.mapLayerFromString(INPUT_LAYER, context)
fields = layer.fields()
fields = INPUT_LAYER.fields()

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

features = QgsProcessingUtils.getFeatures(layer, context)
count = QgsProcessingUtils.featureCount(layer, context)
features = INPUT_LAYER.getFeatures()
count = INPUT_LAYER.featureCount()
if count == 0:
raise GeoAlgorithmExecutionException('Input layer contains no features.')

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

writer.addFeature(outputFeature)
sink.addFeature(outputFeature)
feedback.setProgress(int(count * total))

0 comments on commit 792a252

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