Skip to content

Commit

Permalink
Port some more code to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 13f0813 commit a4cd66f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Expand Up @@ -153,8 +153,9 @@ def processAlgorithm(self, context, feedback):
inFeat = QgsFeature()
outFeat = QgsFeature()
features = QgsProcessingUtils.getFeatures(layer, context)
if len(features):
total = 100.0 / QgsProcessingUtils.featureCount(layer, context)
count = QgsProcessingUtils.featureCount(layer, context)
if count > 0:
total = 100.0 / count
for current, inFeat in enumerate(features):
rownum = current + 1

Expand Down
Expand Up @@ -5,6 +5,7 @@

from processing.tools.vector import TableWriter
from collections import defaultdict
from qgis.core import QgsProcessingUtils
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.tools import dataobjects

Expand All @@ -20,8 +21,8 @@
writer = TableWriter(Frequency, None, fields + ['FREQ'])

counts = {}
feats = processing.features(layer)
nFeats = len(feats)
feats = QgsProcessingUtils.getFeatures(layer, context)
nFeats = QgsProcessingUtils.featureCount(layer, context)
counts = defaultdict(int)
for i, feat in enumerate(feats):
feedback.setProgress(int(100 * i / nFeats))
Expand Down
Expand Up @@ -5,7 +5,7 @@
##Biggest parts=output vector

from processing.tools import dataobjects
from qgis.core import QgsGeometry, QgsWkbTypes
from qgis.core import QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from operator import itemgetter

To_keep = int(To_keep)
Expand All @@ -21,7 +21,7 @@
QgsWkbTypes.MultiPolygon, polyPrder.crs())


for n, feat in enumerate(processing.features(polyLayer)):
for n, feat in enumerate(QgsProcessingUtils.getFeatures(polyLayer, context)):
feedback.setProgress(int(100 * n / count))
geom = feat.geometry()
if geom.isMultipart():
Expand Down
Expand Up @@ -5,7 +5,7 @@
##N_unique_values=output vector

from qgis.PyQt.QtCore import QVariant
from qgis.core import QgsFeature, QgsField
from qgis.core import QgsFeature, QgsField, QgsProcessingUtils
from processing.tools.vector import VectorWriter
from processing.tools import dataobjects

Expand All @@ -20,8 +20,8 @@

outFeat = QgsFeature()
classes = {}
feats = processing.features(layer)
nFeat = len(feats)
feats = QgsProcessingUtils.getFeatures(layer, context)
nFeat = QgsProcessingUtils.featureCount(layer, context)
for n, inFeat in enumerate(feats):
feedback.setProgress(int(100 * n / nFeat))
attrs = inFeat.attributes()
Expand Down

0 comments on commit a4cd66f

Please sign in to comment.