Skip to content

Commit

Permalink
Fix script algorithm centroids tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent 96c5453 commit 792a252
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 15 additions & 8 deletions python/plugins/processing/tests/testdata/scripts/centroids.py
Original file line number Diff line number Diff line change
@@ -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.')

Expand All @@ -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.