Solved

Extracting range of attribute values


Badge +6

I have a col A which has values from 1-5. Can we get the list of all values of col A from 1-5. If so, could you please help me with the logic.

Thanks!

icon

Best answer by lenaatsafe 3 October 2017, 01:11

View original

18 replies

Userlevel 2
Badge +17

I can see two numbers concatenated with a hyphen for each cell in the col A (EVENTIDRAN field).

"737055 - 737060", "737061 - 737066", ...
Do you need to get all the individual values from them?
"737055", "737060", "737061", "737066", ...
Badge +11

Hi @fmeuser_gc - I feel that there will be more than one solution,.. but here is an example workspace template that you can use or build upon. This workspace will add attributes _valx for each integer in the range defined by EVENTIDRAN.

Edit: This workspace was built with FME 2017.1.1 Build 17650 – if incompatible with your FME, the meat and bones of this workspace is included in the image below!

example-extractvaluefromrange.fmwt

Note: It relies on the values of EVENTIDRAN to always be a range that covers six integers, inclusive.

Badge

Hi @fmeuser_gc

one more possible approach could be to:

  • create a copy of the original feature for each value in the EVENTIDRAN range;
  • calculate the corresponding range value for each copy;
  • merge all copies into single feature and store all range values as a list.

This will allow you to process ranges that include different number of values.

Badge +6

I can see two numbers concatenated with a hyphen for each cell in the col A (EVENTIDRAN field).

"737055 - 737060", "737061 - 737066", ...
Do you need to get all the individual values from them?
"737055", "737060", "737061", "737066", ...
Yes I need all individual values like 737055, 737056, 737057, 737058, 737059, 737060.

 

 

Badge +6

Hi @fmeuser_gc - I feel that there will be more than one solution,.. but here is an example workspace template that you can use or build upon. This workspace will add attributes _valx for each integer in the range defined by EVENTIDRAN.

Edit: This workspace was built with FME 2017.1.1 Build 17650 – if incompatible with your FME, the meat and bones of this workspace is included in the image below!

example-extractvaluefromrange.fmwt

Note: It relies on the values of EVENTIDRAN to always be a range that covers six integers, inclusive.

Thank You but it didn't work for me in 2015.1 version. I've tried using AttributeCreator (in 2015.1) instead of AttributeManager (in 2017v).

 

 

Badge +11
Thank You but it didn't work for me in 2015.1 version. I've tried using AttributeCreator (in 2015.1) instead of AttributeManager (in 2017v).

 

 

@fmeuser_gc - Attached is a version that will work in 2015.1.3.2 – same basic idea with the AttributeCreator! :)

 

example-extractvaluefromrange-20151.fmwt

 

Badge +6

Hi @fmeuser_gc - I feel that there will be more than one solution,.. but here is an example workspace template that you can use or build upon. This workspace will add attributes _valx for each integer in the range defined by EVENTIDRAN.

Edit: This workspace was built with FME 2017.1.1 Build 17650 – if incompatible with your FME, the meat and bones of this workspace is included in the image below!

example-extractvaluefromrange.fmwt

Note: It relies on the values of EVENTIDRAN to always be a range that covers six integers, inclusive.

It still didn't work. I was able to get values as x, x+1, x+2, x+3..

 

 

 

Badge +11
It still didn't work. I was able to get values as x, x+1, x+2, x+3..

 

 

0684Q00000ArMPNQA3.jpg

 

@fmeuser_gc - What do you have in the AttributeCreator? Does the expression include the "@Evaluate()" function?

 

@Evaluate(@Value(_range{0})+1) 
Badge +6

Hi @fmeuser_gc - I feel that there will be more than one solution,.. but here is an example workspace template that you can use or build upon. This workspace will add attributes _valx for each integer in the range defined by EVENTIDRAN.

Edit: This workspace was built with FME 2017.1.1 Build 17650 – if incompatible with your FME, the meat and bones of this workspace is included in the image below!

example-extractvaluefromrange.fmwt

Note: It relies on the values of EVENTIDRAN to always be a range that covers six integers, inclusive.

Yes it worked now after including the Evaluate fn.

 

But the tricky part is EVENTRANGE is not always a specific set of range. It can be any numbered range and has to be dynamic. Would it be possible to make it dynamic?

 

 

For ex: Range 5-10 and if we define for x, x+1, x+2, x+3. In this case we will end up missing values of 9, 10.

 

 

Badge +11
Yes it worked now after including the Evaluate fn.

 

But the tricky part is EVENTRANGE is not always a specific set of range. It can be any numbered range and has to be dynamic. Would it be possible to make it dynamic?

 

 

