Writes the contents of an attribute to a text or binary file.
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 a number of attributes, including DogPark and ParkName.
This will take three steps:
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.
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:
INVALID_FILE_INACCESSIBLE
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.
|
Source Attribute |
Name of the attribute whose value will be written out to a file. |
|
Target Filename |
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. |
Transformer parameters can be set by directly entering values, using expressions, or referencing other elements in the workspace such as attribute values or user parameters. Various editors and context menus are available to assist. To see what is available, click
beside the applicable parameter.
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.
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.
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. | |
|
Special Characters |
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. |
Transformers with table-style parameters have additional tools for populating and manipulating values.
|
Row Reordering
|
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. |
|
Filter
|
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
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
|
Reset/Refresh
|
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.
For more information, see Transformer Parameter Menu Options.
|
Processing Behavior |
|
|
Feature Holding |
No |
| Dependencies | None |
| Aliases | |
| History |
The FME Community has a wealth of FME knowledge with over 20,000 active members worldwide. Get help with FME, share knowledge, and connect with users globally.
Search for all results about the AttributeFileWriter on the FME Community.
Examples may contain information licensed under the Open Government Licence – Vancouver, Open Government Licence - British Columbia, and/or Open Government Licence – Canada.