Skip to content

Commit

Permalink
Remove duplicate testForUniqueness method (replaced with QgsProcessin…
Browse files Browse the repository at this point in the history
…gUtils.combineFields)
  • Loading branch information
nyalldawson committed Sep 22, 2017
1 parent 54e5bfd commit a191c77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
9 changes: 4 additions & 5 deletions python/plugins/processing/algs/qgis/Intersection.py
Expand Up @@ -39,7 +39,8 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink,
QgsSpatialIndex,
QgsProcessingParameterField)
QgsProcessingParameterField,
QgsProcessingUtils)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import vector
Expand Down Expand Up @@ -122,12 +123,10 @@ def processAlgorithm(self, parameters, context, feedback):
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)
Expand Down
16 changes: 0 additions & 16 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -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
Expand Down

0 comments on commit a191c77

Please sign in to comment.