Files
-
- 400 KB
- Download
Introduction
Attribute mapping is transforming or connecting one or more attributes of a feature to a new attribute or set of attributes. It can be as simple as renaming an attribute, as in the image below, or as complicated as renaming, dropping, merging, and creating new attributes simultaneously.
The above image maps source attributes to their corresponding destination attributes. For example, the source attribute DIAM_MM gets mapped to the destination attribute Diameter.
Simple one-off attribute mapping like this can be done by modifying the User Attributes in a writer and connecting FME’s visual attribute connectors from the reader to the writer attributes.
However, the SchemaMapper transformer can perform the same (or more complex) operation with much more control.
The following tutorial will demonstrate basic attribute mapping using a CSV lookup table and the SchemaMapper transformer.
Step-by-step Instructions
To replicate the above mapping using the SchemaMapper, a simple CSV (text) file containing a header line and field names will be used as a lookup table. This could be an Excel spreadsheet or any 50+ lookup table formats that the SchemaMapper accepts.
1) Configure the File for Attribute Mapping
In the text editor of your choice, enter the following information separated by commas. (Feel free to skip this step and open the completed workspace to see how the final product works!)
1 SourceAttribute,DestinationAttribute 2 DIAM_MM,Diameter 3 MATERIAL,MaterialType 4 LINING,LiningType 5 INSTALL_DT,DateInstalled
Spaces before or after commas in your lookup table CSV can create issues during feature type mapping. Best practice is to omit all white space surrounding delimiters unless they are present in the attribute values themselves.
Notice that the column headers (e.g., field or attribute names) appear on the first line, followed by our source and destination data. Save the table as a .csv file.
2) Set up the SchemeMapper Transformer
In the SchemaMapper dialog, set up the transformer to read in the CSV lookup table:
At this point, you may take a look at the lookup table reader parameters. Here you will find basic and advanced parameters that dictate how FME reads your lookup table, and how FME will use the lookup table to map attributes.
The default parameter values should be adequate for our example, and in the Preview pane, you should see an accurate tabular representation of your lookup table.
The first parameter lets FME know that we want to use the filename as the feature type name. This doesn’t really matter for CSV, which has no feature type names anyway.
The second set of parameters defines the structure of our CSV, and how FME will read it for schema mapping. Because our lookup file uses commas to separate data, and because our first line contains field names, the default values here are exactly what we want.
In the Preview pane, you can see that when FME finds an attribute whose name is defined in the SourceAttribute column of the lookup table, it renames it to the name in the corresponding DestinationAttribute column.
Below the Preview pane, there are some options for further customizing the schema map; however, the Automatic setting will respect our current parameters and will work perfectly with our simple CSV and attribute mapping example.
3) Create Attribute Map
From the SchemaMapper reader window, continue to the next set of parameters, which deal with creating the “Actions” that the transformer will perform. Add an Attribute Map action and set the source and destination attribute fields appropriately.
Below, another tabular representation of your lookup table will appear with all data cells bolded when they are mapped. Accept the changes and return to the workspace.
Workbench won’t display these mappings automatically (see below where the destination attributes are still red), but FME will still recognize and write the correct attributes for the destination schema. Alternatively, the AttributeExposer transformer can be used to expose these new attributes, which will then show as connected.
Here, writer attributes remain red and unconnected; however, they will be written according to our new schema map:
You can now run the workspace and inspect the output using FME Data Inspector. The output dataset’s schema will reflect the new attribute names. The workspace can now be built upon as required, for more complex attribute or feature type mapping.
Additional Resources
There are several additional tutorials about the SchemaMapper, each with different features and use cases discussed:
Configuring the SchemaMapper Transformer
The SchemaMapper requires an external lookup table to be configured. This article describes creating the lookup table and connecting it to the SchemaMapper.
SchemaMapper: Feature Type Mapping
Feature type mapping is when one or more feature types are mapped and renamed to a new feature type. This article demonstrates how to perform feature type mapping using a lookup table.
SchemaMapper: Conditional Attribute Mapping
Conditional mapping uses the SchemaMapper’s conditional filtering capabilities. It is a way to define a simple clause to perform attribute mappings based on specific conditions. This article describes how to map a schema based on the value of attributes within the feature type.
SchemaMapper: Conditional Feature Type Mapping
This article describes how to use the SchemaMapper’s conditional filtering capabilities to define a clause to map feature types based on the value of attributes within the feature type.
SchemaMapper: Advanced Schema Mapping
This article demonstrates some of the advanced uses of the SchemaMapper, including using multiple clauses to filter features, adding new attributes, and modifying existing attribute values. The article also discusses the order of entries in the lookup table, which is useful for debugging.
SchemaMapper: Generating a Lookup Table from Source Data
The method of generating lookup tables using data sourced from input feature types is discussed in this article.
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.