Question

What is a Counter?

Answer

Description

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 for values of a given attribute.

If you select an attribute in the Counter Name setting it will group by that attribute; i.e. each separate value of that attribute will get its own unique count.

'Histogram'

The 'histogram' function mentioned above returns the frequency of values for an attribute. To activate this select an attribute name in the Counter Name field in the Counter properties dialog. 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.

Count interval other than 1

The AttributeCreator h(in FME2012) 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 

 

Counting backwards

Count backwards by using an AttributeCreator as described before, but with a slightly different function:
 10-((@Count())*2)

10 being your start value, 2 being your interval


.