11import os .path
2+
23from PyQt4 import QtGui
34from PyQt4 .QtCore import *
5+
46from qgis .core import *
7+
58from sextante .core .GeoAlgorithm import GeoAlgorithm
69from sextante .core .QGisLayers import QGisLayers
710from sextante .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -21,26 +24,30 @@ def defineCharacteristics(self):
2124 self .name = "Polygon centroids"
2225 self .group = "Geometry tools"
2326
24- self .addParameter (ParameterVector (Centroids .INPUT_LAYER , "Input layer" , ParameterVector .VECTOR_TYPE_POLYGON ))
27+ self .addParameter (ParameterVector (self .INPUT_LAYER , "Input layer" , ParameterVector .VECTOR_TYPE_POLYGON ))
2528
26- self .addOutput (OutputVector (Centroids .OUTPUT_LAYER , "Output layer" ))
29+ self .addOutput (OutputVector (self .OUTPUT_LAYER , "Output layer" ))
2730
2831 def processAlgorithm (self , progress ):
29- layer = QGisLayers .getObjectFromUri (self .getParameterValue (Centroids .INPUT_LAYER ))
32+ layer = QGisLayers .getObjectFromUri (self .getParameterValue (self .INPUT_LAYER ))
3033
31- provider = layer . dataProvider ( )
34+ outFileName = self . getOutputValue ( self . OUTPUT_LAYER )
3235
33- writer = self . getOutputFromName ( Centroids . OUTPUT_LAYER ). getVectorWriter ( provider . fields (),
34- QGis . WKBPoint , provider . crs () )
36+ settings = QSettings ()
37+ encoding = settings . value ( "/UI/encoding" , "System" ). toString ( )
3538
36- allAttrs = provider .attributeIndexes ()
37- provider .select (allAttrs )
39+ writer = self .getOutputFromName (self .OUTPUT_LAYER ).getVectorWriter (layer .pendingFields (),
40+ QGis .WKBPoint , layer .dataProvider ().crs ())
41+
42+ layer .select (layer .pendingAllAttributesList ())
3843
3944 inFeat = QgsFeature ()
4045 outFeat = QgsFeature ()
41- total = provider .featureCount ()
46+
47+ total = 100.0 / float (layer .featureCount ())
4248 current = 0
43- while provider .nextFeature (inFeat ):
49+
50+ while layer .nextFeature (inFeat ):
4451 inGeom = inFeat .geometry ()
4552 attrMap = inFeat .attributeMap ()
4653
@@ -52,6 +59,6 @@ def processAlgorithm(self, progress):
5259 outFeat .setAttributeMap (attrMap )
5360 writer .addFeature (outFeat )
5461 current += 1
55- progress .setPercentage (int (current / total * 100 ))
62+ progress .setPercentage (int (current * total ))
5663
5764 del writer
0 commit comments