FME Transformers: 2024.1
FME Transformers: 2024.1
AttributeFileReader
Reads the contents of an external text or binary file and attaches it to a feature as the value of an attribute.
Typical Uses
- Attaching files to features
- Adding file contents to features
- Reading geometry content stored in a separate file
How does it work?
The AttributeFileReader receives any type of feature and adds the contents of an external file to them, as the value of a new or existing attribute.
File selection may be done explicitly or by attribute value, expression, user parameter, or conditional value.
The file may be text or binary. (Text refers to the file type, rather than the file content - it may not necessarily be plain text.) A variety of encoding choices are available for text files. Binary files should be designated as Binary (fme-binary), as the transformer is not aware of formats and will simply preserve the file contents as a Blob.
There is no file size limit. Very large files may affect performance, and need sufficient memory to hold them as no file caching is done.
Examples
Example: Attaching a text file as an attribute
In this example, we will read a text file and add it to a raster feature as an attribute. We want to add a palette (the text file) to a numeric raster in GeoTIFF format.
The raster is first routed through a RasterBandInterpretationCoercer to meet processing requirements - the band type must be an unsigned integer to be compatible with palettes.
Next, the raster is passed to an AttributeFileReader. Note that it has one exposed attribute and consists of one numeric band, an 8-bit unsigned integer.
A text file containing the palette information has already been prepared, as shown here in Notepad.
In the parameters dialog of the AttributeFileReader, we keep the default File Contents attribute name as_file_contents, and select the Palette_color.txt file.
As this is a text file, prepared on the same computer it is being processed on, we can use the System Default (fme-system) encoding.
Examining the output from the AttributeFileReader, note that the raster now has an additional attribute, _file_contents, which contains the contents of the text file.
The last step in this workflow is to apply the palette from the new attribute with a RasterPaletteAdder.
Example: Attaching an image to a feature
In this example, we have both a point cloud and an orthoimage of the same area, and want to keep them together - so we will attach the image to the point cloud feature as an attribute.
Note that the point cloud has one exposed attribute.
The orthoimage is a GeoTIFF.
The point cloud is routed into an AttributeFileReader.
In the parameters dialog, we keep the default File Contents attribute name as_file_contents, and select the StadiumOrthoLowRes.tif file.
Source File Character Encoding is set to Binary (fme-binary), which will store the GeoTIFF as a Blob.
Examining the output in the FME Data Inspector, note that the point cloud has a new attribute which contains the orthoimage, still encoded in binary.
From here, the image can be decoded and used at any time with a RasterReplacer, as in the example below which would use the raster to color the points of the point cloud with a PointCloudOnRasterComponentSetter. Another subsequent use could be writing it to a Blob column in a database.
Usage Notes
- All types of binary files are stored as Blobs, and Source File Character Encoding should be set to Binary (fme-binary) .
- The most common text encodings are Windows Latin-1 (windows-1252) and Unicode 8-bit (utf-8).
- If a text file includes special characters, the appropriate Source File Character Encoding should be selected to preserve those characters.
- Full path names can be created from existing attribute values by using the Text Editor to create an expression.
- Some transformers (such as the XMLFlattener) can read external files, and so do not need to use an AttributeFileReader first.
Configuration
Input Ports
Input
Features to receive files as attributes.
Output Ports
Output
Features with files added as attribute values as specified in the parameters.
<Rejected>
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.
Parameters
General
Source Filename |
The name and location of the file to be read. It may be specified explicitly or by attribute value, expression, user parameter, or conditional value. |
Source File Character Encoding |
Specify the source file's character encoding. Binary (fme-binary) includes all binary file types. |
Output Attribute Name
File Contents |
Name the attribute to contain the contents of the file. New attributes will be added and existing attributes will have their values overwritten. |
Editing Transformer Parameters
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.
How to Set Parameter Values
Defining Values
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.
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.
Conditional Values
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Content
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.
Content Types
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. |
Dialog Options - Tables
Table Tools
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.
Reference
Processing Behavior |
|
Feature Holding |
No |
Dependencies | None |
Aliases | |
History |
FME Community
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 AttributeFileReader 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.