Question

Dynamic Attributes in custom transformer?

  • 19 August 2016
  • 4 replies
  • 44 views

Badge

Hi Community,

I created a custom transformer to connect an Inspector with internally defined color styles.

I got fme_color and fme_fill_color as public Parameters.

Purpose is to define the output colors in my Workspace instead in the Data Inspector, so each time I run the process it'll look similarly.

Now I see that all the attributes of my input data is not going through that custom transformer, I need to expose them inside the transformer. But that's kind of senseless to me since I'd like to use that for a variety of data structures, means for each new dataset I need to expose other attributes (different numbers and names of attributes).

Is there a way to create it in an dynamic way like it's possible in FeatureWriters?

Thank you in advance,

Maik.


4 replies

Userlevel 4

Exposing an attribute only means that it'll be visible when designing the workspace. There is no guarantee that the attribute will be available when the workspace is running, as you can expose any attribute name possible. When the workspace is running, it makes not difference to FME if the attribute has been exposed first or not. So I think that exposing dynamic attributes makes little sense.

A few ways to get around this:

  • Manually expose all the possible attribute names (AttributeExposer). This only works if all the possible attribute names are known and there aren't too many of them. Exposing a huge number of attributes risk bloating your workspace and making the FME Workbench sluggish to work with.
  • Dynamically iterate over all the attributes present at run-time using the AttributeExploder transformer. This is a fast and easy solution to implement, but for huge number of features with lots of attributes it may be slow to execute and can consume a lot of memory.
  • Use Python scripting to iterate over all the attributes on each feature, then either do the processing inside your Python script or tag the features and use e.g. a TestFilter after to direct your features according to the tag. This is pretty fast and consumes relatively little memory, but can be a bit complicated if you don't know Python already. There are already a couple of examples on this forum if you look around, e.g. here.

Hopefully someone else can give more suggestions.

Userlevel 2
Badge +17

Hi @maikhertel, from another point of view. If the number of required attributes was fixed, you could pass their values to the custom transformer through its published parameters and use them with common attribute names internally. However, if the number of attributes is different depending on scenarios, I don't think it's possible to create internal attributes dynamically, in general. There could be some special cases where any number of attributes may be passed to a custom transformer through an 'Attribute List' type published parameter, but I don't know whether your case is so.

Badge

Thank you for reply, I'll have a look at it.

But in my special case, I just reviewed the parameters of the standard Inspector, et voila ... there is everthing I was looking for. I can enter vector and area fill color without the custom transformer above and I didn't see these options until now.

But for transfering attributes through a custom transformer like "Dear transformer, please take this set of data, do something with it and give it back with it's original attribute structure" a simple solution would be highly appreciated.

Userlevel 4
Badge +25

I must be misunderstanding. Transformers usually should "take this set of data, do something with it and give it back with it's original attribute structure". I just created a small movie to demonstrate that.

http://screencast.com/t/ouHfIW5mh

If this is what you want, but it's not what you are seeing in Workbench, then please do let us know.

NB: The other transformer you can use is the FeatureColorSetter. This will let you change the color of features and it will be picked up by the Inspector.

Reply