Skip to main content

ID | Mile

0 6.5

1 6.4

2 6.4

3 6.4

4 9.2

5 12.8

etc

 

For every object which has a Mile number that occurs more then once I need to add a number to the Mile number. So for example, ID 1 would be Mile 6.4-1, ID 2 would be Mile 6.4-2 and so on. Now I have done this using Python but I'm sure this can be done with FME also. Can anyone give me some advice? Much appreciated.

Hej @voornaam​ :) you can generate these numbers using a Counter transformer. Set Count Start to 1, set Count Scope to Local, check the box Group Processing and select Group By = "Mile". Then use an AttributeCreator to add -1, -2, -3, etc. to Mile using "@Value(Mile)-@Value(_count)".


Feed features into a Counter with a Group By set to 'Mile', and set the start to 1. Then ExpressionEvaluator to add the count to the original Mile.

image


@nielsgerrits​ @dustin​ 

Wow, thank you for your fast reply's! I've tried both your ideas and they give me the same output, looks good. The next thing I'm trying to tackle is that there are IDs that have a unique Mile number, they get a -1 added as well. Is there some way to use an if like statement that says something like if the Mile number is unique don't add a number and if it occurs more than once, add a number. Any ideas?


I was thinking something like creating a list with Mile numbers that occur just once and use that in some sort of filter?


Using @nielsgerrits​ suggestion, you can put a StatisticsCalculator in between the Counter and the AttributeCreator, getting the total count for each Mile (you'll need to use the Group By parameter set to Mile). Then in the AttributeCreator, use the Conditional Value function to add only if the total count is > 1.imageimageimage


I was thinking something like creating a list with Mile numbers that occur just once and use that in some sort of filter?

Another option is to use a matcher, send the output from the matched port to your counter, then send the unmatched to an AttributeCreator/Manager to set the -1 figure


@dustin​ @nielsgerrits​ Thanks guys. Helped me a lot. What I ended up doing was using two conditional values in the Attribute creator. For objects with a unique Mile number use the existing one and add a number with Mile numbers that occur more than once.

 


Im back.. I'm having to rebuild my bench in FME 2021.0. For the Counter transformer there is no option 'Group By'. Any suggestions on how to solve this?


Im back.. I'm having to rebuild my bench in FME 2021.0. For the Counter transformer there is no option 'Group By'. Any suggestions on how to solve this?

If you set the Counter Name parameter to an attribute that will peform your group by​.


Reply