Franco, unfortunately I was not able to find a way to resolve it by using existing transformers only. I finally fell into the temptation to use Python...
The PythonCaller with this script adds "_group" attribute to input features.
Set "_group" to the "Attributes To Expose" parameter of the PythonCaller.
Assume that both "WSNO" and "USLINKNO1" contain integer value and also there are no duplicate values in "WSNO" and "USLINKNO1".
You can remove the AttributeExposer and the AttributeCreator if you adopt this.
-----
# Python Script Example
import fme, fmeobjects
import collections
class FeatureProcessor(object):
def __init__(self):
# Set of all input features.
self.features = set([])
def input(self, feature):
# Store the input feature in the Set.
self.features.add(feature)
def close(self):
# Connection key attribute names.
frontAttr = 'USLINKNO1' # forward connection key
backAttr = 'WSNO' # backword connection key
# Create two dictionaries.
# d1: key=forward connection key, value=feature
# d2: key=backword connection key, value=feature
d1, d2 = {}, {}
for feature in self.features:
front = int(feature.getAttribute(frontAttr))
back = int(feature.getAttribute(backAttr))
d1[front] = feature
d2[back] = feature
# Initialize group ID.
id = 0
while 0 < len(self.features):
# Retrieve and remove a feature from the Set.
feature = self.features.pop()
# Create and initialize a group.
group = collections.deque()
group.append(feature)
# Initialize forward/backward connection key.
front = int(feature.getAttribute(frontAttr))
back = int(feature.getAttribute(backAttr))
# Append backward connectable features to the group.
while d1.has_key(back):
# - retrieve and remove a feature from d1 dictionary.
# - append the feature to the group.
# - remove the feature from the Set.
# - update backword connection key.
feature = d1.pop(back)
group.append(feature)
self.features.remove(feature)
back = int(feature.getAttribute(backAttr))
# Append forward connectable features to the group.
while d2.has_key(front):
# - retrieve and remove a feature from d2 dictionary.
# - append the feature to the group.
# - remove the feature from the Set.
# - update forword connection key.
feature = d2.pop(front)
group.appendleft(feature)
self.features.remove(feature)
front = int(feature.getAttribute(frontAttr))
# Set group ID and output features in the group.
for feature in group:
feature.setAttribute('_group', id)
self.pyoutput(feature)
# Update group ID for the next group.
id += 1
-----