Constructing Values

Constructing Values goes one step further than setting an attribute with a simple, fixed value.

FME has various functions that allow the workspace author to create a simple, fixed value for an attribute.

For example, here an author is using the AttributeCreator transformer to set the value of an existing attribute and to create a new attribute with a fixed value:

However, in many cases the workspace requires a value to be constructed out of a number of existing values, or perhaps an arithmetic calculation, and FME is capable of doing that as well.

There are, basically, two methods to constructing attribute values: Transformer Construction and Integrated Construction.

Transformer Construction

Transformer construction is a basic method of constructing attribute values. The author sets simple values in a transformer, but uses two or more transformers in a series in order to build a more complex value.

For example, here the workspace author needs to create a label in their spatial data.

First they create an attribute value by calculating a number, concatenate it onto a string attribute, trim the result, and then use that as the content for a LabelPointReplacer transformer.

This is an acceptable way of working that is self-documenting and easy to understand; but it is also a fairly crude method and results in the use of more transformers than is perhaps necessary.

Integrated Construction

Integrated construction is a more elegant method of constructing attribute values. Instead of using a string of transformers, the author uses functionality built into a single transformer’s parameter dialog window.

In short, the attribute value is constructed at its point of use; it’s a more efficient method and reduces the number of transformers cluttering up the workspace canvas.

Most transformer parameters have one of two pieces of inbuilt functionality that allow this to take place: a Text Editor or an Arithmetic Editor.

The text editor allows values to be constructed from strings. It includes access to all FME feature attributes and user parameters, plus special characters, FME Functions, and various string manipulation related functions.

The arithmetic editor allows values to be calculated from arithmetic calculations. Again, it includes access to all FME feature attributes, user parameters, and FME Functions; but additionally it gives access to a series of mathematical functions and operators.

Professor Lynn Guistic says…
“Although we’re talking about attributes here, the same functionality applies to any transformer parameter. For example, the label parameter for the LabelPointReplacer can be constructed using a text editor instead of a series of transformers. We’re only discussing it here in terms of “attributes” because traditionally you would construct an attribute and supply it to the parameter. Now everything is built into that parameter.”

Text Editor

The Text Editor is a tool for string-based construction of attributes. In it, the workspace author can construct values out of fields such as the following:

  • String Constants
  • FME Feature Attributes
  • User or System Parameters
  • Special Characters

The text editor window is a free-form dialog into which the author can construct almost any form of string. Here, for example, the author is constructing a string that describes a cell phone tower. Such a string could be applied as a label, written as an attribute value, or used in many other ways.

Constant values can be entered directly into the expression field.

Fixed items are generated by using the left-hand menu. In addition to the ability to use attributes, parameters, and special characters, the advanced editor allows the author to make use of special functions.

These are added to the expression by locating them in the menu and either double-clicking that entry or dragging it into the expression:

FME Feature Functions are the underlying functions used by FME transformers. By accessing these, the author is reaching directly into core FME functionality.

All FME functions are of the form @functionname() where the part inside parentheses is a function parameter.

For example the function @Value(Roads) returns the value of the attribute called Roads.

Not all functions have parameters, or those parameters are not always compulsory; for example the function @Area() does not need to take a parameter.

Professor Lynn Guistic says…
“FME functions can be used in the text editor to calculate values on the fly, instead of using a transformer. For example, an author wants to create an attribute whose contents include the area of the feature in the form “ sq. metres” They could calculate the area with an AreaCalculator and use @Value(_area) sq. metres or they could cut out that transformer and go directly with: @Area() sq. metres”

The editor also has a set of string functions and mathematical functions. The string functions carry out operations like formatting, extracting, trimming, and padding. The mathematical functions are the usual advanced arithmetic functions such as int, cos, and log.

The string functions are mostly based around Tcl, while the arithmetic functions around C.

Arithmetic Editor

The Arithmetic Editor dialog is a tool for building arithmetic expressions.

Like the text editor, the arithmetic editor has the ability to calculate values using constant values, feature attributes, parameters, and other functions.

However, the arithmetic editor works entirely with numbers to calculate a numeric value. The implications of this are:

  • All attribute values used must be numeric, or converted to numeric inside the expression by using a function.
  • The only FME functions and string functions available are those that return a numeric value; for example @Area(), @Count(), and @StringLength()
  • The value returned to the workspace will be a numeric type, not a string.

For example, here a workspace author is calculating the property tax for a set of features using the attributes TaxBand and AssessedValue, in conjunction with the @Area() function.

