Question

attributeExists check

  • 20 October 2014
  • 18 replies
  • 139 views

Hi,

 

 

I am going to check if a set of attributes exists in my feature.

 

For example I have "measuredHeight, CreatinDate, Function" and I want to see if the feature that I have, has all these three titles as the seperated attributes.

 

First I am wondering to know if there is any way to do this without writing any script?!

 

 

The second is, I think it is very easy to do it in TclCaller with "FME_AttributeExists <attributeName>"

 

But I don't know how can I ask it to check if the three above mentioned(pre-defined) attributes exist or not(Normally I have them as a text defined through published parameter).

 

 

I appreciate your advice in advanced!

 

Mani

 

 

18 replies

Badge +2

 

HI,

 

 

I understood that you have single attribute with 3 attributes and you want the features which have all the 3 attributes defined.

 

In FME,use attributer splitter and tester with "and" for this purpose.

 

 

Pratap

 

 
No! I think I explained it not clearly. I have to check if my feature class has three attributes with these names:

 

 

 

1) measuredHeight

 

2) CreatinDate

 

3) Function

 

 

if not it should raise and error.

 

 

So Actually I want to determine if my interested attributes are present on a feature.

 

 

Mani

 

 

 
Userlevel 4
Hi,

 

 

you can use a Tester:

 

 

 

 

Make sure that you leave the "Right value" blank and that the pass criteria is set to AND.

 

 

Connect the Failed port to a Terminator if you want to stop the translation when a feature with one or more of these attributes are missing.

 

 

David

 

 

why should it work like this?

 

 

because when e.g. the attribute CreationDate does not exist then the tester does not check it. I think you are going to test here the content of the attribute not the existence of the attribute itself.

 

Actually I don't care if the values of these attributes are valid/Null/etc. I just wanna know if they exist because in the next step they should be populated by some other department and my task is the validity check of the data.

 

 

And these names are not fixed, from feature to feature they differ. My idea is to define a Custom transformer with a published parameter to give these names and check the availability of the attributes(columns) with the identical names(set by user). If they are passed, the data is ready for the next department to work on it. Otherwise I should send them back.

 

 

any further idea?

 

 

Thank you.

 

Mani

 

 
Userlevel 4
Hi,

 

 

why should it not work like this?

 

 

As per usual, there are several ways to accomplish the same thing with FME. You can also look at the NullAttributeMapper that has the option of checking for missing attributes (as oppposed to empty attributes). You can then map those to a dummy value e.g. "ATTRIBUTE_IS_MISSING" and check for that value with a Tester.

 

 

Alternative solutions could include using the AttributeExploder.

 

 

Creating a custom transformer for this sounds like a good idea.

 

 

David

 

 
Badge +3
HI,

 

 

Prior to 2014 there was a "attribute exists" in the tester. It has now become "attribute is missing". And it is available in the tester.

 

 

( check wiki.tcl.tk/17441 for a discussion on null, missing etc.)

 

 

Testing for a empty value is not the same afaik.

 

 

 

And you can (as Daid suggests) explode the attributes (or read schema) and then listbuild on a common value ( if this doesnot exist, create a common value: i ususualy do somthing like "concatThis" =1)

 

Then, if you dont want to use tcl, just concat the _attribute_value{} by 'concatThis" to something like "attributes_list"

 

Use tester to test for "lookedupAttribute" IN "attributes_list".

 

 

 
Badge +3
...Daid =David.

 

 

If u indeed make it a custom transformer, you can make "lookedupAtribute" a parameter, of course.

 

 

 

If you want to test multiple attributes to existing attributes, your can have your published parameter accept input like "attt1,att2,att3". 

 

Attributesplitter to turn it in a list and exploder to turn it into attributevalues. Explode "attributes_list{}" as well and then use a featuremerger to compare them.

 

 

Thank you David. The tester doesn't work because if you have a look to the image, I need to check if in the feature class "Building" I have the attributes "gml_id" and "citygml_function". When I use tester like what you suggested, It passes the feature although I don't have citygml_function.

 

 

As I said because It checks the content of attribute and not the existence of the attribute itself.

I think NullAttributeMapper does not work in my case as well. At least I coudn't understand it.

 

 

Thanks again for your time.

 

 

Mani
Thank you Gio. I will check your solution.

 

 

Mani
Badge +3
did you try the "attribute is missing" operator ??? (no realy a operator, but it is found there at the bottom of the list)

 

 

This replaced the "attribute exists" since fme2013 version.
Userlevel 2
Badge +17
Hi Mani,

 

 

Look at icons displayed at the head of Left Value column. Arrow means an attribute value; "k" means a constant. So the second test condition "the string 'citygml_function' is not empty" is always true.

 

 

Takashi
Hi Takashi and thank you for your tip.

 

 

Gio, "attribute is missing" works. I had a bit problem because I am using CityGML and when the attribute is missing in the source file it still appears as an attribute in FME but instead having "missing" as the value. First I was confused! But now I think this part is solved :).

 

 

Now I am working to make it as a custom transformer as you suggested.

 

 

BTW, Thank you David, Takashi and Gio for your advice and help!

 

 

Best regards,

 

Mani
Badge +3
<missing>, <null> are not "values". They are not strings.

 

More like a placeholder for an indication that there is no pointer to any register, empty pointer.
Badge +7

I've just had the same requirement for checking fields exist in a CSV file and have solved it using AttributeValidator. Under Attributes to Validate, select the fields you want to check exist (in my case I selected all fields). Under Validation Rule select "Has a Value".

If features come out of the "Passed" port, you know it's OK. If they come out of the "Failed" port you can act accordingly e.g. log the problem features, send an email, terminate the Workspace.

I guess this won't necessarily work for all Readers, for example the Excel Reader with "Read blank cells as" set to Null.

Userlevel 5
Badge +25

I've just had the same requirement for checking fields exist in a CSV file and have solved it using AttributeValidator. Under Attributes to Validate, select the fields you want to check exist (in my case I selected all fields). Under Validation Rule select "Has a Value".

If features come out of the "Passed" port, you know it's OK. If they come out of the "Failed" port you can act accordingly e.g. log the problem features, send an email, terminate the Workspace.

I guess this won't necessarily work for all Readers, for example the Excel Reader with "Read blank cells as" set to Null.

The Tester and TestFilter can check for null and empty attributes as well.

 

 

Userlevel 2
Badge +16

Tester and TestFilter have the option to test for Attribute has a Value (Not Null, Not Empty and not Missing).

Same option as the AttributeValidator mentioned by @tim_wood.

Userlevel 2
Badge +17

Note that the "Attribute has a value" operator won't distinguish <empty>, <null> and <missing>. If you want to determine if an attribute exists literally (an attribute isn't missing in other words), you will have to use the "Attribute Is Missing" operator.

Badge +11

You should use the AttributeExploder transformer. This transformer takes any of your attributes and converts them into new Attributes "name" and "value". In your example you'll get three features with following attribute pairs:

Feature 1: name = measuredHeight, value = XXXX

Feature 2: name = CreatinDate, value = XXXX

Feature 3: name = Function, value =XXXX

By doing so, you transform the attribute into a value of another attribute. Therefore you can use the Tester on the "name" attribue and check if some specific value is there or missing.

As you want to check the global schema of your geodatabase, make sure that you're inserting just the first record of your database table to avoid unnecessary, and time consuming checks.

Reply