Skip to main content

Hi there,

I want to start a new counter every time an attribute changes.
So I have an attribute equal to either same or next.

Same – Count Value = 1

Same – Count Value = 1

Same – Count Value = 1

Same – Count Value = 1

Same – Count Value = 1

Next – Count Value = 2

Same– Count Value = 2

Same– Count Value = 2

Same– Count Value = 2

Next – Count Value = 3

Same– Count Value = 3

This is so that I can put all the Count 1s in a folder, all the Count 2s in the next folder, etc.

It seems simple, but I can't quite put my finger on how to do it!

Thanks, Amt

Hi @amit, I would use the Advanced Attribute Value Handling options and Conditional Value setting in the AttributeCreator.

  1. Expose "count" attribute with the AttributeExposer. This "count" has no value (missing attribute) at this point.
  2. Then, set the required value to "count" with the AttributeCreator. The setting looks like this.


Hi @amit, I would use the Advanced Attribute Value Handling options and Conditional Value setting in the AttributeCreator.

  1. Expose "count" attribute with the AttributeExposer. This "count" has no value (missing attribute) at this point.
  2. Then, set the required value to "count" with the AttributeCreator. The setting looks like this.

Spot on. Just make sure your data is sorted by the key attribute first, otherwise you'll get unexpected results...


Hi @takashi, thanks for the quick reply. I've used that function before, but didn't realise it could be used for this! I've made an error somewhere in the syntax below, in the output values I think? Can't spot what I've done wrong.


Hi @takashi, thanks for the quick reply. I've used that function before, but didn't realise it could be used for this! I've made an error somewhere in the syntax below, in the output values I think? Can't spot what I've done wrong.

@amit, if the value of "Adjacent" is not numeric, don't use the @Evaluate function. Probably you entered "feature[-1].Adjacent" using the Arithmetic Editor. "@Evaluate(<string>)" returns <null>, if the <string> cannot be interpreted as a numeric (FME 2015+).


@takashi. Thanks for reply, as you've noted, it's not a number. So what I have now is:

If @Value(Adjacent) = @Value(feature[-1].Adjacent)

the Output value is:

feature[-1].Adjacent

Else if:

@Value(feature[-1].count+1

However, it still fails, cannot evaluate the expression. Could you help please?


@takashi. Thanks for reply, as you've noted, it's not a number. So what I have now is:

If @Value(Adjacent) = @Value(feature[-1].Adjacent)

the Output value is:

feature[-1].Adjacent

Else if:

@Value(feature[-1].count+1

However, it still fails, cannot evaluate the expression. Could you help please?

Oh, I've overlooked. The output values in your screenshot seem to be string literals (headed by "k" icon).

  • The output value in the "If" row should be the value of "feature[-1].count" attribute. Enter it with the Text Editor (double-click on or drag-and-drop from the left pane of the editor).
  • The output value in the "Else" row should be a math expression "@Value(feature[-1].count) + 1". Enter the expression with the Arithmetic Editor.

Make sure that you have exposed "count" with the AttributeExposer before the AttributeCreator.


@takashi. Getting warmer! The expression is now valid and the workspace runs

I've also exposed the Count and Sorted them in the right order.

However, the inspector gives me.


The output value in the If row is still a string literal. The menu button can also be used to set the attribute value.


wow, I had misunderstood about the values of Adjacent! I thought the sequence is like: {a, a, a, a, b, b, b, b, b, c, c, c, ...}. My approach won't solve your issue unfortunately.


Re-challenge.

or


Re-challenge.

0684Q00000ArJjxQAF.png

 or

0684Q00000ArJXGQA3.png

or PythonCaller?

class FeatureProcessor(object):
    def __init__(self):
        self.count = 1

    def input(self, feature):
        if feature.getAttribute('Adjacent') == 'next':
            self.count += 1
        feature.setAttribute('count', self.count)
        self.pyoutput(feature) 

@takashi , challenge successful! Thank you very much, appreciate all the help.

To put the workspace into context for all (as I now feel I didn't give enough information), we have a 360 pano camera that consists of 7 Go Pros in a rig. We need to organise each setup into a folder consisting of the 7 photos each. Problem is, the camera times are not synced up (they seem to reset when you taken the battery out) and sometimes only say 5 of the 7 cameras fire.

I created a workspace that zeroes the first photo from each setup (i.e. first photo of each camera of first first setup = 0 seconds) and then substracts that from each photo (grouped by camera). Then worked out the gap in seconds before/after photo (again, grouped by photo) using the adjacent feature function. If the gap was greater than 3 seconds then 'next' setup otherwise 'same'.

Thanks again @takashi.

Cheers, Amit


Reply