Files
-
- 20 KB
- Download
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 input features to be retained until all features have been received, allowing the transformer to complete its 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.
To run the SimpleLoopingDemo-Completed.fmw workspace, the SimpleLoopingDemo.fmx custom transformer must be moved to the default location so that it can 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 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:
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 features a point and a square Creator transformer, as well as the SimpleDemoLoop custom transformer, which is already set up. We just need to add the SpatialFilter transformer and resolve the blocking transformer error.
Switch to the 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.
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\TransformersClick 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 essential to make all changes in the .fmx file 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.
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 "Transformer Parameters" and 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.
4) Run the Translation
In the original workspace, we will need to delete the SimpleLoopDemo transformer and re-add it to update its 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.
After running the workspace, you can inspect the square, original point, and the final point coming from the Outside port. Inspecting these will yield the results below, where the red point represents the original and the blue point represents the new point.
Additional Resources
Looping with Blocking Transformers Documentation
Looping in Custom Transformers - FME Form Advanced Training Course Manual
Blocking Transformers - Core Concepts From the 2017 FME UC