Files
-
- 90 KB
- Download
Introduction
A fanout is a way within FME to split output data based upon the value of an attribute. The data is divided at write time, rather than within the workspace itself (like an on-the-fly AttributeFilter). There are two different kinds of fanout: feature type fanout and dataset fanout. This article will demonstrate both kinds of fanout using a CSV file containing information about community trees.
Step-by-step Instructions
Feature Type Fanout
A feature type fanout writes a single dataset but divides the data into multiple layers/themes/feature types/objects/classes within that dataset.
A feature type fanout. Data is divided into multiple layers based on an elevation attribute.
1. Open the Starting Workspace
Open the FanoutTrees-Start.fmwt template file. This template reads in the CommunityTrees.csv file and then extracts the Year from the DATE_PLANTED attribute using the SubstringExtractor transformer. It then sorts the data in Numeric Descending order using the Sorter transformer. The Sorter ensures that when you view the data in Microsoft Excel, the most recent year appears first and the oldest year appears last.
2. Write Out to Microsoft Excel
Add a Microsoft Excel writer:
- Format: Microsoft Excel
- Dataset: TreesByYear.xlsx
- Sheet Definition: Automation
Click OK to close the Feature Type dialog. We will return to it in a minute. After you add the writer, connect it to the Sorter.
3. Create Feature Type Fanout
Once the writer feature type is connected to the Sorter, open up the parameters:
-
Sheet Name: YEAR_PLANTED attribute
- Click the drop-down arrow next to Sheet Name, expand Attributes, then select YEAR_PLANTED
Creating the fanout this way creates a different sheet for each year within a single Microsoft Excel file.
4. Run the Workspace and View the Results
Save and run the workspace. You can view the results in either the FME Data Inspector or Microsoft Excel. The output will be a single Microsoft Excel file with a sheet for each year.
Dataset Fanout
A dataset fanout divides the data and writes a different dataset for each division.
A dataset fanout. Data is divided into multiple datasets based on an elevation attribute.
1. Open the Starting Workspace (or Continue Working in the Same Workspace)
The starting workspace template for Dataset Fanout is the same as the one for Feature Type fanout, so you can open a fresh workspace or continue in the same one.
2. Write Out to Microsoft Excel
Add a (another) Microsoft Excel writer:
- Format: Microsoft Excel
- Dataset: Output.xlsx
- Sheet Definition: Automation
In the Feature Type dialog:
- Sheet: Trees.
After adding the writer, connect it to the Sorter.
3. Set Dataset Fanout in the Navigator Pane
In the Navigator Pane, expand the Output [XLXSW] writer, then double-click on Fanout Dataset to open the parameters.
- Fanout Dataset: Enabled
- Fanout Expression:
TreesByNeighbourhood\@Value(NEIGHBOURHOOD_NAME)_Trees.xlsxThis expression will create a folder named TreesByNeighbourhood and a Microsoft Excel file for each neighborhood using NEIGHBOURHOOD_NAME. To ensure we know what is in this file, add _Trees at the end. Include the file extension when creating a dataset fanout.
4. Run the Workspace and View the Results
Save and run the workspace. You can view the results in either the FME Data Inspector or a file manager. The output will be a different Microsoft Excel file for each neighborhood, each with a single sheet called Trees.
Combination Fanouts
Setting both a feature type fanout AND a dataset fanout in the same workspace is no problem. The dataset fanout will produce several output datasets, each with a number of layers created by the feature type fanout.
To create a Combination Fanout, follow the steps in both Feature Type Fanout to add the Microsoft Writer and Dataset Fanout for the datasets in Navigator.
Raster Data and Fanouts
Each new Raster format writer generally includes a Feature Type Fanout automatically.
This is so that each outgoing feature (file) is written with the same filename as was read on input; the fanout attribute being fme_basename
One drawback is that the FME Data Inspector’s Open Dataset dialog gets confused when you open the FME Data Inspector from the writer. You will have to manually select the raster files when trying to inspect, or use the asterisk (*) wildcard, ie., *.jpg if all the files are contained in the same folder.
Multi-Attribute Fanouts
Each fanout setting allows a user to select only a single attribute to fan out. However, you can create multi-attribute fanouts by merging attributes using the StringConcatenator transformer.
File vs Folder Datasets
Fanout behavior changes depending on whether you are working with a file-based format or a directory-based format. For instance, an AutoCAD DWG writer (file-based) creates new layers with a feature-type fanout and new drawings with a dataset fanout. An Esri Shapefile writer (directory-based) will create new shapefiles on a feature-type fanout and new directories on a dataset fanout.
This table explains the different combinations you can get:
| Format/Fanout Type | Feature Type Fanout | Dataset Fanout | Feature Type AND Dataset |
| Directory (e.g., Esri shapefile) | One directory with multiple files | Multiple directories with one file | Multiple directories with multiple files |
| File (e.g. Microsoft Excel or OGC GeoPackage) | One file with multiple layers | Multiple files with one layer | Multiple files with multiple layers |
Batch Processing
When combined with input aggregation features, you can often get away with doing all of your translations in a single workspace, in a sort of pseudo-batch process.
"Batch" processing with fanouts. For each dataset that enters the workspace, it outputs a similarly named dataset.
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.