SchemaMapper: Conditional Feature Type Mapping

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

Conditional mapping makes use of the SchemaMapper’s “Filter Features” action. It is a way to define a simple conditional clause to perform attribute or feature type mappings based on specific conditions. In short, conditional feature type mapping is when the connection between what we have and want depends on an attribute's value.

In the previous Conditional Attribute Mapping article, a single layer containing watermain data for the city of Vancouver was divided into Abandoned and Active feature types using an AttributeFilter to split the incoming data (we also did some attribute renaming in the SchemaMapper, but our focus here is on the fme_feature_type).

Using conditional feature type mapping, these two datasets can be divided further based on their pipe material. Using the SchemaMapper’s “Feature Type Map” action in tandem with a filter action, we can construct an “IF” statement that will decide how to route our feature types. Here’s an example of the kind of logic we’re looking at:

Basic Feature Type map without conditional logic:

IF [existing] fme_feature_type = xxxx 
THEN SET [new] fme_feature_type to zzzz

Adding the filter action adds an “AND” to this existing condition.

Conditional Feature Type Map:

IF [existing] fme_feature_type = xxxx AND attribute = yyyy 
THEN SET [new] fme_feature_type to zzzz

Process Overview

Feature Type Mapping Lookup Table

In a text editor, create a lookup table within the SchemaMapper (or optionally jump to the completed workspace template and skip the step-by-step process). The SchemaMapper lookup table has to define both a clause for the feature type and a clause for the attribute values. The table should look something like this:

1 SourceFeatureType,SourceAttribute,SourceAttributeValue,DestinationFeatureType
2 Active,Material,Steel,Steel 
3 Active,Material,Copper,Copper 
4 Active,Material,Cast Iron,CastIron 
5 Active,Material,Ductile Iron,DuctileIron 

Line 1 contains the field names for the lookup table. Other lines include the information by which to restructure the data. For example, line 2 sets up the conditional execution as follows:

IF Source Feature Type = “Active” AND “Material” = “Steel” 
THEN Destination Feature Type = “Steel” 

To fully map this source data, each source feature type and attribute value must be added to the lookup table. Otherwise, they will be excluded from the mapping action.

Feature Type Mapping: SchemaMapper Definition

Open the SchemaMapper parameters dialog and set up the transformer to read in the CSV lookup table. Add a Filter action to define a clause where Material Attribute = Material Value.

Next, define the feature type mapping to be carried out (wherever the above conditions are true). In the SchemaMapper, use the Add (+) button, then select Feature Type Map action, and set the Source and Destination Feature Type Fields:

To reiterate, the logic here is:

IF SourceAttribute = SourceAttributeValue 
THEN MAP SourceFeatureType to DestinationFeatureType

When completed, the SchemaMapper parameters will show our two actions - one for filtering features based on our attribute values, and one for remapping the feature types accordingly:

The source data has only been mapped to the destination feature type. For the destination feature types to be created and connected, an AttributeFilter transformer is needed to sort through the remapped feature types and route them appropriately to our writer feature types.

Updating Data

The SchemaMapper is extendable because it enables the user to edit the lookup table outside of FME to handle schema transformation within the workspace. The following example adds a new feature type with additional attribute values to the workflow.

Workspace Changes

The workspace ACAD reader is currently set up with two feature types: Active and Abandoned.

Our current SchemaMapper setup perfectly handles these objects' schemas, feature types, and attribute values. But suppose we introduce some new and strange data? How would our workflow handle the transformation?

Let’s enable our Additional Feature Type (“Update”) and see if we can integrate it into our current workspace.

Lookup Table Changes

The “Update” dataset contains two new Material attribute values: “Earthenware” and “Polybutylene.” In this case, the lookup table needs to accommodate both the new feature type and the new attribute values. The updated schema information can be added directly to the lookup table to accommodate these new values.

Add the following lines for the new feature type at the foot of the existing lookup table:

1 Update,Material,Earthenware,Earthenware 
2 Update,Material,Polybutylene,Polybutylene 

Save the lookup table and return to the workspace. After adding the two new feature types to the AttributeFilter transformer and adding “Earthenware” and “Polybutylene” writer feature types, the workspace should now handle the new data defined in the lookup table.

The next step in this process would be to make the workflow entirely dynamic for reading and writing data without the workspace author having to define the feature types beforehand. For more information about dynamic workspaces, please refer to the Tutorial: Dynamic Workflows article

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