Skip to main content
Solved

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

  • July 4, 2022
  • 7 replies
  • 57 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, 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.

7 replies

geomancer
Evangelist
Forum|alt.badge.img+58
  • Evangelist
  • 932 replies
  • 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
  • 46 replies
  • 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

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
  • 46 replies
  • 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

@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+58
  • Evangelist
  • 932 replies
  • 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+58
  • Evangelist
  • 932 replies
  • 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
  • 46 replies
  • July 5, 2022

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+58
  • Evangelist
  • 932 replies
  • July 5, 2022

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