Counter

From fmepedia

Counter is a Workbench Transformer.

A Counter transformer adds a numeric attribute to a feature and assigns a value. Each subsequent feature passing through the transformer receives an incremented value - in other words the Counter is counting the features.

This can be a useful transformer for assigning a unique, numeric ID number to a set of features, for counting the number of features or (see below) for creating a basic histogram (http://en.wikipedia.org/wiki/Histogram) for values of a given attribute.

If you put an attribute in the Counter Name setting it will group by that attribute. So to group-by line_id set the Counter name to &line_id (the & is important to denote this is an attribute).

Table of contents

'Histogram'

The 'histogram' function mentioned above returns the frequency of values for an attribute. To activate this enter the attribute name into the Counter Name field in the Counter properties dialog. Make sure the attribute is defined as such by prefixing it with an '&' character - for example, &property_type. Not only does this number features according to their value of 'property_type' it will also add a small table to the foot of the log file summarising them.


Multiple Counters

Multiple Counter transformers within a workspace can cause confusion.

Each Counter has a Counter Name property in its dialog. When multiple Counters have different names each Counter produces a unique count starting at 1 (or whatever the user desires). However, when multiple Counters have the same name they produce a single count.

For example, there are two workspaces each with two Counters. Ten features passed each Counter through would result in the following...

Workspace 1
Counter Name: Counter1 - features numbered 1 - 10
Counter Name: Counter2 - features numbered 1 - 10
Workspace 2
Counter Name: Counter - features numbered 1 - 10
Counter Name: Counter - features numbered 11 - 20

Obviously this effect can be used as needed to produce different results; however - the default behaviour of FME is to name all Counters the same, so if you place multiple Counters in a workspace be aware that they will produce a single count. If you don't want this go into the settings dialog and rename the Counters to give them different names.

Mireland 10:11, 4 Oct 2005 (PDT)

Count interval other than 1

The ExpressionEvaluator has the ability to use the @Count() function within the expression, so you could do it all from there w/o even using the Counter transformer! The expression would be:

((@Count())*2)+1

Alternatively (a little more hacky) an AttributeCreator will do the same with the value set to:

@Evaluate("((@Count())*2)+1")

Of course you can also continue to use a Counter and perform this operation on the count attribute using an ExpressionEvaluator.

Counting backwards

By using an ExpressionEvaluator as described before, but with a slightly different function:

10-((@Count())*2)

10 being your start value, 2 being your interval.

User Comments Add a new comment

Mark,

Thanks for the tip on the histogram, I think that will come in useful for some people.