The Safe Software Blog
Mark Ireland

Get the Blog Newsletter

Delivered by FeedBurner

About FME    |   October 11, 2010   |   By Mark Ireland

FME 2011 Sneak Peek: IFMEWorkspaceRunner

Hi all,
I have the greatest respect for folk who have mastered a skill I have great trouble with, and computer programming – or is it now software engineering? – is high on this list. If you know the difference between a class and an interface (and a method and an object) then kudos to you.

However, sometimes I think developers get the wrong end of the stick with regard to FME. So here’s a quick guide to FME for developers, with particular emphasis on something new for FME2011.

Getting Started
I’ve seen – and seen quite often – questions from folk who have installed FME for evaluation and immediately started coding a C++ solution to do something like convert Shape data to KML

Dude! Just because we have an SDK, doesn’t mean you have to use it for everything!

Seriously, when you set out to translate and transform spatial data programmatically, you might want to consider whether it’s an effective use of your time. Most users could accomplish a Shape to KML translation in under 30 seconds with Workbench. Do you really need to spend days doing the same thing in Java?

Plus, you can run a workspace on FME Server – but you can’t do the same with an FME Objects application.

What it comes down to is this: it’s more efficient and flexible to define a translation in Workbench, and just execute it programmatically, than it is to code the whole thing from scratch.

And where FME2011 comes in is that we have a whole new way to do just that. But first let’s review a couple of existing methods.

Command Line Execution
Because FME is a command line engine at heart, it’s very simple to execute a workspace by issuing a command in that form. The log window for any workspace will even tell you what that command should be. Even non-programmers (like myself) can manage to wrap that sort of functionality into a nicer interface for an end user to use.

FME Server Execution
When you need to execute a workspace from within a web page, then FME Server is the way to go. It’s simple to publish a workspace to the server and, because of the easy-to-use API, it’s a doddle to kick off a translation using a URL. You can even do it RESTfully with FME Server 2011

The difficulty in running a workspace programmatically has been that there was no way to actually use FME Objects to run a workspace; or at least no simple and flexible way. So you would find it quite difficult to define a translation within Workbench and then run it from your own application.

What’s new for FME2011 is a class (or is that interface?) within FME Objects called IFMEWorkspaceRunner, that does as the name suggests and provides a way to run a workspace from an application.

Check out the API docs at <FME>fmeobjectscppapidocclassIFMEWorkspaceRunner.html (you must choose to install the developer resources to get these).

This document tells me there are 8 public methods available with this class. Let’s see what they do:

IFMEWorkspaceRunner Methods

  • run: Does what you would expect and just runs a workspace using the default parameters.
  • promptRun: Again obvious; fires up the FME parameters dialog for the user then runs the workspace
  • runWithParameters: A vital method, it will let you pass parameter values to FME that you have captured in some other way. i.e. your own application can accept/create parameters, and not have to use the default FME prompts.

This is also important because promptRun accepts parameters and passes them straight to FME. There is no feedback on what those values were. Using runWithParameters this way lets you keep a record of what parameters were set.

Of course, you can’t pass parameter values to a workspace unless you know exactly what parameters are required, and in what form. So there are a series of methods to fetch that information:

  • getPublishedParamNames: This method lets you retrieve a list of parameters for a workspace
  • getParamValues: This method lets you retrieve allowed values for each parameter
  • getParamType: This method lets you retrieve the type of each workspace parameter
  • getParamOptional: This method lets you determine whether each parameter is optional or not
  • getParamLabel: This method lets you retrieve the label text defined for each parameter

For an example of the IFMEWorkspaceRunner, check out the samples in the FME Objects folder; the C++ sample is here: <FME>fmeobjectssamplesCppCppViewerViewerDoc.cpp

IFMEWorkspaceRunner is available for use in C++, Java and .NET in FME2011 beta builds 6458 or greater. Hopefully there will also be a Python version by the time FME2011 is released.

Quick Review!
Q) Why is IFMEWorkspaceRunner important?
A) Developing translations is much easier in Workbench than it is using FME Objects in a programming environment. IFMEWorkspaceRunner is important because it lets you develop a translation in the easier environment (Workbench) and run it within a software application.

And don’t forget…
There are a series of upcoming FME User Meetings in October 2010. Don Murray (our President), Mark Stoakes (head of Professional Services) and Craig Vernon (Director of Sales) will be visiting Regina (SK), Edmonton (AB), Denver (CO), Seattle (WA) and Victoria (BC) for a series of presentations and all sort of other fun.

You can check out the agendas and sign up using the link above.