Professor Lynn Guistic says…
“At this point two questions are probably uppermost in your mind. Firstly, why do some transformer parameters have options for both the text and arithmetic editor (like the AttributeCreator) whereas others have just the text editor or just the arithmetic editor? That’s easy. The editor is matched to the type of value expected by that parameter. For example, the LabelPointReplacer transformer has Label and Label Height parameters. The Label parameter can access the text editor, because it expects a string. The Label Height parameter can access the arithmetic editor because it expects a number. The AttributeCreator transformer allows access to both because it doesn’t rely on a particular type. It is happy with either numeric or string values. Secondly, you’re probably wondering why there are math functions inside the text editor and how you can use them. That’s simple. The FME function @Evaluate() carries out a mathematical calculation. So if you need to calculate a numeric value as part of a string, then use that function; like so:”

Advantages and Disadvantages

There are some obvious advantages and disadvantages to using integrated construction of attributes, compared to a sequence of transformers.

A sequence of transformers is self-documenting.

A casual user could look at the workspace and understand what is happening.

Integrating this into a single parameter in a single transformer leads to a more closed workspace. A casual user would have to investigate the workspace closely to understand how it works.

On the other hand, integrated functions produce much more clean and elegant solutions. They take up less space on the canvas and are generally less cluttered.

So the decision on which method to use depends as much on your confidence in using FME, and how much the workspace might need to be shared with others, as anything else.

The Engineering department at the City of Interopolis has invested in FME Server and is now creating a KML dashboard to provide access to the information FME Server provides.

In this workspace they translate a DWG dataset of traffic signals to KML. The KML output will contain a URL that points to a workspace on FME Server. When the URL hyperlink is clicked it will cause a workspace to run and FME Server to return information about the traffic signal.

Today, however, your task is not to work on the Server workspace; rather it is to help create the hyperlink that points to that workspace.

1) Inspect Source Data

Inspect the source data for the workspace. You can find it at:

Format Autodesk AutoCAD DWG/DXF Dataset C:\FMEData2015\Data\Engineering\TrafficSignals.dwg

When reading this data it’s preferable to set the parameter Group Entities By to ‘Attribute Schema.’

Notice how each traffic signal is represented by a point feature with a text object that specifies the ID number for the signal:

2) Start Workbench

Open the workspace C:\FMEData2015\Workspaces\DesktopAdvanced\Exercise5a-Begin.fmw.

The first part of the workspace concerns getting the ID number from the text label and onto the point feature. It’s not our main point of concern, so we can pretty much ignore this part:

The part of the workspace that does concern us is the last four transformers:

Inspect each transformer in turn, examining what it does and what parameters are set.

You should quickly see that this section is constructing a hyperlink that points to FME Server. From what we’ve learned about integrated attribute construction, we know that it should be possible to improve upon this design.

3) Place AttributeCreator

Place an AttributeCreator transformer with a parallel connection out of the NeighborFinder matched port.

It’s important to ensure it is connected in to the current flow of data, else no attributes will be available.

Open the parameters dialog. For attribute name enter SignalURL (to match the output schema).

Under Value, click the drop-down menu arrow and choose the option Open Text Editor:

4) Create Attribute Value

In the expression dialog enter the text:

http://interopolis.org/fmedatastreaming/Engineering/signalinfo.fmw?signalid=

If it’s easier, this can simply be copied from the existing StringConcatenator transformer; although it doesn’t really matter if you get it wrong because it’s just an exercise(!)

Now we need a function to replace the SubstringExtractor transformer. In the left-hand set of menus, click on String Functions to expand the list of available functions.

Locate the substring function and double-click it to insert it into the expression.

The expression will now look like this, with the part pre-selected:

The string we want to process is the value of the attribute fme_text_string. So, in the left-hand set of menus, click on FME Feature Attributes to expand the list of available attributes.

Locate the attribute fme_text_string and double-click it to insert it into the expression.

The latter part of the expression now looks like this, with the attribute filled in:

The values of the two fields are the same as used in the SubstringExtractor transformer. In this case the values are 4 (the fifth character in) and -1 (the end of the string).

So, manually select each in turn and replace them with 4 and -1. The expression now looks like this:

On the end of the expression, manually type &username=

And, finally, in the left-hand menus click on Published Parameters to expand the list of available parameters.

Double-click on Username to insert that user parameter into the expression:

The last part of the expression now looks like this:

Notice how attributes are denoted by an @Value() function, whereas parameters are denoted as $()

Click OK to close the dialog, and then OK again to close the main AttributeCreator dialog.

5) Clean Workspace

Now clean up the workspace by connecting the newly created AttributeCreator to the output feature type, and deleting the other four transformers that already existed.

Add a little annotation to denote that this transformer now creates the URL:

Save and run the workspace to confirm that it does still work correctly.

Compare the original workspace to the new one. Is one “better” than the other? If so, why?

What are the advantages and disadvantages of each workspace?