CSV Writer Workspace
From fmepedia
| Table of contents |
Scenario
A common user requirement is to convert data held as plain X/Y coordinates into true spatial features. However, sometimes the opposite operation is required.
This workspace converts spatial features into a plain text, comma delimited (CSV) file. It is taken from an advanced module in the FME Desktop training course.
The data required to run the workspace is part of the FME Sample Dataset (http://www.safe.com/support/onlinelearning/fmesampledata.php).
Data
This example can be modified very easily to handle any source, but in this case the source data is a set of park features in MapInfo TAB format. The destination data is to be a CSV dataset with the structure:
<park name> <x coordinate>,<y coordinate> <x coordinate>,<y coordinate> <x coordinate>,<y coordinate> ... <park name> <x coordinate>,<y coordinate> <x coordinate>,<y coordinate> etc...

Above: One of the source features and how the output will look.
Workspace Detail
The workspace:
- The Deaggregator deaggregates any aggregate features, and the Counter creates a unique ID for each feature.
- If your source data is not aggregated, and already has unique IDs, obviously you will not require these steps.
- Splits into two streams. The first stream is to create a header record for each feature.
- In this case the header is simply the park name (created with AttributeCopier, but you may wish to be more detailed than that.
- A coordinate ID is created and set to -1 (to identify the header) using the AttributeCreator.
- The second stream is the part handling the spatial data.
- The CoordinateConcatenator extracts a list of coordinates for each feature
- The AttributeSplitter turns the coordinates into a true FME list attribute
- The ListExploder explodes the list into a separate feature per coordinate pair
- A second Counter creates a unique ID per coordinate
- The Sorter merges the header and spatial data back together and sorts them into the correct order - this is the reason for the feature and coordinate IDs

