Add a count attribute to the FeatureHolder

Related products: FME Form

To count the number of features I use the StatisticsCalulator. I don't want to use an attribute to analyse, I only want to know how many features have past the flow to continue if it is below a certain amount.

Bij (optionally) adding a count-attribute to the featuerholder it is more efficient to achieve this. The attribute is added to all the features.

That's a good idea. I think I would try to improve on it by saying the StatisticsCalculator should be updated to allow no attribute to be analyzed. If that's the case then only Total Count is output. Would that be as good, do you think? I've found the same recently, that I want a count of features without having to select an attribute to analyze.

 

 


I've often used the aggregator/deaggregator for that purpose. Though I don't think I've ever benchmarked it against the statisticsCalculator.

 

 


Check out the FeatureCounter transformer on the FME Hub

 

 


Just out of curiosity, I did a mini benchmark with some data with a lot of attributes:

FeatureCounter custom transformer = 41.7 s

StatisticsCalculator(Analyse 1 unique attribute for _count only) = 47.6 s

AttributeKeeper(unique attribute only) -> StatisticsCalculator = 31.3 s

Aggregator(Attributes only, drop attributes, build list, unique attribute only) -> ListElementCounter = 24.1 s

Raw PythonCaller keeping only an integer count = 5.3 s

I feel like getting the feature count for 125,000 features should really be faster than this. After all, it only takes about 160 s on this same machine to pump these features through a JSONTemplater with 2 sub-templates so I feel all the above options are doing excess work.

EDIT: I've now packaged up the PythonCaller code I used and published it on the Hub here


I gave the FeatureCounter an update, so give it a try again in 2020 (it's now version 3 of the transformer) and hopefully it will be quicker.

Another method would be:

  • Create an attribute, set value to 1 (AttributeCreator)
  • Aggregate the data (Aggregator: Set Attributes to sum to step 1 attribute)

But I gave that a try and it didn't seem any quicker, so I didn't change the transformer to use that method.