Skip to main content
Open

Lists - Extract Element Range

Related products:Transformers
  • November 17, 2024
  • 5 replies
  • 75 views
danilo_fme
larue
chriswilson
geoportalcartog
  • danilo_fme
    danilo_fme
  • larue
    larue
  • chriswilson
    chriswilson
  • geoportalcartog
    geoportalcartog

chriswilson
Supporter

Or ‘list slicing’ of course.  For example this list with element positions also as values for illustration:

List[0,1,2,3,4]

A following AttributeManager wants to extract:

Attribute1 = List{0} so would retrieve the value of ‘0’

Attribute2 = List{1} would retrieve ‘1’

Attribute3 = List{2:} or {List{2:5} or List{2:-1} would retrieve ‘2,3,4’

Doing this without python would save time and also those without python skills would benefit.  I am aware of the ListSlicer and ​@takashi could correct me if I’m wrong but it doesn’t quite seem to achieve this if the element range is open-ended or goes from e.g. element 2 to the end of the list.  Maybe it’s just an enhancement to that transformer?

A ListIndexRetriever type transformer might be a good way to do this, or bake it into attribute transformers in addition to the current single-element functionality.

5 replies

chriswilson
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • November 22, 2024

Just correcting the second example for Attribute3 - this would be List{2:4} in this case


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • November 22, 2024

Have you looked at the ListElementExtractor from FME Hub?

 


chriswilson
Supporter
Forum|alt.badge.img+11
  • Author
  • Supporter
  • November 26, 2024
geomancer wrote:

Have you looked at the ListElementExtractor from FME Hub?

 

It needs to be able to extract a slice that is open-ended e.g. from an index to the end of the list, into one attribute.  The ListElementExtractor and Takashi’s ListSlicer don’t cover the functionality I’m suggesting.


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • November 27, 2024

You can remove the superfluous list elements with a BulkAttributeRemover, and use ListConcatenator to combine the remaining list elements into a single attribute.

The regular expression used in the example below is _IDs\{[0|1|2|3]\} (the list is named _IDs, the list elements ro remove are 0, 1, 2 and 3, and the curly brackets need to be escaped with a \ because they have a special meaning in regular expressions).

 


LizAtSafe
Safer
Forum|alt.badge.img+15
  • Safer
  • April 5, 2025
NewOpen

Reply


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