Skip to main content
Solved

Add an extra incremental number to a list of values

  • May 4, 2022
  • 9 replies
  • 711 views

Forum|alt.badge.img

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.

Best answer by nielsgerrits

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)".

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

9 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • Best Answer
  • May 4, 2022

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)".


dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • May 4, 2022

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


Forum|alt.badge.img
  • Author
  • 4 replies
  • May 4, 2022

@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?


Forum|alt.badge.img
  • Author
  • 4 replies
  • May 4, 2022

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


dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • May 4, 2022

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


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3422 replies
  • May 4, 2022

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


Forum|alt.badge.img
  • Author
  • 4 replies
  • May 6, 2022

@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.

 


Forum|alt.badge.img
  • Author
  • 4 replies
  • May 24, 2022

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?


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3422 replies
  • May 24, 2022

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​.