SchemaMapper: Conditional Attribute Mapping

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

Conditional mapping uses the SchemaMapper’s Filter Features action. It is a way to define a simple conditional clause to perform attribute mappings based on specific conditions.

In this tutorial, we will manipulate a single layer that contains water main data for the city of Vancouver. Based on attribute values, the layer can be divided into abandoned and active pipes. We will make use of this value, along with conditional clauses, to remap the layer’s schema in two ways:

1) Using attribute values as a filter 

2) Using FME feature types as a filter

Source

emzaR-bTp3Bhu_JxMkyH11x2Ziqj6_BYMUY1mJODmyvT7vXNdDeMH1gsTj83TbB5tvvhCBfvWOQb6J-6OExzUALrKTgf5DwMU7aBGk4dnKYrXlE7dgRCZJimr4NKaZo6BTMziRw

Process Overview

The water mains schema contains attributes named OBJECTID and LifecycleStatus, both of which will play a part in our conditional filter. Open the dataset in the Data Inspector and take a look at the LifecycleStatus attribute of a few features. You’ll notice that it has either the value Abandoned or the value Active:

For our tutorial, depending on the value of LifecycleStatus, the fme_feature_type attribute will be mapped to either Abandoned or Active, and OBJECTID will be renamed to either AbandonedID or ActiveID.

Conditional Attribute Mapping Lookup Table

If our conditional attribute mapping lookup table followed the simple structure used in the Attribute Mapping Article, where the left column holds the attributes and values we’re starting with, and the right column dictates what we want as output, the table would look something like this:

1 SourceAttribute,DestinationAttribute
2 OBJECTID,AbandonedID 
3 OBJECTID,ActiveID

The problem with this lookup table is that OBJECTID is defined as a source twice under SourceAttribute (because we want to map it in two different ways). This is clearly problematic; we need to give more explicit instructions. To correct this, a clause is added stating when to use which definition.

1 FilterAttribute,FilterAttributeValue,SourceAttribute,DestinationAttribute
2 LifecycleStatus,Abandoned,OBJECTID,AbandonedID 
3 LifecycleStatus,Active,OBJECTID,ActiveID

The logic working here is as follows:

IF LifecycleStatus = Abandoned THEN OBJECTID → AbandonedID
IF LifecycleStatus = Active THEN OBJECTID → ActiveID

Conditional Attribute Mapping in SchemaMapper

In our demo workspace, open the SchemaMapper transformer’s parameters. A lookup table is provided—feel free to inspect the lookup table reader parameters in the Preview panel to get a sense of the table structure.

Click through to the Create Actions parameters window. Notice that we have two Actions - one for filtering features and one for mapping attributes.

The Filter Features action defines the clause where LifecycleStatus Attribute = LifecycleStatus Value:

The Map Attributes action defines the attribute map where SourceAttribute becomes DestinationAttribute:

Also worth noting is the Source Attribute: Keep / Remove option. Remove is selected to tidy the data and focus on the remapped attribute values rather than the originals. Using the Keep option would retain the original OBJECTID field and values along with the new ones.

Accept the parameters and return to the workspace. Our single water mains layer has now been logically split into two based on the LifecycleStatus attribute: features marked with an AbandonedID and features marked with an ActiveID. Using an AttributeFilter, we can map the two groups of features onto two outgoing feature types and write our AutoCAD file.

Since Workbench does not know that the correct mappings exist in the SchemaMapper, the destination attributes are flagged as unconnected (the red triangles that appear in our writer attribute dropdown). However, when the workspace is run, the output will be correct because the attributes exist; they just aren’t exposed.

Alternatively, the AttributeExposer transformer can expose these new attributes and cause the writer attributes to be visibly connected.

Advanced Example

Conditional Attribute Mapping using Feature Type Names

Filtering is not limited to user-defined attributes since it is also possible to filter by format attributes. An example of a useful format attribute is fme_feature_type, which contains the feature type name. The key to performing this task is to provide the FME format attribute in the lookup table. In the following example, two feature types exist in the workspace: Water_Distribution/wControlValve and Water_Distribution/wMain. We would like to rename attributes in the resulting schema based on which feature type is being read.

We need a lookup table that uses the >fme_feature_type attribute to create this workflow. A lookup table is provided within the workspace template, but you may wish to create your own, which looks like the one below:

1 FilterAttribute,FilterAttributeValue,SourceAttribute,DestinationAttribute
2 fme_feature_type,Water_Distribution/wControlValve,OBJECTID,ValveID 
3 fme_feature_type,Water_Distribution/wControlValve,Diameter,ValveDiameter 
4 fme_feature_type,Water_Distribution/wMain,OBJECTID,PipeID 
5 fme_feature_type,Water_Distribution/wMain,Diameter,PipeDiameter 

As with conditional attribute mapping, each line in our lookup table defines a schema mapping rule. The first rule in this lookup table states:

IF Feature Type Name = Water_Distribution/wControlValve 
THEN OBJECTID becomes ValveID

The SchemaMapper transformer's Create Actions dialogue mirrors the example table given above. For example, in the preset Filter Features action window, the two columns that dictate the attribute filter portion of our rules are highlighted:

Run the workspace and notice that the AttributeFilter separates our two feature types, and that we have remapped our OBJECTID attribute along the way.

Tutorial Series

Configuring the SchemaMapper Transformer

The SchemaMapper requires an external lookup table to be configured. This article describes how to create the lookup table and connect it to the SchemaMapper.

SchemaMapper: Attribute Mapping

Attribute mapping is when one or more attributes on a feature are mapped by renaming their existing attribute names to a new one. This article demonstrates the design of a simple lookup table and how it can be used to map attributes.

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 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.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.