For ex: Range 5-10 and if we define for x, x+1, x+2, x+3. In this case we will end up missing values of 9, 10.

 

 

@fmeuser_gc - Ah, yes.. My example definitely relied on a fixed range size as I had noted. If you need to work with dynamic ranges, hopefully the MINEVENT and MAXEVENT are accurate – because you could then use a loop (e.g. with TestFilter) to count up each iteration from MINEVENT until the value of MAXEVENT is reached. This idea would likely have FeatureMerger in the mix too... To summarize, yes I think it is possible to make it dynamic.

 

 

I suggest that you give it a try – the FME Community will be here to help! You may find it useful to create separate Q&A; postings based on what part of the workflow you need help with.

 

Badge +6
@fmeuser_gc - Ah, yes.. My example definitely relied on a fixed range size as I had noted. If you need to work with dynamic ranges, hopefully the MINEVENT and MAXEVENT are accurate – because you could then use a loop (e.g. with TestFilter) to count up each iteration from MINEVENT until the value of MAXEVENT is reached. This idea would likely have FeatureMerger in the mix too... To summarize, yes I think it is possible to make it dynamic.

 

 

I suggest that you give it a try – the FME Community will be here to help! You may find it useful to create separate Q&A; postings based on what part of the workflow you need help with.

 

I have a hard time in getting this loop. Tried using Tester and TestFilter but no luck.

 

 

Userlevel 2
Badge +17

If the number of values within a range could be different for each row, the method suggested by @LenaAtSafe can be applied.

Alternatively, the AttributeSplitter + PythonCaller with a small script could also be a solution. For example, assuming that the hyphen-separated range values has been split into _list{0} and _list{1} with the AttributeSplitter beforehand, a PythonCaller with this script stores every value within the range into a list attribute called "_value{}".

# PythonCaller Script Example
def extractRangeValues(feature):
    s = int(feature.getAttribute('_list{0}'))
    t = int(feature.getAttribute('_list{1}'))
    for i, v in enumerate(range(s, t+1)):
        feature.setAttribute('_value{%d}' % i, v)<br>
Badge +6

Hi @fmeuser_gc

one more possible approach could be to:

  • create a copy of the original feature for each value in the EVENTIDRAN range;
  • calculate the corresponding range value for each copy;
  • merge all copies into single feature and store all range values as a list.

This will allow you to process ranges that include different number of values.

Hi @LenaAtSafe - This worked. Able to get all ranges of values. Thanks much!

 

Badge +6

Hi @fmeuser_gc

one more possible approach could be to:

  • create a copy of the original feature for each value in the EVENTIDRAN range;
  • calculate the corresponding range value for each copy;
  • merge all copies into single feature and store all range values as a list.

This will allow you to process ranges that include different number of values.

Hi @LenaAtSafe, Any idea how to do the otherway, meaning dynamic higher to lower range.

 

 

For ex: To read from 10 to 5 or 19 to 12

 

 

Currently I'm reading from dynamic lower to higher range. Ex: 5 to 10, 12 to 19.

 

 

Badge +6

I can see two numbers concatenated with a hyphen for each cell in the col A (EVENTIDRAN field).

"737055 - 737060", "737061 - 737066", ...
Do you need to get all the individual values from them?
"737055", "737060", "737061", "737066", ...
Hi @takashi, any idea how to do other way around from higher to lower range.

 

For ex; 737060 - 737055 should be exploded as 737055, 737056, 737057, 737058, 737059, 737060

 

Userlevel 2
Badge +17
Hi @takashi, any idea how to do other way around from higher to lower range.

 

For ex; 737060 - 737055 should be exploded as 737055, 737056, 737057, 737058, 737059, 737060

 

If you adopted the solution @LenaAtSafe provided, you can insert a ListSorter between the AttributeSplitter and the Cloner to sort the elements of the list by numeric ascending.
Badge +6

@takashi, @LenaAtSafe - I also encountered values with multiple ranges within single field (For ex: 1-5, 6-10 in single field) which causing it to fail.

It was working earlier for only single range values say 1-5 in a single field.

Apologize many questions on this scenario.

Userlevel 2
Badge +17

@takashi, @LenaAtSafe - I also encountered values with multiple ranges within single field (For ex: 1-5, 6-10 in single field) which causing it to fail.

It was working earlier for only single range values say 1-5 in a single field.

Apologize many questions on this scenario.

You can split the comma separated multiple ranges (e.g. "1-5, 6-10") with an AttributeSplitter (Delimiter: ,) and explode the resulting list with a ListExploder. You can then apply @LenaAtSafe's method to individual single range (e.g. "1-5").

 

Reply