1
1
import os .path
2
+
2
3
from PyQt4 import QtGui
3
4
from PyQt4 .QtCore import *
5
+
4
6
from qgis .core import *
7
+
5
8
from sextante .core .GeoAlgorithm import GeoAlgorithm
6
9
from sextante .core .QGisLayers import QGisLayers
7
10
from sextante .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -21,26 +24,30 @@ def defineCharacteristics(self):
21
24
self .name = "Polygon centroids"
22
25
self .group = "Geometry tools"
23
26
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 ))
25
28
26
- self .addOutput (OutputVector (Centroids .OUTPUT_LAYER , "Output layer" ))
29
+ self .addOutput (OutputVector (self .OUTPUT_LAYER , "Output layer" ))
27
30
28
31
def processAlgorithm (self , progress ):
29
- layer = QGisLayers .getObjectFromUri (self .getParameterValue (Centroids .INPUT_LAYER ))
32
+ layer = QGisLayers .getObjectFromUri (self .getParameterValue (self .INPUT_LAYER ))
30
33
31
- provider = layer . dataProvider ( )
34
+ outFileName = self . getOutputValue ( self . OUTPUT_LAYER )
32
35
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 ( )
35
38
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 ())
38
43
39
44
inFeat = QgsFeature ()
40
45
outFeat = QgsFeature ()
41
- total = provider .featureCount ()
46
+
47
+ total = 100.0 / float (layer .featureCount ())
42
48
current = 0
43
- while provider .nextFeature (inFeat ):
49
+
50
+ while layer .nextFeature (inFeat ):
44
51
inGeom = inFeat .geometry ()
45
52
attrMap = inFeat .attributeMap ()
46
53
@@ -52,6 +59,6 @@ def processAlgorithm(self, progress):
52
59
outFeat .setAttributeMap (attrMap )
53
60
writer .addFeature (outFeat )
54
61
current += 1
55
- progress .setPercentage (int (current / total * 100 ))
62
+ progress .setPercentage (int (current * total ))
56
63
57
64
del writer
0 commit comments