Thursday, April 16, 2009

Exposing hidden data from Smallworld to FME

A member of the sw-gis group recently posted a question asking how to export join attribute information from Smallworld via FME. I responded to the group but thought the answer might be worth sharing here as well.

Question:

I'm using FME with Smallworld 4.0. How can I export join attributes (e.g., export transformer bank id with the transformer)? I coudn't find it in the FME workbench.


Answer:

I think the easiest way to do this is to use the fme_pseudo_field_factory.

For example...

If you’re your record exemplar is :transformer and the transformer_bank ID attribute is called :transformer_bank_id, then you can define a new FME Pseudo Field...

_pragma(classify_level=basic, usage={redefinable})
## used by FME SWAF interface to allow a customizer to add
## pseudo fields to the schema for Smallworld tables to be
## passed to FME.
transformer.define_shared_constant(:fme_pseudo_fields,
{fme_pseudo_field_factory.new_derived_field(:transformer_bank_id,:extdb_string)},
_false)
$

You can actually define more than one fme_pseudo_field for a given record exemplar if you want to.

Declaring :transformer_bank_id as a new derived field will make this "field" available to the FME feature. When FME asks a "transformer" for its :transformer_bank_id, it will simply call transformer_bank_id and use that value in the workspace.

There is nothing special about the naming convention of the pseudo field. The only thing to keep in mind is that the class on which you define :fme_pseudo_fields must respond (either as a method or field call) to the name of the derived field.

So you could actually accomplish the same thing as above with...

_pragma(classify_level=basic, usage={redefinable})
## used by FME SWAF interface to allow a customizer to add
## pseudo fields to the schema for Smallworld tables to be
## passed to FME.
transformer.define_shared_constant(:fme_pseudo_fields,
{fme_pseudo_field_factory.new_derived_field(:bank_id,:extdb_string)},
_false)
$


As long as you also have defined a method...

_method transformer.bank_id
## bank_id : integer
##
## returns self’s transformer_bank_id

_return _self.transformer_bank_id
_endmethod
$

The FME fme_pseudo_fields concept is very powerful because it allows you to send data to FME that is not stored in a single attribute in Smallworld.

I have used it in the past for exporting data from Physical Network Inventory (PNI). If you are familiar with that datamodel you will know that there are many layers of relationships. Some of the records have geometries and some do not. A customer wanted to export all underground and aerial routes (these are the features with geometry) but wanted to label the features in the exported format with data from a related non-RWO record. Using the fme_pseudo_fields approach made it very easy to create a Magik method that created a suitable labelling string based on the related records but expose the results to FME as a feature attribute.

8 comments:

Ravi Pedapati said...

Does this work for CST4.0?
fme_pseudo_field_factory is a class in FME410 for Smallworld 4.1

Alfred Sawatzky said...

I have used it at 4.0. I believe that it originally shipped as a patch file so you may need to contact your Smallworld support desk to request the extra code.

Mišo Glagolić said...

For FME 400 the patch is part of Technical Support Bulletin Number 106

Anonymous said...

I've tried this with SW41 and it doesn't seem to work. I can see a couple of problems with the source, string length is hard coded to zero for pseudo fields and the pseudo field method doesn't get called. Is there a patch for this?

Junior said...

I have the same issue using pseudo_fields...

The method fme_tics_client.int!create_feature doesn't load any pseudo_field.

The only way to solve the problem was developing my own patch.

Junior said...

I have this issue to in SW4.1..

Basically the fme_tics_client.int!create_feature method don't load any pseudo_field. So, I develop a fix to put the pseudo_fields in the FME features objects.

Duncan MacGrregor said...

There is an official patch for this which fixes the problems in SW41, the patch number is 118434_1 and it will be released in a translators TSB later this year. If you need it urgently then contact your local customer support organisation.

Anonymous said...

Why the logical field width is 0 at the input and output ? except for rwo_id