2013-05-18

Sort only part of an attribute in a list

Community > Sort only part of an attribute in a list

# Python script version
import fmeobjects
import re

AttrName = ['field0', 'field1', 'field2', 'field3']

def sortAttributes(feature):
    v = {}
    for n in AttrName:
        s = feature.getAttribute(n)
        if s and re.match('^.+_.+$', s): v[s.split('_')[-1]] = s
    i = 0
    for k in sorted(v.keys()):
        feature.setAttribute(AttrName[i], v[k])
        i = i + 1
    for j in range(i, len(AttrName)):
        feature.setAttribute(AttrName[j], '')

No comments:

Post a Comment