Question

Create column names from column values.

  • 26 October 2015
  • 8 replies
  • 68 views

Badge
Hello,

 

 

guess this question has been asked here many times, however I still struggle with finding a good answer. 

 

 

 

 

Basically what is happening: this is a table that shows records all possible values of all possible attributes, from all possible objects. However I need to create a table, where column names will be values from the column 'attribute', where each row will be singular object. Real table has much more columns, this is just an extract.

 

 

Resulting table should have one row per 'object_id', attributes created from 'attribute' column and the attributes created should be filled with values from 'value' column. There are going to be a lot of attributes created, not each of those objects has all of those attributes.

 

 

Any help is really appreciated.

 

 

Radek

8 replies

Userlevel 4
Hi

 

 

The easiest is to first create a temporary workspace to read all possible values of the 'attribute' column and use a DuplicateRemover and then manually create the output table based on those. In a second workspace, read your input data and use an AttributeRenamer to rename the value columns, then use an Aggregator (Keep input attributes=Yes, group by=object_id) to assemble your features before writing them.

 

 

A more complex solution could use dynamich schemas, see https://knowledge.safe.com/articles/Samples_and_Demos/Dynamic-Workflow-Tutorial-Destination-Schema-is-Derived-from-List-Attributes

 

 

David
Badge

Hello and thanks for a fast reply.

I am trying to implement this on FME cloud, and quite possibly in a single workspace, therefore i have no idea if any of your suggestions will work.

I have been trying attributepivoter, to no success.

Badge
Just to clarify: I am trying to write a workspace that takes tables from a schema stored in a postgresql database, joins several of those tables to style data with geometry. This table I have sent in this example serves as a way to add and style data with geometry, that are stored elsewhere.
Userlevel 4
Badge +25
Easiest way is to use an AttributeCreator. The attribute to create is the value of the attribute field, and the value of that attribute will be the contents of the value field.

 

 

Like this:

 

 

 

Badge
Easiest way is to use an AttributeCreator. The attribute to create is the value of the attribute field, and the value of that attribute will be the contents of the value field.

 

 

Like this:

 

 

 

I am trying the same thing in FME Desktop 2016 build 16674 and I do not manage to get values as attributes names with this method. Does it still work for 2016 version of FME Desktop?
Userlevel 2
Badge +17
I am trying the same thing in FME Desktop 2016 build 16674 and I do not manage to get values as attributes names with this method. Does it still work for 2016 version of FME Desktop?
Hi @tono, yes, it still works for FME 2016 and 2017. Note that the new attribute name created with this method won't be shown automatically on the Workbench GUI. You can expose the new name with the AttributeExposer if necessary.

 

Badge +1
I am trying the same thing in FME Desktop 2016 build 16674 and I do not manage to get values as attributes names with this method. Does it still work for 2016 version of FME Desktop?

 

I just ran into this as well. Using this approach also seems to wipe out the feature. A inspector showing a single feature before an attribute creator set up like this will show a table with values for all attributes. A inspector placed after this attribute creator will show an empty table. This is with build 16716.

 

 

Update: Actually sorry I take this back. The attribute creator does appear to work--it's the FME Data Inspector Table View that appears to not like the output of this type of attribute creator. My feature is still there with the new attribute--the table view is just empty.
Badge +7
Easiest way is to use an AttributeCreator. The attribute to create is the value of the attribute field, and the value of that attribute will be the contents of the value field.

 

 

Like this:

 

 

 

This was useful for me. I'm reading in various CSVs, each of which has logged a different validation error for the same dataset. Using the AttributeCreator solution above, I can turn the fme_basename into an attribute name and assign it a value of "Fail". The AttributeExposer then makes these attribute names available in the Workspace (slightly annoying they don't appear automatically). I then use an Aggregator (on the unique ID for each record) and NullAttributeMapper (to fill in the <missing> values) to combine the various CSVs into a single output table listing the features that failed validation, and which tests they failed. Thanks everyone.

 

 

Reply