Skip to content
Permalink
Browse files

[processing] refactored some helpre functions (contributed by Nathan …

…Woodrow)
  • Loading branch information
alexbruy committed Dec 29, 2013
1 parent 6b4641d commit 77fb9a5492bf58b030b11c4252f4e4530d73912e
Showing with 15 additions and 22 deletions.
  1. +15 −22 python/plugins/processing/tools/vector.py
@@ -135,34 +135,27 @@ def spatialindex(layer):


def createUniqueFieldName(fieldName, fieldList):
shortName = fieldName[:10]
def nextname(name):
num = 1
while True:
returnname ='{name}_{num}'.format(name=name[:8], num=num)
yield returnname
num += 1

if len(fieldList) == 0:
return shortName
def found(name):
return any(f.name() == name for f in fieldList)

fieldNames = [f.name() for f in fieldList]
shortName = fieldName[:10]

if shortName not in fieldNames:
if not fieldList:
return shortName

shortName = fieldName[:8] + '_1'
changed = True
while changed:
changed = False
for n in fieldList:
if n == shortName:

# Create unique field name
num = int(shortName[-1:])
if num < 9:
shortName = shortName[:8] + '_' + str(num + 1)
else:
shortName = shortName[:7] + '_' + str(num + 1)

changed = True

return shortName
if not found(shortName):
return shortName

for newname in nextname(shortName):
if not found(newname):
return newname

def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
idx = layer.fieldNameIndex(fieldName)

0 comments on commit 77fb9a5

Please sign in to comment.
You can’t perform that action at this time.