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.
Expand Up @@ -2,16 +2,16 @@


tests: tests:


# - algorithm: script:centroids - algorithm: script:centroids
# name: Centroids script test name: Centroids script test
# params: params:
# INPUT_LAYER: INPUT_LAYER:
# name: polys.gml name: polys.gml
# type: vector type: vector
# results: results:
# OUTPUT_LAYER: OUTPUT_LAYER:
# name: expected/centroid_polys.gml name: expected/centroid_polys.gml
# type: vector type: vector
# compare: compare:
# geometry: geometry:
# precision: 7 precision: 7
23 changes: 15 additions & 8 deletions python/plugins/processing/tests/testdata/scripts/centroids.py
@@ -1,17 +1,24 @@
##Centroids=name ##Centroids=name
##Geometry=group ##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 from qgis.core import QgsWkbTypes, QgsProcessingUtils


layer = QgsProcessingUtils.mapLayerFromString(INPUT_LAYER, context) fields = INPUT_LAYER.fields()
fields = 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) features = INPUT_LAYER.getFeatures()
count = QgsProcessingUtils.featureCount(layer, context) count = INPUT_LAYER.featureCount()
if count == 0: if count == 0:
raise GeoAlgorithmExecutionException('Input layer contains no features.') raise GeoAlgorithmExecutionException('Input layer contains no features.')


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


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

0 comments on commit 792a252

Please sign in to comment.