Skip to content
Permalink
Browse files
Remove len method from vector.features
Use QgsProcessingUtils::featureCount instead
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent f4f4ca3 commit 6397386fdaa6e57fedbe315a2b9a3c8d0c2e06bb
Showing with 257 additions and 206 deletions.
  1. +3 −2 python/plugins/processing/algs/qgis/AddTableField.py
  2. +3 −2 python/plugins/processing/algs/qgis/AutoincrementalField.py
  3. +5 −4 python/plugins/processing/algs/qgis/BasicStatistics.py
  4. +3 −2 python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
  5. +3 −2 python/plugins/processing/algs/qgis/BasicStatisticsStrings.py
  6. +2 −2 python/plugins/processing/algs/qgis/Boundary.py
  7. +2 −2 python/plugins/processing/algs/qgis/BoundingBox.py
  8. +1 −1 python/plugins/processing/algs/qgis/Buffer.py
  9. +2 −2 python/plugins/processing/algs/qgis/Centroids.py
  10. +2 −2 python/plugins/processing/algs/qgis/CheckValidity.py
  11. +1 −1 python/plugins/processing/algs/qgis/Clip.py
  12. +2 −2 python/plugins/processing/algs/qgis/ConvexHull.py
  13. +2 −2 python/plugins/processing/algs/qgis/Delaunay.py
  14. +3 −2 python/plugins/processing/algs/qgis/DeleteColumn.py
  15. +3 −2 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  16. +3 −2 python/plugins/processing/algs/qgis/DeleteHoles.py
  17. +3 −2 python/plugins/processing/algs/qgis/DensifyGeometries.py
  18. +3 −2 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  19. +2 −2 python/plugins/processing/algs/qgis/Difference.py
  20. +2 −2 python/plugins/processing/algs/qgis/Dissolve.py
  21. +3 −2 python/plugins/processing/algs/qgis/DropGeometry.py
  22. +3 −2 python/plugins/processing/algs/qgis/EquivalentNumField.py
  23. +3 −2 python/plugins/processing/algs/qgis/ExecuteSQL.py
  24. +3 −2 python/plugins/processing/algs/qgis/Explode.py
  25. +2 −2 python/plugins/processing/algs/qgis/ExportGeometryInfo.py
  26. +3 −2 python/plugins/processing/algs/qgis/ExtendLines.py
  27. +2 −2 python/plugins/processing/algs/qgis/ExtentFromLayer.py
  28. +4 −3 python/plugins/processing/algs/qgis/ExtractByLocation.py
  29. +2 −2 python/plugins/processing/algs/qgis/ExtractNodes.py
  30. +3 −2 python/plugins/processing/algs/qgis/ExtractSpecificNodes.py
  31. +3 −2 python/plugins/processing/algs/qgis/FieldPyculator.py
  32. +3 −2 python/plugins/processing/algs/qgis/FieldsCalculator.py
  33. +3 −2 python/plugins/processing/algs/qgis/FieldsMapper.py
  34. +3 −2 python/plugins/processing/algs/qgis/FixGeometry.py
  35. +3 −2 python/plugins/processing/algs/qgis/GeometryByExpression.py
  36. +3 −2 python/plugins/processing/algs/qgis/GeometryConvert.py
  37. +3 −2 python/plugins/processing/algs/qgis/Gridify.py
  38. +2 −2 python/plugins/processing/algs/qgis/Heatmap.py
  39. +3 −2 python/plugins/processing/algs/qgis/HubDistanceLines.py
  40. +3 −2 python/plugins/processing/algs/qgis/HubDistancePoints.py
  41. +3 −2 python/plugins/processing/algs/qgis/HubLines.py
  42. +3 −2 python/plugins/processing/algs/qgis/HypsometricCurves.py
  43. +2 −2 python/plugins/processing/algs/qgis/Intersection.py
  44. +4 −3 python/plugins/processing/algs/qgis/JoinAttributes.py
  45. +3 −2 python/plugins/processing/algs/qgis/LinesIntersection.py
  46. +2 −2 python/plugins/processing/algs/qgis/LinesToPolygons.py
  47. +2 −2 python/plugins/processing/algs/qgis/MeanCoords.py
  48. +2 −2 python/plugins/processing/algs/qgis/MergeLines.py
  49. +2 −2 python/plugins/processing/algs/qgis/MultipartToSingleparts.py
  50. +2 −2 python/plugins/processing/algs/qgis/NearestNeighbourAnalysis.py
  51. +3 −2 python/plugins/processing/algs/qgis/OffsetLine.py
  52. +4 −3 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  53. +3 −2 python/plugins/processing/algs/qgis/Orthogonalize.py
  54. +4 −4 python/plugins/processing/algs/qgis/PointDistance.py
  55. +2 −2 python/plugins/processing/algs/qgis/PointOnSurface.py
  56. +2 −2 python/plugins/processing/algs/qgis/PointsAlongGeometry.py
  57. +3 −2 python/plugins/processing/algs/qgis/PointsDisplacement.py
  58. +3 −2 python/plugins/processing/algs/qgis/PointsFromLines.py
  59. +3 −2 python/plugins/processing/algs/qgis/PointsFromPolygons.py
  60. +2 −2 python/plugins/processing/algs/qgis/PointsInPolygon.py
  61. +3 −2 python/plugins/processing/algs/qgis/PointsInPolygonUnique.py
  62. +3 −2 python/plugins/processing/algs/qgis/PointsInPolygonWeighted.py
  63. +3 −2 python/plugins/processing/algs/qgis/PointsLayerFromTable.py
  64. +3 −2 python/plugins/processing/algs/qgis/PointsToPaths.py
  65. +2 −2 python/plugins/processing/algs/qgis/PoleOfInaccessibility.py
  66. +3 −2 python/plugins/processing/algs/qgis/Polygonize.py
  67. +2 −2 python/plugins/processing/algs/qgis/PolygonsToLines.py
  68. +3 −2 python/plugins/processing/algs/qgis/RandomExtract.py
  69. +4 −3 python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py
  70. +2 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  71. +2 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  72. +1 −1 python/plugins/processing/algs/qgis/RandomSelectionWithinSubsets.py
  73. +2 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  74. +2 −1 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  75. +3 −2 python/plugins/processing/algs/qgis/RemoveNullGeometry.py
  76. +2 −2 python/plugins/processing/algs/qgis/ReprojectLayer.py
  77. +3 −2 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  78. +2 −2 python/plugins/processing/algs/qgis/SelectByLocation.py
  79. +1 −1 python/plugins/processing/algs/qgis/ServiceAreaFromLayer.py
  80. +2 −2 python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
  81. +2 −2 python/plugins/processing/algs/qgis/ShortestPathPointToLayer.py
  82. +2 −2 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  83. +2 −2 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  84. +3 −2 python/plugins/processing/algs/qgis/SingleSidedBuffer.py
  85. +3 −2 python/plugins/processing/algs/qgis/Smooth.py
  86. +3 −2 python/plugins/processing/algs/qgis/SnapGeometries.py
  87. +2 −2 python/plugins/processing/algs/qgis/SpatialJoin.py
  88. +3 −2 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  89. +4 −3 python/plugins/processing/algs/qgis/SplitWithLines.py
  90. +3 −2 python/plugins/processing/algs/qgis/StatisticsByCategories.py
  91. +2 −2 python/plugins/processing/algs/qgis/SumLines.py
  92. +2 −2 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  93. +3 −2 python/plugins/processing/algs/qgis/TextToFloat.py
  94. +2 −1 python/plugins/processing/algs/qgis/TopoColors.py
  95. +3 −2 python/plugins/processing/algs/qgis/Translate.py
  96. +3 −3 python/plugins/processing/algs/qgis/Union.py
  97. +1 −0 python/plugins/processing/algs/qgis/VectorSplit.py
  98. +2 −2 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  99. +3 −2 python/plugins/processing/algs/qgis/ZonalStatistics.py
  100. +0 −9 python/plugins/processing/tools/vector.py
