Question

Accessing attribute values in custom transformers

  • 15 October 2013
  • 3 replies
  • 3 views

Badge
I'm having difficulty understanding how to access attributes within a custom transformer. 

 

 

I have a workflow that takes two sets of input features, call them sources and candidates. Each has a unique ID field, call them SOURCE_ID and CAND_ID.

 

 

I want to spatially match the features from one set (the candidates) against the features from the other set (the sources), determining the source feature that the greatest proportion of the candidate feature is closest to.  So each candidate feature is split into points (vertices) and each vertex is matched to the nearest source with a Neighbour Finder. Then I summarise to find what proportion of each candidate was matched to each source. So that uses a ListBuilder, grouping by CAND_ID, and a ListHistogrammer to find out how many vertices in each candidate were matched to each SOURCE_ID.

 

 

This all works, but now I want to put it into a custom transformer. Within that I need to access the value of the CAND_ID field, to put as the Group By in the ListBuilder, and the SOURCE_ID field, as the list attribute to summarise in the ListHistogrammer.  I can't figure out how to do this without forcibly exposing them using an AttributeExposer which I understand is a hack and will stop the transformer working if the name of those fields changes in the input data.

 

 

On the ListBuilder I can set the Group By to a parameter. But on the ListHistogrammer I can't see a way to use a parameter to tell the ListHistogrammer what SourceListAttribute it should summarise by. 

 

 

I'm sure I'm missing something obvious! Any ideas? Thanks!

3 replies

Userlevel 4
Hi,

 

 

the most flexible way is to define your input attributes as published parameters in your custom transformer.

 

 

You can define the parameter as type "Attribute name", that makes it easier to use your custom transformer in the Workbench.

 

 

Inside your custom transformer, use an AttributeDereferencer on your published parameter to get the value into a named attribute that is internal to the custom transformer. You then do your processing using this internal attribute, rather than a hard-coded name as you would using the AttributeExposer.

 

 

I recommend removing this internal attribute (AttributeRemover( before the output.

 

 

David
Badge
David,

 

 

Thank you very much! The AttributeDereferencer was exactly what I needed. I wasn't aware of that and hadn't managed to find it with searching with that obscure name.

 

 

One further question though. In the AttributeDereferencer, if I put the published parameter in for the Source Attribute, this doesn't seem to work (the requested Destination Attribute is not added to the output feature). I have made it work by using a ParameterFetcher first to load the parameter value into yet another attribute, then choosing this in the AttributeDereferencer. Is this what you'd expect? Why wouldn't it work using the parameter directly in the AttributeDereferencer?

 

 

Thanks again,

 

Harry

 

 

 

 

Userlevel 4
Hi,

 

 

I'm surprised that the AttributeDereferencer can't use the published parameter name directly. I'd say that might be a bug, consider sending it in to Safe so they can have a look.

 

 

David

Reply