31
31
import math
32
32
33
33
from PyQt4 .QtCore import QObject , SIGNAL , QThread , QMutex , QVariant , QFile
34
- from PyQt4 .QtGui import QDialog , QDialogButtonBox , QMessageBox
34
+ from PyQt4 .QtGui import QDialog , QDialogButtonBox , QMessageBox , QListWidgetItem
35
35
from qgis .core import QGis , QgsFeatureRequest , QgsField , QgsVectorFileWriter , QgsFeature , QgsGeometry
36
36
import ftools_utils
37
37
from ui_frmPointsInPolygon import Ui_Dialog
@@ -54,7 +54,7 @@ def __init__(self, iface):
54
54
QObject .connect (self .toolOut , SIGNAL ("clicked()" ), self .outFile )
55
55
QObject .connect (self .inPoint , SIGNAL ("currentIndexChanged(QString)" ), self .listPointFields )
56
56
QObject .connect (self .inPoint , SIGNAL ("activated(QString)" ), self .listPointFields )
57
-
57
+
58
58
self .progressBar .setValue (0 )
59
59
self .populateLayers ()
60
60
@@ -66,15 +66,15 @@ def populateLayers( self ):
66
66
self .inPoint .clear ()
67
67
layers = ftools_utils .getLayerNames ([QGis .Point ])
68
68
self .inPoint .addItems (layers )
69
-
69
+
70
70
def listPointFields (self ):
71
71
if self .inPoint .currentText () == "" :
72
72
pass
73
73
74
74
inPnts = ftools_utils .getVectorLayerByName (self .inPoint .currentText ())
75
75
if inPnts :
76
76
pointFieldList = ftools_utils .getFieldList (inPnts )
77
-
77
+
78
78
self .attributeList .clear ()
79
79
for field in pointFieldList :
80
80
if field .type () == QVariant .Int or field .type () == QVariant .Double :
@@ -119,7 +119,7 @@ def accept(self):
119
119
120
120
self .btnOk .setEnabled (False )
121
121
122
- self .workThread = PointsInPolygonThread (self , inPoly , inPnts , self .lnField .text (), self .outShape .text (), self .encoding ,
122
+ self .workThread = PointsInPolygonThread (inPoly , inPnts , self .lnField .text (), self .outShape .text (), self .encoding ,
123
123
self .attributeList , self .statisticSelector )
124
124
125
125
QObject .connect (self .workThread , SIGNAL ("rangeChanged(int)" ), self .setProgressRange )
@@ -171,7 +171,7 @@ def restoreGui(self):
171
171
self .btnOk .setEnabled (True )
172
172
173
173
class PointsInPolygonThread (QThread ):
174
- def __init__ ( self , widget , inPoly , inPoints , fieldName , outPath , encoding , attributeList , statisticSelector ):
174
+ def __init__ ( self , inPoly , inPoints , fieldName , outPath , encoding , attributeList , statisticSelector ):
175
175
QThread .__init__ ( self , QThread .currentThread () )
176
176
self .mutex = QMutex ()
177
177
self .stopMe = 0
@@ -184,7 +184,6 @@ def __init__( self, widget, inPoly, inPoints, fieldName, outPath, encoding, at
184
184
self .encoding = encoding
185
185
self .attributeList = attributeList
186
186
self .statistics = statisticSelector .currentText ()
187
- self .widget = widget
188
187
189
188
def run (self ):
190
189
self .mutex .lock ()
@@ -196,7 +195,7 @@ def run(self):
196
195
polyProvider = self .layerPoly .dataProvider ()
197
196
pointProvider = self .layerPoints .dataProvider ()
198
197
199
- fieldList = ftools_utils .getFieldList (self .layerPoly )
198
+ fieldList = ftools_utils .getFieldList (self .layerPoly )
200
199
index = polyProvider .fieldNameIndex (unicode (self .fieldName ))
201
200
if index == - 1 :
202
201
index = polyProvider .fields ().count ()
@@ -234,7 +233,7 @@ def run(self):
234
233
while polyFit .nextFeature (polyFeat ):
235
234
inGeom = polyFeat .geometry ()
236
235
atMap = polyFeat .attributes ()
237
- outFeat .setAttributes (atMap )
236
+ outFeat .setAttributes (atMap )
238
237
outFeat .setGeometry (inGeom )
239
238
240
239
count = 0
@@ -257,7 +256,7 @@ def run(self):
257
256
count += 1
258
257
for item in selectedItems :
259
258
valueList [item .text ()].append (pntFeat .attribute (item .text ()))
260
-
259
+
261
260
self .mutex .lock ()
262
261
s = self .stopMe
263
262
self .mutex .unlock ()
@@ -279,7 +278,7 @@ def run(self):
279
278
# Jump over invalid values
280
279
if non_numeric_values is True :
281
280
continue
282
-
281
+
283
282
if values and len (values ) > 0 :
284
283
if self .statistics == "sum" :
285
284
value = reduce (myAdder , values )
@@ -298,7 +297,7 @@ def run(self):
298
297
299
298
outFeat .setAttributes (atMap )
300
299
writer .addFeature (outFeat )
301
-
300
+
302
301
self .emit ( SIGNAL ( "updateProgress()" ) )
303
302
304
303
self .mutex .lock ()
@@ -321,10 +320,10 @@ def stop(self):
321
320
self .mutex .unlock ()
322
321
323
322
QThread .wait ( self )
324
-
325
- def myAdder (x ,y ):
323
+
324
+ def myAdder (x ,y ):
326
325
return x + y
327
-
326
+
328
327
def two_pass_variance (data ):
329
328
"""
330
329
Variance algorithm taken from Wikipedia:
@@ -333,18 +332,18 @@ def two_pass_variance(data):
333
332
n = 0.0
334
333
sum1 = 0.0
335
334
sum2 = 0.0
336
-
335
+
337
336
for x in data :
338
337
n = n + 1.0
339
338
sum1 = sum1 + float (x )
340
-
339
+
341
340
if (n < 2 ):
342
341
return 0
343
342
344
343
mean = sum1 / n
345
-
344
+
346
345
for x in data :
347
346
sum2 = sum2 + (x - mean )* (x - mean )
348
-
347
+
349
348
variance = sum2 / (n - 1 )
350
349
return variance
0 commit comments