Question

Make a Dictionary

  • 22 August 2013
  • 4 replies
  • 27 views

Badge +1
I have four attributes coming out of a feature reader and I want to combine three of them into a key with the fourth as a value in a dictionary, something like:

 

 

dictCost = [{"att1::att2::att3" : att4},{"att1::att2::att3" : att4},{"att1::att2::att3" : att4}]

 

 

I know that I can do this in Python, but can I build a dictionary or string-indexd array this way in "straight" FME?

 

 

Thanks

4 replies

Userlevel 4
Badge +13
Hi,

 

 

I would look into the string concatanetor or attribute creator for that for the FME way, otherwise you can always use python in a python caller.

 

Badge +1
I know that I can build the key with the string concatenator. However, I want to build a string indexed array so I can access the value of a given concatenated key. However, FME seems to have only numeric arrays, not a string-indexed array like a Python dictionary.
Userlevel 2
Badge +17
Hi,

 

 

FME cannot build a string-indexed dictionary except in Python script. But in many cases, I think a dictionary-like functionality can be realized via FeatureMerger.

 

If those three attributes were concatenated, the features itself can be considered as a dictionary. That is to say, you can append "att4" associated with a specified key value to any feature using a FeatureMerger.

 

Is this approach useless in your situation?

 

 

Takashi
Badge +1
Using the FeatureMerger as a dictionary is an excellent concept, and that's what I wound up doing. As you have said, when the:

 

 

attr1::attr2::attr3  

 

 

...key matches, then I have attr4 as the value.

 

 

Still, it would be nice to have an FME string-indexed array structure.

Reply