Skip to main content
Solved

rename last index in a list


mel
Contributor
Forum|alt.badge.img+7
  • Contributor

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.

View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, 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
Forum|alt.badge.img+9

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+18
  • Contributor
  • December 8, 2015

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


takashi
Evangelist
  • 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+19
  • Safer
  • December 9, 2015
roland.martin wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings