Files
Introduction
In this article, we will perform a couple of translations demonstrating how to use date/time attribute values in destination filenames. These workflows are useful in scenarios such as Status Reports, Work Schedules, and Maintenance Schedules.
This article helps you to understand the following:
- How to set the DateTime attribute on the dataset using DateTimeStamper
- Use DateTime Functions (DateTimeConverter) to extract the month name from the date attributes
- Use Data Fanouts on File and Folder-based formats. The behavior of fanout changes based on whether you are working with a file-based format or a directory-based format. For instance, a DWG writer (file-based) will create new layers with a feature type fanout, and new drawings with a dataset fanout. A SHAPE writer (directory-based) will create new shapefiles on a feature-type fanout and new directories on a dataset fanout.
Step-by-Step Instructions
Example 1: File-based formats
File-based formats such as GML, DWG, and DGN can assign data to different layers within a single file using Dataset Fanout. In this example, we will create an attribute and then use the DateTimeStamper and DateTimeConverter transformers to generate an ACAD output file with the first three letters of a month in the filename. The complete workspace is available in the Downloads section (date-in-file-based-ex1.fmwt)
1. Generate a New Workspace
Open FME Workbench and click on Generate Workspace.
Complete the dialog, using the following information:
- Reader Format: MapInfo TAB
- Dataset: Parks.tab (see Downloads section)
- Writer Format: MITAB
- Dataset: C:\Temp\Output\Parks.dwg
2. Create Date Attribute
The input data does not contain any attributes with date values, so we will add a date attribute. Add a DateTimeStamper transformer to the canvas and insert it between the Reader and Writer feature types. Set the transformer properties as follows:
Set Result Attribute to _month.
The attribute created by the DateTimeStamper stores the system-generated current date as YYYYMMDD
3. Format Date Attribute
As _month attribute stores date in format YYYYMMDD and we want output filenames to contain the first three letters of a month. To achieve this, we will use DateTime functions. Add a DateTimeConverter and connect it to the DateTimeStamper output port.
Set the transformer properties as follows:
-
Datetime Attributes:
_month -
Output Format:
%b
Expand Quick Reference to check all the functions available
4. Setting Output Filename
The next step is to use the newly generated date attribute in the destination file name using dataset fanout. Connect the output port of DateTimeConverter to the ACAD writer.
-
In the Navigator window, expand ACAD writer and click on ‘Fanout Dataset’.
- Open the Fanout Expression dialog by clicking on the ellipsis button. In the text editor window, add the following expression:
Parks_@Value(_month).dwg
5. Run Workspace
Run the workspace by pressing F5 or clicking the Run button on the toolbar. Confirm that the result is shown under Result.
Workspace
The workspace after completion should appear as below.
Result
Run the workspace and open the Output directory. Notice that the file name contains the month value as expected.
Example 2: Folder-based Formats
This example includes folder-based writers such as SHAPE and MITAB (formats that do not have a way to assign data to different layers within a single file). For this exercise, we will use DateTimeStamper in conjunction with feature-type fanout. The DateTimeStamper adds a date to our features, and feature-type fanout generates separate files based on that date value. The complete workspace is available in the Downloads section (date-in-folder-based-ex2.fmwt)
1. Generate a New Workspace
Open Workbench and click "Generate Workspace."
- Reader Format: MapInfo TAB
- Dataset: Parks.tab (see Downloads section)
- Writer Format: MITAB
- Dataset: C:\Temp\Output\Parks.tab
2. Create Date Attribute
The input data does not contain any attributes with date values, so we will add a date attribute. Add a DateTimeStamper transformer to the canvas and insert it between the Reader and Writer feature types.
Set the transformer properties as follows:
- Type: Date
- Result Attribute: _timestamp
The attribute (_timestamp) stores system-generated current date as YYYYMMDD
3. Setting File-name
The next step is to use this newly generated date attribute to name the destination file using feature-type fanout.
- Open the writer FeatureType properties dialog.
- Under the Parameters tab > General > TableName.
- Click the drop-down button and select the _timestamp attribute as the input
4. Run Workspace
Run the workspace by pressing F5 or clicking the Run button on the toolbar. Confirm that the file is written with the date, as shown under Result
Workspace
The workspace after completion should appear as below.
Result
Run the workspace and open the Output directory. Notice that the file name contains the current date.
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.