Solved

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


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

icon

Best answer by geomancer 4 July 2022, 16:23

View original

7 replies

Userlevel 4
Badge +36

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

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'.

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?

Userlevel 4
Badge +36

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

Userlevel 4
Badge +36

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

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

Userlevel 4
Badge +36

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

Reply