Skip to main content
Question

Writing out to csv in columns rather than rows

  • 15 November 2012
  • 5 replies
  • 29 views

Hi,

 

 

I ahve a query regarding writing out coordinates to a csv file. Been pulling my hair out trying to sort it for the last while but can't figure it out. I reckon i'm either missing something stupidly small or it just can't be done!

 

 

Basically my simple workspace is reading in a .tab file, using the CoordinateConcantenator to retrieve each feature's coordinates and then using an AttributeSplitter to split the coordinate values into sperate list attributes.

 

 

When I write it to a csv file the first Row contains the attributes of the first feature, second row containing the attributes of the second feature and so on...

 

 

What I want to do it have the first Column of the csv containing the first feature, second column containing the attributes of the second feature etc, so basically flipping the layout of the csv file.

 

 

Any suggestions greatly appreciated!

 

 

Cheers,

 

TK
Hi TK,

 

 

Have a look here

 

http://fmepedia.safe.com/articles/Samples_and_Demos/Pivot-table

 

 

Hope this helps.
If I'm understanding your question correctly, you want to change:

 

 

1,2

 

3,4

 

 

to:

 

1,3

 

2,4

 

 

If so, this is not the default way that FME works as it writes each feature to its own row in a chronological order.

 

 

However, to beat the system, either use Itay's suggestion of a Pivot table or:

 

I believe I've done it by using AttributeCopiers, AttributeSetters and the @Value macro. However I've uploaded a quick and dirty method that I've just tested to:

 

http://demo.1spatial.com.au/Images/tmp/ReverseColsAndRows.png

 

 

Have fun!

 


Hmm thought i'd replied to this a few weeks back, must have forgotten to click submit!

 

 

Anyway, thanks for both the answers. Kathy, I tried to follow the workspace you put together. However I came across a few issues.

 

 

On your AttributeSplitter it is outputting a number of _list2 attributes:

 

_list2{}

 

_list2{0}

 

_list2{1}

 

_list2{2}

 

 

However, when I set my workspace identically (except with 6 features rather than 3) it is only creating one _list2 attribute.

 

Also it doesn't allow me to link the attributes from my AttributeSplitter to my Writers.

 

 

Am I missing something small here? 

 

 

Thanks,

 

TK
Sure, I simply exposed a few elements of the list.

 

 

Right click on the _list2{} attribute below a transformer and select to Expose Elements.
Thanks Kathy,

 

I'd completely forgotten about this issue, i managed to work it out myself after a few hours!

Reply