Writes the contents of an attribute to a text or binary file.
- Writing files mid-workspace that contain the value of an attribute
- Replacing a writer where the desired content is stored as an attribute
- Writing images that have been stored as blob attributes
- Writing coordinate system information to a file
- Writing text lists of attribute values
How does it work?
The AttributeFileWriter receives any type of feature and writes the contents (value) of a specified attribute to an external file.
A Target Filename and encoding type must be specified. File names may be provided explicitly or by attribute value, expression, user parameter, or conditional value. If a target file already exists, it may be overwritten or appended to.
The attribute value and target file may be text or binary. A variety of encoding choices are available for text files. Binary files should be designated as Binary (fme-binary), as the transformer writes it as-is and will simply preserve the attribute contents as a Blob.
In this example, we have a shape file of city parks. Some of them are dog parks, and we want to write a text file containing all of their names.
Note that the source data has 28 attributes, including DogPark and ParkName.
This will take three steps:
- Use a Tester to identify only the dog parks.
- Add a carriage return to the park name with an AttributeManager.
- Write a text file with the AttributeFileWriter.
In the parameters dialog of the Tester, we create one Test Clause, looking for DogPark = Y.
Next, we need to add a carriage return to the end of the attribute so that each one will be written on a separate line.
In the parameters dialog of an AttributeManager, we use the Text Editor to construct an expression that will add the special character to the existing ParkName attribute value.
The final step is to write the text file. In the parameters dialog of the AttributeFileWriter, we choose the ParkName attribute and set a Target Filename.
If Target File Exists is set to Append to file, and a text encoding is chosen.
The output file, as examined here in Notepad, contains the dog park names.
A variation on this would be to add <p> tags around each line, with a <br> tag line break, to write the output as very basic HTML.
In this example, we have a database table that contains the locations of public art installations. Each record has an image of the art, stored as a blob, in a bytea type column named blob_image.
We want to write all of the images to individual binary files, and know that they have been stored in the blob field as JPGs.
The features are routed from the database reader to an AttributeFileWriter.
In the parameters dialog, the Source Attribute is set to blob_image. A path and filename are specified, and the name includes the attribute value of registryid to create unique file names.
If Target File Exists is set to Overwrite file, and the Target File Encoding is set to Binary (fme-binary). The transformer does not know that the images are encoded as JPEGs - it will just preserve what it receives.
In the output directory, one file is created for each feature.
Note that even though JPEG encoding was not explicitly specified, using Binary (fme-binary) preserved the original encoding and produced a usable JPG file.
- When writing any binary file types, ensure that Target File Encoding is set to Binary (fme-binary).
- Full path names can be created from existing attribute values by using the Text Editor to create an expression.
- The most common text encodings are Windows Latin-1 (windows-1252) and Unicode 8-bit (utf-8).
- If you are unsure of the encoding used by the attribute, the Feature Information window in the FME Data Inspector will often help (see image in previous example)
Features with attributes to be written to files.
Unmodified features. Files will have been written as specified in the parameters.
If an invalid filename is specified, the feature will be routed to the <Rejected> port. Rejected features will have an fme_rejection_code attribute with one of the following values:
Rejected Feature Handling: can be set to either terminate the translation or continue running when it encounters a rejected feature. This setting is available both as a default FME option and as a workspace parameter.
Name of the attribute whose value will be written out to a file.
The name and location of the file to be written.
It may be specified explicitly or by attribute value, expression, user parameter, or conditional value.
If Target File Exists
Specifies the action to take if the target file already exists.
Note that when appending to a text file, you may want to add a special character (newline or carriage return) to the attribute value prior to the AttributeFileWriter.
Target File Character Encoding
The character encoding of the target file. The default encoding is System default (fme-default).
Note that binary files must be specified as Binary (fme-binary) regardless of type.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.
Using the Text Editor
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
Using the Arithmetic Editor
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
|These functions manipulate and format strings.|
|A set of control characters is available in the Text Editor.|
|Math functions are available in both editors.|
|Date/Time Functions||Date and time functions are available in the Text Editor.|
|These operators are available in the Arithmetic Editor.|
|These return primarily feature-specific values.|
|FME and workspace-specific parameters may be used.|
|Creating and Modifying User Parameters||Create your own editable parameters.|
Dialog Options - Tables
Transformers with table-style parameters have additional tools for populating and manipulating values.
Enabled once you have clicked on a row item. Choices include:
Cut, Copy, and Paste
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers.
|Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output.|
|Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers.|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers.
Note: Not all tools are available in all transformers.
The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.
Search for all results about the AttributeFileWriter on the FME Community.
Examples may contain information licensed under the Open Government Licence – Vancouver and/or the Open Government Licence – Canada.