Is there an easy way to extract a subset of values from a list attribute. For example if the list attribute contains: 1,3,5,6,8,10,5 etc up to hundreds of values, how can I extract the first 10 values as a list also?
Hi @johnm, the ListSlicer from FME Hub might help you.
Otherwise in the standard Transformers use a ListExploder which gives an option to assign an Element Index attribute which will be a sequence from Base 0 of 0,1,2,3,4...
A Tester on the output of the ListExploder using a Test criteria of Element Index < 10 will give the first 10 values in each List that was attributed against the base Features.
This can then be pushed back into Features with Lists by recompiling the Tester output with ListBuilder, now limited to a maximum of the first 10 List Items.
Hi @bwn, I think that is the best solution as the ListSlicer that takashi suggested has a python compatability issue which I can't change on my work FME version as they are still at 2.7. Thanks again. John
Hi @takashi, This is a good transformer and does what I want except there is a python compatabily issue when I download it. I cannot change this where I work as they are still using 2.7 and a new version may cause problems on FME Server. Thanks again, John
Hi @takashi, This is a good transformer and does what I want except there is a python compatabily issue when I download it. I cannot change this where I work as they are still using 2.7 and a new version may cause problems on FME Server. Thanks again, John
The transformer supports both Python 2.7 and Python 3.x, so you can just change the Python Compatibility parameter to 3.x+ after adding the transformer.
Addition, I updated the transformer in the Hub to change the default Python version to 3.x+. You can also replace the transformer with the new one.
Hi @bwn, I think that is the best solution as the ListSlicer that takashi suggested has a python compatability issue which I can't change on my work FME version as they are still at 2.7. Thanks again. John
It's worth keeping an eye on performance. Whilst exploding and rebuilding the list will work, if your lists have hundreds of elements it may be much slower to do this than using the custom transformer or a python solution
You can use the AttributeKeeper to keep a certain amount of list attributes.
Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.
It's hardly elegant, but if it's just 10 values for one attribute, you could use an AttributeCopier; i.e. copy
alist{0}.myattribute to anotherlist{0}.myattribute
alist{1}.myattribute to anotherlist{1}.myattribute
...and so on, for all ten attributes.
You can use the AttributeKeeper to keep a certain amount of list attributes.
Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.
Oh, very good solution. I'd no idea that was even possible!
If you always keep first 10 elements, the BulkAttributeRemove could also be an easy solution.
e.g.
If you always keep first 10 elements, the BulkAttributeRemove could also be an easy solution.
e.g.
Yes, similarly I thought the BulkAttributeRemover alternative would also work @takashi. It was some of your similar posts on using RegEx and BulkAttributeRenamer that really show how List Attributes are just Normal Attributes with an Attribute Name of ListName{indexvalue} and hence can be manipulated just like any other regular Attribute.
The only thing is it gets trickier to write the RegEx when you get variations of like "the first 35 elements" etc. , but from a performance perspective, one of the best ways of doing it rather than use ListExploder.
You can use the AttributeKeeper to keep a certain amount of list attributes.
Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.
Similarly that's a new one for me! I'd only every used a single index value rather than a range since that is the default Dialog value.....but I guess it pays to RTFM!