Including Dates into the Names of Output Files or Features

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2018.x

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 DateTime attribute on the dataset using DateTimeStamper
  • Use DateTime Functions (DateTimeConvertor) to extract month name from 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, DGN, can assign data to different layers within a single file using Dataset Fanout . In this example, we will create an attribute, then use DateTimeStamper and DateTimeConvertor transformers to generate an ACAD output file with the first 3 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.

open-generate.png

 

Complete 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 have no attribute with date values, so we are going to add a date attribute. Add a DateTimeStamper transformer on the canvas and insert it between reader and writer feature types. Set the transformer properties as follows:

datetimestamper-ex1.png

Set Result Attribute to _month.

The attribute created by the DateTimeStamper stores 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 DateTimeConvertor and connect it to the DateTimeStamper output port.

Set the transformer properties as follows:

Datetime Attributes: _month

Output Format: %b

datetimeconvertor.png

NOTE: Expand Quick Reference to check all the functions available

 

4. Setting Output Filename

The next step is to use the newly generate date attribute in the destination file name using dataset fanout . Connect the output port of DateTimeConverter to ACAD writer.

  • In the Navigator window, expand ACAD writer and click on ‘Fanout Dataset’.

    dataset-fanout.png

  • Open Fanout Expression dialog by clicking on the ellipsis button. In the text-editor window add the following expression.
Parks_@Value(_month).dwg

 

fanout-dataset.png

 

5. Run workspace

Run the workspace by pressing F5 clicking on the Run button on the toolbar. Confirm that the result as shown under Result.

 

Workspace

The workspace after completion should appear as below.

complete-ex1.png

 

Result

Run the workspace and open the Output directory. Notice that the file name contains the month value as expected.

result-ex1.png

 

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 are going to 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 on Generate Workspace.

open-generate.png

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 have no attribute with date values, so we are going to add a date attribute. Add a DateTimeStamper transformer on 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 destination file using feature-type fanout.

  • Open the writer FeatureType properties dialog.
  • Under Parameters tab > General > TableName.
  • Click the drop-down button and select _timestamp attribute as the input

featutetype-fanout.png

 

4. Run workspace

Run the workspace by pressing F5 clicking on the Run button on the toolbar. Confirm that the file is written with date, as shown under Result

 

Workspace

The workspace after completion should appear as below.

 

complete-ex2.png

 

Result

Run the workspace and open the Output directory. Notice that the file name contains the current date.

result-ex2.png

Please follow the link for more information on Data Fanouts.

 

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.

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.