Skip to content

Commit

Permalink
fix Sum line length tool after API changes (fix #7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Mar 13, 2013
1 parent 105bfdd commit a57aa0c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions python/plugins/fTools/tools/doSumLines.py
Expand Up @@ -103,7 +103,7 @@ def compute(self, inPoly, inLns, inField, outPath, progressBar):
fieldList = ftools_utils.getFieldList(polyLayer)
index = polyProvider.fieldNameIndex(unicode(inField))
if index == -1:
index = polyProvider.fieldCount()
index = polyProvider.fields().count()
fieldList.append( QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("length field")) )
sRs = polyProvider.crs()
inFeat = QgsFeature()
Expand All @@ -119,17 +119,13 @@ def compute(self, inPoly, inLns, inField, outPath, progressBar):
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
return
writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, polyProvider.geometryType(), sRs)
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs)
spatialIndex = ftools_utils.createIndex( lineProvider )
polyFit = polyProvider.getFeatures()
polyFit = polyProvider.getFeatures()
while polyFit.nextFeature(inFeat):
inGeom = QgsGeometry(inFeat.geometry())
atMap = inFeat.attributes()
lineList = []
length = 0
#(check, lineList) = lineLayer.featuresInRectangle(inGeom.boundingBox(), True, False)
#lineLayer.select(inGeom.boundingBox(), False)
#lineList = lineLayer.selectedFeatures()
lineList = spatialIndex.intersects(inGeom.boundingBox())
if len(lineList) > 0: check = 0
else: check = 1
Expand All @@ -141,8 +137,9 @@ def compute(self, inPoly, inLns, inField, outPath, progressBar):
outGeom = inGeom.intersection(tmpGeom)
length = length + distArea.measure(outGeom)
outFeat.setGeometry(inGeom)
atMap.append(QVariant(length))
outFeat.setAttributes(atMap)
outFeat.setAttribute(index, QVariant(length))
#outFeat.setAttribute(index, QVariant(length))
writer.addFeature(outFeat)
start = start + 1
progressBar.setValue(start)
Expand Down

0 comments on commit a57aa0c

Please sign in to comment.