Skip to content

Commit

Permalink
Remove len method from vector.features
Browse files Browse the repository at this point in the history
Use QgsProcessingUtils::featureCount instead
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent f4f4ca3 commit 6397386
Show file tree
Hide file tree
Showing 100 changed files with 257 additions and 206 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/AddTableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/AutoincrementalField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions python/plugins/processing/algs/qgis/BasicStatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/BasicStatisticsNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/BasicStatisticsStrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/BoundingBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/CheckValidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/ConvexHull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Delaunay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/DeleteColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/DeleteHoles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/DensifyGeometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Dissolve.py