Skip to main content
Solved

rename last index in a list

  • December 8, 2015
  • 4 replies
  • 25 views

mel
Contributor
Forum|alt.badge.img+7

I am using LineJoiner to merger street segments together based on the attribute STREET. Each segment contains STREET, FROM_STREET and TO_STREET and a SEQUENCE. I have ordered them by Sequence before the LineJoiner transformer and now I want to extract the FROM_STREET and TO_STREET for the merged segments. I renamed ROAD{0}.FROM_STREET to FROM_STREET, and that works fine. But how do I tell the List Element Selection to be the last element? It won't take -1 or any non-number or _element_count. Is there another way to do this? Ideally I would like it to be something simple like ROAD{MAX}.TO_STREET.

Best answer by roland.martin

I'd probably use a ListIndexer here - it pushes all the list items at index 0 or -1 into attributes, with an optional prefix.

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.

4 replies

roland.martin
Contributor
Forum|alt.badge.img+11
  • Contributor
  • Best Answer
  • December 8, 2015

I'd probably use a ListIndexer here - it pushes all the list items at index 0 or -1 into attributes, with an optional prefix.


erik_jan
Contributor
Forum|alt.badge.img+23
  • Contributor
  • December 8, 2015

You can use the ListElementCounter to retrieve the index number of the last entry in a list.


takashi
Celebrity
  • December 9, 2015

Alternatively, FME Functions might also be used in an expression setting to the Value column of AttributeCreator, like this.

@Value(ROAD{@Evaluate(@NumElements(ROAD{})-1)}.TO_STREET)

The FMEFunctionCaller can also be used to perform the expression.


fmelizard
Safer
Forum|alt.badge.img+21
  • Safer
  • December 9, 2015

I'd probably use a ListIndexer here - it pushes all the list items at index 0 or -1 into attributes, with an optional prefix.

Agreed. I'd stick with the above method to get the first one. But BEFORE renaming the 0th element, I'd do the ListIndexer with -1 (which is the last element). If you log or inspect you'll see why -- doing the ListIndexer first will get you the TO_STREET and the FROM_STREET but from the last element of the list. Following that with the Renamer to get you the FROM_STREET of the 0th will overwrite the other value that was there and get you what you want.