Looping with Blocking Transformers

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

When working in FME some transformers are known as “Blocking Transformers,” for example, the Clipper, SpatialRelator or any transformer that can use "Group By" functionality. These transformers require all of the input features to be held there until all of the features have been received to complete the transformer’s action before releasing the features to continue down the workflow. Watch the Blocking Transformers section of the FME Core Concepts video from the 2017 FME UC to learn more.


Holding all the features presents a problem when looping inside a custom transformer because the blocking transformer will never receive all the input features since it will be expecting features from the loop. Thankfully, as long as you are using FME 2011+, FME has a solution.


Downloads

SimpleLoopDemo.zip

*Note: To run the SimpleLoopingDemo-Completed.fmw workspace, the SimpleLoopingDemo.fmx custom transformer will need to be moved to the default location to be able to be accessed by the workspace. This location can be found in Tools > FME Options… > Default Paths > Shared FME Folders


Adding a Blocking Transformer

When a blocking transformer is added inside of a custom transformer with a loop, a warning message will appear. This message states that to use this transformer, the custom transformer needs to be exported to an external .fmx file:

addwarning.png

Once the file has been exported, the custom transformer with the loop can be used.


Example

In this example, a loop will be used to move a point towards a square’s boundary and check whether the point stays within the square. Once the point leaves the square, the workspace will finish.


1) Open template workspace

In FME Workbench, open the SimpleLoopDemo.fmw. This workspace has a point and a square Creator transformer, as well as the SimpleDemoLoop custom transformer already set up. We just need to add the SpatialFilter transformer and resolve the blocking transformer error.


Switch the to SimpleLoopDemo tab, this is the custom transformer that is almost finished. Add a SpatialFilter to the canvas. Click Yes on the warning message that appears.

demostarting.png

blockingwarning.png

In the Export as Custom Transformer dialog, change the Insert Mode to Linked Always. The Save Location should be automatically populated with the default path that is set up in your FME Options. The common path is:

C:\Users\SampleUser\Documents\FME\Transformers

exportparameters.png

Click OK to save the transformer. A new instance of FME Workbench will open with the SampleLoopDemo.fmx custom transformer. When working with external custom transformers, it is important to make all of the changes in the .fmx instead of in the .fmw workspace.


2) Connect SpatialFilter

In the .fmx version of FME Workbench that opened when the custom transformer was saved, connect the SpatialFilter transformer. Connect the Filter input port to the Square port and the Candidate input port to the Point port. Next, connect the Passed output port to the Offsetter and the Failed output port to the Outside port.

spatialfilter.png


3) Set Blocking Parameters

Before we can save and use this transformer in our workspace, we need to set a couple of additional parameters to enable the loop to run with the blocking transformer.


In the Navigator window, expand the Transformer Parameters, then expand Advanced. Double click on Enable Blocked Looping, to open the parameters, and change it to Yes. Next, it is a good idea to set the Maximum number of iterations parameter, especially when testing, to prevent infinite loops. Double click on the parameter and set it to 10. Save the transformer.

navigatorparms.png


4) Run the Translation

Back in the original workspace, we will need to delete the SimpleLoopDemo transformer and re-add it to update the properties, you will know it has been updated when the SimpleLoopDemo transformer has an Incomplete port. It can be re-added by typing SimpleLoopDemo onto the canvas. Reconnect the ports and then run the translation.

quickadd.pngsimplecompleted.png


After running the workspace, you can inspect the square, original point and the final point coming from the Outside port. Inspecting these will give you the results below, where the red point was the original and the blue point is the new point.

simpleoutput.png


Additional Resources

Looping with Blocking Transformers Documentation

Looping in Custom Transformers - FME Desktop Advanced Training Course Manual

Blocking Transformers - Core Concepts From the 2017 FME UC

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.