Skip to content

Commit 9b83b53

Browse files
committedApr 2, 2015
minor fixes
1 parent f0053b8 commit 9b83b53

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed
 

‎python/plugins/fTools/tools/doPointsInPolygon.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import math
3232

3333
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
3535
from qgis.core import QGis, QgsFeatureRequest, QgsField, QgsVectorFileWriter, QgsFeature, QgsGeometry
3636
import ftools_utils
3737
from ui_frmPointsInPolygon import Ui_Dialog
@@ -54,7 +54,7 @@ def __init__(self, iface):
5454
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
5555
QObject.connect(self.inPoint, SIGNAL("currentIndexChanged(QString)"), self.listPointFields)
5656
QObject.connect(self.inPoint, SIGNAL("activated(QString)"), self.listPointFields)
57-
57+
5858
self.progressBar.setValue(0)
5959
self.populateLayers()
6060

@@ -66,15 +66,15 @@ def populateLayers( self ):
6666
self.inPoint.clear()
6767
layers = ftools_utils.getLayerNames([QGis.Point])
6868
self.inPoint.addItems(layers)
69-
69+
7070
def listPointFields(self):
7171
if self.inPoint.currentText() == "":
7272
pass
7373

7474
inPnts = ftools_utils.getVectorLayerByName(self.inPoint.currentText())
7575
if inPnts:
7676
pointFieldList = ftools_utils.getFieldList(inPnts)
77-
77+
7878
self.attributeList.clear()
7979
for field in pointFieldList:
8080
if field.type() == QVariant.Int or field.type() ==QVariant.Double:
@@ -119,7 +119,7 @@ def accept(self):
119119

120120
self.btnOk.setEnabled(False)
121121

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,
123123
self.attributeList, self.statisticSelector)
124124

125125
QObject.connect(self.workThread, SIGNAL("rangeChanged(int)"), self.setProgressRange)
@@ -171,7 +171,7 @@ def restoreGui(self):
171171
self.btnOk.setEnabled(True)
172172

173173
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):
175175
QThread.__init__( self, QThread.currentThread() )
176176
self.mutex = QMutex()
177177
self.stopMe = 0
@@ -184,7 +184,6 @@ def __init__( self, widget, inPoly, inPoints, fieldName, outPath, encoding, at
184184
self.encoding = encoding
185185
self.attributeList = attributeList
186186
self.statistics = statisticSelector.currentText()
187-
self.widget = widget
188187

189188
def run(self):
190189
self.mutex.lock()
@@ -196,7 +195,7 @@ def run(self):
196195
polyProvider = self.layerPoly.dataProvider()
197196
pointProvider = self.layerPoints.dataProvider()
198197

199-
fieldList = ftools_utils.getFieldList(self.layerPoly)
198+
fieldList = ftools_utils.getFieldList(self.layerPoly)
200199
index = polyProvider.fieldNameIndex(unicode(self.fieldName))
201200
if index == -1:
202201
index = polyProvider.fields().count()
@@ -234,7 +233,7 @@ def run(self):
234233
while polyFit.nextFeature(polyFeat):
235234
inGeom = polyFeat.geometry()
236235
atMap = polyFeat.attributes()
237-
outFeat.setAttributes(atMap)
236+
outFeat.setAttributes(atMap)
238237
outFeat.setGeometry(inGeom)
239238

240239
count = 0
@@ -257,7 +256,7 @@ def run(self):
257256
count += 1
258257
for item in selectedItems:
259258
valueList[item.text()].append(pntFeat.attribute(item.text()))
260-
259+
261260
self.mutex.lock()
262261
s = self.stopMe
263262
self.mutex.unlock()
@@ -279,7 +278,7 @@ def run(self):
279278
# Jump over invalid values
280279
if non_numeric_values is True:
281280
continue
282-
281+
283282
if values and len(values) > 0:
284283
if self.statistics == "sum":
285284
value = reduce(myAdder, values)
@@ -298,7 +297,7 @@ def run(self):
298297

299298
outFeat.setAttributes(atMap)
300299
writer.addFeature(outFeat)
301-
300+
302301
self.emit( SIGNAL( "updateProgress()" ) )
303302

304303
self.mutex.lock()
@@ -321,10 +320,10 @@ def stop(self):
321320
self.mutex.unlock()
322321

323322
QThread.wait( self )
324-
325-
def myAdder(x,y):
323+
324+
def myAdder(x,y):
326325
return x+y
327-
326+
328327
def two_pass_variance(data):
329328
"""
330329
Variance algorithm taken from Wikipedia:
@@ -333,18 +332,18 @@ def two_pass_variance(data):
333332
n = 0.0
334333
sum1 = 0.0
335334
sum2 = 0.0
336-
335+
337336
for x in data:
338337
n = n + 1.0
339338
sum1 = sum1 + float(x)
340-
339+
341340
if (n < 2):
342341
return 0
343342

344343
mean = sum1 / n
345-
344+
346345
for x in data:
347346
sum2 = sum2 + (x - mean)*(x - mean)
348-
347+
349348
variance = sum2 / (n - 1)
350349
return variance

0 commit comments

Comments
 (0)
Please sign in to comment.