@@ -28,7 +28,8 @@
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
@@ -100,7 +101,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())
outFeat = QgsFeature()
features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
geom = feat.geometry()
@@ -28,7 +28,8 @@
from qgis.PyQt.QtCore import QVariant
from qgis.core import (QgsField,
QgsFeature,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -70,7 +71,7 @@ def processAlgorithm(self, context, feedback):
vlayer.crs())
outFeat = QgsFeature()
features = vector.features(vlayer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(vlayer, context)
for current, feat in enumerate(features):
feedback.setProgress(int(current * total))
geom = feat.geometry()
@@ -34,7 +34,8 @@
from qgis.core import (QgsStatisticalSummary,
QgsStringStatisticalSummary,
QgsDateTimeStatisticalSummary,
QgsFeatureRequest)
QgsFeatureRequest,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterTable
@@ -145,7 +146,7 @@ def processAlgorithm(self, context, feedback):
self.createHTML(output_file, data)

def calcNumericStats(self, features, feedback, field):
count = len(features)
count = QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / float(count)
stat = QgsStatisticalSummary()
for current, ft in enumerate(features):
@@ -193,7 +194,7 @@ def calcNumericStats(self, features, feedback, field):
return data

def calcStringStats(self, features, feedback, field):
count = len(features)
count = QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / float(count)
stat = QgsStringStatisticalSummary()
for current, ft in enumerate(features):
@@ -224,7 +225,7 @@ def calcStringStats(self, features, feedback, field):
return data

def calcDateTimeStats(self, features, feedback, field):
count = len(features)
count = QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / float(count)
stat = QgsDateTimeStatisticalSummary()
for current, ft in enumerate(features):
@@ -33,7 +33,8 @@

from qgis.core import (QgsStatisticalSummary,
QgsFeatureRequest,
QgsProcessingAlgorithm)
QgsProcessingAlgorithm,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterTable
@@ -124,7 +125,7 @@ def processAlgorithm(self, context, feedback):
request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry).setSubsetOfAttributes([fieldName], layer.fields())
stat = QgsStatisticalSummary()
features = vector.features(layer, context, request)
count = len(features)
count = QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / float(count)
for current, ft in enumerate(features):
stat.addVariant(ft[fieldName])
@@ -33,7 +33,8 @@

