Conditional Execution based on Feature Existence

(FME 2013 SP4 Build 13547)

From this thread. > Community: conditional execution of densifying
To simplify explanation, assume there are two feature types - e.g. TypeA and TypeB; TypeA features have to be processed only when one or more TypeB feature exists. In other words, it's not necessary to process TypeA features when there is no TypeB feature.

My first inspiration was to use unconditional merging like this image.
The Sampler and the AttributeKeeper are not essential but I think those are effective to prevent unnecessary processing in the FeatureMerger as much as possible.
About unconditional merging, see "Join On" Parameter of the FeatureMerger.

A PythonCaller followed by a FeatureTypeFilter would be also one of options.
# Python Script Example
# Hold every features, output them only when a TypeB feature exists.
# If there is no TypeB feature, output a Signal feature.
import fmeobjects

class FeatureDispatcher(object):
    def __init__(self):
        self.typeAFeatures = []
        self.typeBFeatures = []
    def input(self, feature):
        type = feature.getAttribute('fme_feature_type')
        if type == 'TypeA':
        elif type == 'TypeB':
    def close(self):
        if 0 < len(self.typeBFeatures):
            map(self.pyoutput, self.typeAFeatures)
            map(self.pyoutput, self.typeBFeatures)
            logger = fmeobjects.FMELogFile()
            logger.logMessageString('No TypeB Feature.', fmeobjects.FME_WARN)
            signal = fmeobjects.FMEFeature()
            signal.setAttribute('fme_feature_type', 'Signal')

Not only for this case, I think that various Transformers (maybe within Workflow category) for flow control can be considered.

Note: fmeobjects.FMEFeature class (FME Objects Python API) has "getFeatureType" and "setFeatureType" methods. I thought I can use them to get / set "fme_feature_type" attribute value (i.e. feature type name), but it is not always so in my testing. I couldn't confirm exact functions of those methods.

No comments:

Post a Comment