Exercise 4 Grounds Maintenance Project - Labelling Features
Data City Parks (MapInfo TAB)
Overall Goal Calculate the size and average size of each park in the city, to use in Grounds Maintenance estimates for grass cutting, hedge trimming, etc.
Demonstrates Content transformation with parallel transformers
Start Workspace C:\FMEData2018\Workspaces\DesktopBasic\Transformation-Ex4-Begin.fmw
End Workspace C:\FMEData2018\Workspaces\DesktopBasic\Transformation-Ex4-Complete.fmw

Let's continue your work on the grounds maintenance project.

In this part of the project, we’ll create a label for each park and write it to a new output layer. This step is best done using a parallel stream of data.

1) Start Workbench
Start Workbench (if necessary) and open the workspace from Exercise 3. Alternatively you can open C:\FMEData2018\Workspaces\DesktopBasic\Transformation-Ex4-Begin.fmw

The previous exercise measured park areas with the AreaCalculator. Now we are asked to add this information as labels to the output dataset.

This step can be achieved using the LabelPointReplacer transformer.

2) Create New Writer Feature Type
Because we want to write label features to a separate layer (table) in the output, we need to create another feature type object on the canvas. There is more about this in a later chapter, but for now, right-click the writer feature type and choose the option Duplicate. Doing so creates a new feature type (layer) in the output dataset.

Now clean up this feature type's schema. View the feature type's dialog and rename the new type to ParkLabels. In the User Attributes tab delete all of the existing user attributes.

3) Place a StringConcatenator Transformer
Click onto a blank area of canvas. Type "StringConcatenator" to add a transformer of this type.

Connect it to the Complete port of the StatisticsCalculator by dragging a second connection from there to the new transformer.

Make a new connection from the StringConcatenator to the new feature type.

4) Check Transformer Parameters
View the parameters for the StringConcatenator transformer. There are both basic and advanced dialogs, and the basic one looks like this:

Enter LabelText as the name for the new attribute to create.

In the String Parts section, set the following four parts:

String TypeString Value
Attribute ValueParkName
New Line
Attribute ValueParkArea
Constant sq metres

Be sure to include a space character in the constant before "sq metres".

You may find it quicker to switch to the Advanced editor dialog and enter the content directly:
@Value(ParkArea) sq metres

5) Place a LabelPointReplacer Transformer
Click onto the connection between StringConcatenator:Output and the ParkLabels feature type. Type "LabelPointReplacer" to add a transformer of this type.

The new transformer will be added and automatically connected between those two objects.

6) Check LabelPointReplacer Parameters
Inspect the LabelPointReplacer parameters.

Firstly click the drop-down arrow to the right of the Label parameter:

Select Attribute Value > LabelText to select the label previously defined in the StringConcatenator.

Now click in the Label Height field and type 25 (that’s 25 working units, which in this case is metres).

The “Always Rotate Label” parameter can be left to its default value.

Many parameter fields (like Label Height) can be set either as a constant value (by typing it in) or set to an attribute by clicking the drop down arrow and selecting Attribute Value.

And - as you'll see shortly - it's also possible to construct a parameter value directly inside the transformer settings

7) Run the Translation
Add another bookmark if you wish, run the translation, and inspect the output.

Notice that the output is in two layers in two files. Use the FME Data Inspector to open both output files in the same view.

Map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.

Save the workspace – it will be completed in further examples.

Advanced Exercise
Now you know how to create a new feature type (layer) in the output, how to test data, and how to use parallel streams, why not try this task: Identify which parks are smaller than average and which parks are larger than average, and write them out to different feature types.

By completing this exercise you have learned how to:
  • Create a new writer feature type
  • Use multiple streams of transformers in a single workspace
  • Use the StringConcatenator to construct a string for use elsewhere
  • Use an attribute as the value of a transformer's parameter

results matching ""

    No results matching ""