Parsing attribute values

Community > Parsing attribute values

- StringSearcher or AttributeSplitter

- Tester
- StringReplacer or StringConcatenator

I would use a combination of StringSearcher and StringReplacer with:

^(.+) to (.+)$

# Python script also can be used.

import fmeobjects
import re

class UpDownRegulator(object):

    def __init__(self):
        self.attrName = 'up_to_down'
        self.regex = re.compile('^\s*(.+)\s+to\s+(.+)\s*$')

    def input(self, feature):

        s = feature.getAttribute(self.attrName)
        if s:
            m = self.regex.match(s)
            if m:
                u, d = m.group(1), m.group(2)
                if u < d: u, d = d, u
                feature.setAttribute(self.attrName, '%s to %s' % (u, d))

    def close(self):


No comments:

Post a Comment