from qgis.core import (QgsProcessingAlgorithm,
QgsStringStatisticalSummary,
QgsFeatureRequest)
QgsFeatureRequest,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterTable
@@ -111,7 +112,7 @@ def processAlgorithm(self, context, feedback):
layer.fields())
stat = QgsStringStatisticalSummary()
features = vector.features(layer, context, request)
count = len(features)
count = QgsProcessingUtils.featureCount(layer, context)
total = 100.0 / float(count)
for current, ft in enumerate(features):
stat.addValue(ft[fieldName])
@@ -27,7 +27,7 @@

import os

from qgis.core import QgsGeometry, QgsWkbTypes
from qgis.core import QgsGeometry, QgsWkbTypes, QgsProcessingUtils

from qgis.PyQt.QtGui import QIcon

@@ -84,7 +84,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

for current, input_feature in enumerate(features):
output_feature = input_feature
@@ -27,7 +27,7 @@

import os

from qgis.core import QgsGeometry, QgsWkbTypes
from qgis.core import QgsGeometry, QgsWkbTypes, QgsProcessingUtils

from qgis.PyQt.QtGui import QIcon

@@ -73,7 +73,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

for current, input_feature in enumerate(features):
output_feature = input_feature
@@ -40,7 +40,7 @@ def buffering(feedback, context, writer, distance, field, useField, layer, disso

current = 0
features = vector.features(layer, context)
total = 100.0 / float(len(features))
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

# With dissolve
if dissolve:
@@ -29,7 +29,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsWkbTypes
from qgis.core import QgsWkbTypes, QgsProcessingUtils

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
@@ -74,7 +74,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, input_feature in enumerate(features):
output_feature = input_feature
if input_feature.geometry():
@@ -30,7 +30,7 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsSettings, QgsGeometry, QgsFeature, QgsField, QgsWkbTypes
from qgis.core import QgsSettings, QgsGeometry, QgsFeature, QgsField, QgsWkbTypes, QgsProcessingUtils
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterSelection
@@ -137,7 +137,7 @@ def doCheck(self, context, feedback):
error_count = 0

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, inFeat in enumerate(features):
geom = inFeat.geometry()
attrs = inFeat.attributes()
@@ -29,7 +29,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWkbTypes, QgsProcessingUtils

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
@@ -31,7 +31,7 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsWkbTypes
from qgis.core import QgsField, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -116,7 +116,7 @@ def processAlgorithm(self, context, feedback):
if useField:
unique = layer.uniqueValues(index)
current = 0
total = 100.0 / (len(features) * len(unique))
total = 100.0 / (QgsProcessingUtils.featureCount(layer, context) * len(unique))
for i in unique:
first = True
hull = []
@@ -31,7 +31,7 @@
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QVariant

from qgis.core import QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes
from qgis.core import QgsField, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsPoint, QgsWkbTypes, QgsProcessingUtils

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -85,7 +85,7 @@ def processAlgorithm(self, context, feedback):
ptNdx = -1
c = voronoi.Context()
features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, inFeat in enumerate(features):
geom = QgsGeometry(inFeat.geometry())
if geom.isNull():
@@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication)
from qgis.core import (QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
@@ -86,7 +87,7 @@ def processAlgorithm(self, context, feedback):
layer.wkbType(), layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

for current, f in enumerate(features):
attributes = f.attributes()
@@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsFeatureRequest,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -69,7 +70,7 @@ def processAlgorithm(self, context, feedback):

features = vector.features(layer, context)

total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
geoms = dict()
for current, f in enumerate(features):
geoms[f.id()] = f.geometry()
@@ -24,7 +24,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication)
from qgis.core import (QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import (ParameterVector,
ParameterNumber)
@@ -82,7 +83,7 @@ def processAlgorithm(self, context, feedback):
layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

for current, f in enumerate(features):
if f.hasGeometry():
@@ -31,7 +31,8 @@
from qgis.core import (QgsGeometry,
QgsPoint,
QgsWkbTypes,
QgsApplication)
QgsApplication,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -88,7 +89,7 @@ def processAlgorithm(self, context, feedback):
layer.wkbType(), layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, f in enumerate(features):
feature = f
if feature.hasGeometry():
@@ -32,7 +32,8 @@
from qgis.core import (QgsPoint,
QgsGeometry,
QgsWkbTypes,
QgsApplication)
QgsApplication,
QgsProcessingUtils)

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -82,7 +83,7 @@ def processAlgorithm(self, context, feedback):
layer.wkbType(), layer.crs())

