Skip to main content
Solved

How to filter an attribute based on association with other attribute?


smfks911

Hi friends,

 

I would like to filter roads (Name) that passes through more than 2 suburbs (Suburb). I do not see a straight solution in Tester. Can anyone please give me a clue to about this issue?

 

best regards,

FS

Best answer by geomancer

Hi @smfks911​ , if your road name does always end with a space and the type, you can use a Regular Expression to separate this part form the rest of the road name. But be aware that road names come in many variations, and may not always end in the road type!

Extract_Road_Type

View original
Did this help you find an answer to your question?

7 replies

geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • July 4, 2022

The Tester (and similar transformers) test on individual features.

Use an Aggregator (Attributes Only mode, group by name, generate a list of attribute Suburb).

Next use a ListElementCounter to count the number of elements in the list.

Test on the number of elements.

Suburbs


smfks911
  • Author
  • July 4, 2022
geomancer wrote:

The Tester (and similar transformers) test on individual features.

Use an Aggregator (Attributes Only mode, group by name, generate a list of attribute Suburb).

Next use a ListElementCounter to count the number of elements in the list.

Test on the number of elements.

Suburbs

Thanks so much @geomancer​ for a great clue but this process is separating out the road name from the full table. As I want to use the name and suburb field later to create a RoadID, I have selected 'Merge incoming Attributes'.


smfks911
  • Author
  • July 4, 2022
geomancer wrote:

The Tester (and similar transformers) test on individual features.

Use an Aggregator (Attributes Only mode, group by name, generate a list of attribute Suburb).

Next use a ListElementCounter to count the number of elements in the list.

Test on the number of elements.

Suburbs

@geomancer​ sorry to ping you again. Can you please give me another work around?

 

I would like to create two attributes by splitting a 'Road_name' attribute. So when road name is like Harris Rd, I will split them into two attributes 'type' and 'name' by recalling _list{1} and _list{0}. but when the Road_name has three words like David Conway St, I cannot simply do it by recalling _list{0,1}. What else I can do for such situation, i.e. create one attribute by combining two list elements?


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • Best Answer
  • July 4, 2022

Hi @smfks911​ , if your road name does always end with a space and the type, you can use a Regular Expression to separate this part form the rest of the road name. But be aware that road names come in many variations, and may not always end in the road type!

Extract_Road_Type


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • July 4, 2022

Note: the above workspace was made in FME 2020. In newer versions you can use ReplaceRegularExpression or SubstringRegularExpression, see StringFunctions.


smfks911
  • Author
  • July 5, 2022
geomancer wrote:

Note: the above workspace was made in FME 2020. In newer versions you can use ReplaceRegularExpression or SubstringRegularExpression, see StringFunctions.

Thanks a heap @geomancer​. Your solution really worked in one transformer. Before go sleep last night, I sorted to a solution like I used AttributeSplitter to split at the white space, then used listElementCounter to separate that have 2 element or more than two. Then used conditional values in attributeCreator to create Name and Type attributes. But obviously your one is best answer. If you have time, can you please explain what the string functions are doing in this script.attributeSplitterForRoadNameattributeCreationfromList


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • July 5, 2022
geomancer wrote:

Note: the above workspace was made in FME 2020. In newer versions you can use ReplaceRegularExpression or SubstringRegularExpression, see StringFunctions.

Name: @Trim(@ReplaceRegEx(@Value(road_name), \\w+$, ))

@ReplaceRegEx(@Value(road_name), \\w+$, ): find everything after the last space, including the space, replace with a space

@Trim(): remove leading and trailing spaces

 

Type: @Trim(@ReplaceString(@Value(road_name),@Value(Name), ))

@ReplaceString(@Value(road_name),@Value(Name), ):  find the value of attribute 'Name' in attribute 'road_name', and replace with a space

@Trim(): remove leading and trailing spaces

 

Both string functions can be simplified somewhat:

@ReplaceRegEx(@Value(road_name), \\w+$,"")

@ReplaceString(@Value(road_name),@Value(Name),"")

 

And like I said, In newer versions of FME you can use ReplaceRegularExpression or SubstringRegularExpression


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