Hi,
Â
Â
it depends on what you want to accomplish, but there is the NullAttributeMapper that could be helpful in this case.
Â
Â
David
Thank you for your prompt answer.
Â
Â
first the problem is I am going to do a validity check based on a set of given values. On of the condition is if the attributes are empty then it should terminate the rest of process. So NullAttributeMapper won't output only the empty attribute.
Â
Â
Secondly, In general Is there any way to for example see if there is a specific value in a set of attributes(In tester for each attribute it should be written separately and when I wanna check for more than one value(like 20 values) it is time consuming) like the function we have in attributefilter.
Â
Â
Thank you
Â
Mani
Hi,
Â
Â
There doesn't seem to be a transformer that exactly fits to your requirement. But the Tester with a test condition like "attr =" (right value is blank) can test whether "attr" is Empty or Null or Missing, since = operator doesn't distinguish the trio. Even though there are 20+ attributes to be tested, I don't think setting 20+ conditions in a Tester is so troublesome.
Â
Â
If a more flexible way (easier to set/change target attributes) is required, I would create a custom transformer wrapping a simple Tcl script.
Â
The implementation would be:
Â
- Create a published parameter. Type: Attribute List (space delimited).
Â
- Fetch the parameter value - i.e. a string containing space delimited attribute names with a ParameterFetcher to save it as an attribute. e.g. named "_attrs".
Â
- Add a TclCaller to check if one of the attributes contains Empty or Null, or is Missing. This procedure example returns 1 if an attribute is empty or null or missing; otherwise returns 0.
Â
-----
Â
proc checkEmptyNullMissing {} {
Â
   foreach attr FME_GetAttribute "_attrs"] {
Â
       if {
            return 1Â
       }Â
   }Â
   return 0Â
}Â
-----Â
- Route the feature to different output port according to the result.Â
Â
Naturally Python can also do the same thing, but I think Tcl is easier since space delimited attribute names can be treated directly as a list for the iteration.Â
Â
One more.Â
If you rename the attributes so that those can be populated into a list using the ListPopulator or the ListExpressionPopulator, you can create a list containing the attribute values, and then the ListSearcher can be used to check if the list contains a specific value.Â
Â
Takashi
Thank you Takashi.
Â
Â
The second solution seems really interesting. I've never worked with TcLCaller and don't know about TcL and I really like to know how it works.
I tried to do step by step like what you wrote here but I have problem. Here is what I did in custom transformer:
Â
Â
1- I created a published parameter (type --> Attribute List (space delimited)) named=FEATURE ATTRIBUTES
Â
2- In the next step I add ParameterFetcher give published parameter as Parameter Name and _attrs as Target Attribute.
Â
3- In TclCaller in Tcl Expression I put the code you wrote.
Â
Â
proc checkEmptyNullMissing {} {
Â
   for each attr rFME_GetAttribute _attrs] {
Â
       if { string equal FME_GetAttribute $attr] {}]} {
Â
           return 1
Â
       }
Â
   }
Â
   return 0
Â
}
Â
Â
(the rest I don't know how to configure to have the result)
Â
Â
I have also problem because I have values in integer and not string. Does it have any effect in our case?
Â
Â
Can you please help me for the rest?
Â
Â
Best regards,
Â
Mani
Â
Â
Basically the Tcl interpreter treats every variable as a character string except when performing numeric calculations, so the returned value from a procedure can also be treated as a string, even though the representation is a number. i.e. "0" or "1" in the example.
Â
And the returned value will be stored in an attribute which you specified to the "Destination Attribute" parameter of the TclCaller. "_result" by default.
Â
So you can test the value ("0" or "1") with a Tester.
Â
Â
See also here to learn more about the TclCaller.
Â
TclCaller help (
http://docs.safe.com/fme/html/FME_Transformers/Default.htm#Transformers/tclcaller.htm)
Â
"foreach" is a Tcl command, you can not separate "for" and "each".
It's maybe unnecessary addition... don't forget to set the procedure name - "checkEmptyNullMissing" to the "Tcl Expression" parameter of the TclCaller.
Thank you so much. It works perfectly