features = vector.features(layer, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
for current, f in enumerate(features):
feature = f
if feature.hasGeometry():
@@ -29,7 +29,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -80,7 +80,7 @@ def processAlgorithm(self, context, feedback):
outFeat = QgsFeature()
index = vector.spatialindex(layerB)
selectionA = vector.features(layerA, context)
total = 100.0 / len(selectionA)
total = 100.0 / QgsProcessingUtils.featureCount(layerA, context)
for current, inFeatA in enumerate(selectionA):
geom = inFeatA.geometry()
diff_geom = QgsGeometry(geom)
@@ -30,7 +30,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry
from qgis.core import QgsFeature, QgsGeometry, QgsProcessingUtils

from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
@@ -87,7 +87,7 @@ def processAlgorithm(self, context, feedback):

outFeat = QgsFeature()
features = vector.features(vlayerA, context)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(vlayerA, context)

if not useField:
first = True
@@ -28,7 +28,8 @@
from qgis.core import (QgsFeatureRequest,
QgsWkbTypes,
QgsCoordinateReferenceSystem,
QgsApplication)
QgsApplication,
QgsProcessingUtils)
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
@@ -76,7 +77,7 @@ def processAlgorithm(self, context, feedback):

request = QgsFeatureRequest().setFlags(QgsFeatureRequest.NoGeometry)
features = vector.features(layer, context, request)
total = 100.0 / len(features)
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)

for current, input_feature in enumerate(features):
writer.addFeature(input_feature)
Loading

0 comments on commit 6397386

Please sign in to comment.