Remove duplicate testForUniqueness method (replaced with QgsProcessingUtils.combineFields)

This commit is contained in:
Nyall Dawson 2017-09-23 08:37:35 +10:00
parent 54e5bfda5c
commit a191c77bcb
2 changed files with 4 additions and 21 deletions

View File

@ -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)

View File

@ -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