2013-09-25

WorkspaceRunner Examples

In past, there was an article describing WorkspaceRunnder examples in FMEpedia. Although there is a link to the URL in the WorkspaceRunner transformer description (Workbench help), the linked page is currently disabled. Where has it gone?
-----
2013-10-02
The article has been updated, 1 Oct. 2013. Link from Workbench help is also available.
Thank you, Safe support team!
FMEpedia: Batch Processing Using the WorkspaceRunner
-----

Usage of the WorkspaceRunner is not so difficult. But many beginners seem to feel it's difficult to understand how it works, as I was so. In fact, questions about the WorksapceRunner are often posted in Community, I recently posted a couple of examples to correspond to such a question.

> Creating a BATCH with multiple INPUTS (variables) to run a workbench that intersects LINES AND POLYGONS
> Workspace Runner and Path Format Reader example
For these questions I provided example workspaces showing the most basic usage of the WorkspaceRunner - i.e. performing simple batch processing.
Download (3MB zipped file including test data)

> Dynamic schema partial merge from 2 data sources
Although the subject of this question is an application of Dynamic Schema functionality, I thought it can be realized using the WorkspaceRunners, and created applicable workspaces. It was a very interesting challenge.
Download (32KB zipped file, including test data)
-----
2013-09-27
However, a custom format could be more elegant solution in this case.
Download: Custom Format Example 0 (22KB) using Python script
Download: Custom Format Example 1 (23KB) non-scripted version
Related article: FMEpedia > Extracting a schema subset for dynamic schemas
-----

Through creating these examples, I felt that knowing well about Published Parameters is the key to understand how the WorkspaceRunner works.
Anyway, I hope that the upgraded article is uploaded to FMEpedia in the near future.

2013-09-11

What does the InsidePointReplacer create?

FME provides three transformers to create a point related to an area feature.
CenterOfGravityReplacer creates the center of mass,
CenterPointReplacer creates the center of the bounding box,
InsidePointReplacer creates an inside point of the original area.

The point created by the InsidePointReplacer is guaranteed to be inside of the original area, but other transformers may create an outside point. The center point or the center of mass of U or L shape probably is outside, for example.
If knowing what kind of point will be created, there are no practical problems.

However, I want to know the actual algorithm that is used in the InsidePointReplacer.
If the original shape is a triangle or a rectangle, the inside point seems to match with the center of mass. Otherwise, the inside point is different from the center of mass even if that is inside the area.
The algorithm is in a black box.

> Community: Deaggregating polygons andresultant centroid position

2013-09-01

Extract List Attribute Elements in Python Script

=====
2013-12-23: FME 2014 supports <null>; a list attribute can also contain <null> elements. But FMEFeature.getAttribute and setAttribute methods do not treat <null> elements as <null>.
We should be aware this point in FME 2014+.
See more information here > Null in FME 2014: Handling Null with Python / Tcl
=====

To extract list attribute elements and create non-list attributes storing the values:
Simple List: _list{i} --> attr_i
# Example 1
def extractListElements(feature):
    i = 0
    while True:
        v = feature.getAttribute('_list{%d}' % i)
        if v == None:
            break
        feature.setAttribute('attr_%d' % i, v)
        i += 1

# Example 2
def extractListElements(feature):
    list = feature.getAttribute('_list{}')
    if list != None:
        for i, v in enumerate(list):
            feature.setAttribute('attr_%d' % i, v)

Complex List: _list{i}.attr --> attr_i
# Example 3
def extractComplexListElements(feature):
    i = 0
    while True:
        v = feature.getAttribute('_list{%d}.attr' % i)
        if v == None:
            break
        feature.setAttribute('attr_%d' % i, v)
        i += 1

# Example 4
def extractComplexListElements(feature):
    list = feature.getAttribute('_list{}.attr')
    if list != None:
        for i, v in enumerate(list):
            feature.setAttribute('attr_%d' % i, v)

Nested List: _list{i}.sub{j} --> attr_ij
# Example 5
def extractNestedListElements(feature):
    i = 0
    while True:
        sub = feature.getAttribute('_list{%d}.sub{}' % i)
        if sub == None:
            break
        for j, v in enumerate(sub):
            feature.setAttribute('attr_%d%d' % (i, j), v)
        i += 1

Related articles:
Community > Set a list attribute in Python
Community > FME Terminologies about List Attribute

2013-08-24

Japanese character problem

=====
2103-12-19: I confirmed that almost all the problems  related to Japanese characters has been solved in FME 2014 Beta Build 14220.
> Japanese Character Problems in FME 2014 Beta
=====

The Japanese Windows usually uses the code page 932 to process character strings. In this environment, a standard Japanese character is represented with two byte code.
There are some characters whose second byte is equal to 0x5c. Since 0x5c indicates a back slash (\) in ascii character code set, those characters could cause problem in string processing. So, some people often call them as だめ文字 (damemoji: dumb characters).

Almost all the damemoji are seldom used, but one of them - 表 (hyou) exceptionally very often occurs in FME use cases, because it means "table".
What is worse, FME currently doesn't work if a Reader / Writer Feature Type Name ends with a damemoji. In fact, there are many database tables, Excel worksheets, csv files named "****表" (foobar_table). We have to replace "表" with a non-damemoji character or remove it in such a case. This is the only workaround in the meantime.
It's a serious problem for the Japanese FME users.
Hope strongly that the problem is solved as soon as possible.

=====
2013-11-29: On Writers, it seems that this problem has been solved in FME 2013 SP2+.
Many thanks, Safe!

=====
2013-11-29: A friend asked me. "There should be many countries other than Japan using 2-byte character code set. Are there Damemoji in those countries?"
Probably, yes. According to "Shift_JIS" (Wikipedia Japanese version), GBK (Chinese, cp936) and Big5 (Traditional Chinese, cp950) also have some Damemoji - i.e. characters whose second byte is 0x5C.
But I have not heard that the problem similar to Shift JIS (Japanese, cp932) occurs in FME use cases. If there is an opportunity, I would like to discuss with Chinese FME users about this problem.

Next: Japanese Character Problems in FME 2014 Beta

Find the shortest path visiting all the given points

If the order of visiting points is defined, these transformers can be used to do that.
PointConnector: create a line connecting the points in the order of visiting.
Chopper: split the line into individual line segments.
ShortestPathFinder: find shortest paths for all the segments (FROM-TO lines).
* FME 2013+

-----
2013-09-18
It's not necessary to chop the line into individual line segments.
ShortestPathFinder help:
"It can contain intermediate stops before the final destination. For example, a FROM-TO line may be used to find the path from A to B to C to D. This can also be read as “the path from A to D that also passes through B and C.”
-----

It's not so difficult, I recently created a practical workspace based on this approach for an actual project.
But when the the order of visiting is unknown - in other words, when you need to find the optimal route which visits all the given points, it will be the famous "Travelling salesman problem". Several approximation algorithms have been invented to solve the problem, however, FME currently doesn't support them.
> Community: Shortest path along a network between multiple points