From a191c77bcbc177738956fc43b5462c524971c36d Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 23 Sep 2017 08:37:35 +1000 Subject: [PATCH] Remove duplicate testForUniqueness method (replaced with QgsProcessingUtils.combineFields) --- .../plugins/processing/algs/qgis/Intersection.py | 9 ++++----- python/plugins/processing/tools/vector.py | 16 ---------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/python/plugins/processing/algs/qgis/Intersection.py b/python/plugins/processing/algs/qgis/Intersection.py index 2f960c46e78..ce5ed7974d9 100644 --- a/python/plugins/processing/algs/qgis/Intersection.py +++ b/python/plugins/processing/algs/qgis/Intersection.py @@ -39,7 +39,8 @@ from qgis.core import (QgsFeatureRequest, QgsProcessingParameterFeatureSource, QgsProcessingParameterFeatureSink, QgsSpatialIndex, - QgsProcessingParameterField) + QgsProcessingParameterField, + QgsProcessingUtils) from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm from processing.tools import vector @@ -122,12 +123,10 @@ class Intersection(QgisAlgorithm): fieldListB = sourceB.fields() field_indices_b = [i for i in range(0, fieldListB.count())] - fieldListB = vector.testForUniqueness(fieldListA, fieldListB) - for b in fieldListB: - fieldListA.append(b) + output_fields = QgsProcessingUtils.combineFields(fieldListA, fieldListB) (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context, - fieldListA, geomType, sourceA.sourceCrs()) + output_fields, geomType, sourceA.sourceCrs()) outFeat = QgsFeature() indexB = QgsSpatialIndex(sourceB.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([]).setDestinationCrs(sourceA.sourceCrs())), feedback) diff --git a/python/plugins/processing/tools/vector.py b/python/plugins/processing/tools/vector.py index d4917f373a4..2bb659611a5 100755 --- a/python/plugins/processing/tools/vector.py +++ b/python/plugins/processing/tools/vector.py @@ -95,22 +95,6 @@ def values(source, *attributes): return ret -def testForUniqueness(fieldList1, fieldList2): - '''Returns a modified version of fieldList2, removing naming - collisions with fieldList1.''' - changed = True - while changed: - changed = False - for i in range(0, len(fieldList1)): - for j in range(0, len(fieldList2)): - if fieldList1[i].name() == fieldList2[j].name(): - field = fieldList2[j] - name = createUniqueFieldName(field.name(), fieldList1) - fieldList2[j] = QgsField(name, field.type(), len=field.length(), prec=field.precision(), comment=field.comment()) - changed = True - return fieldList2 - - def createUniqueFieldName(fieldName, fieldList): def nextname(name): num = 1