Skip to main content
Question

Trouble with StringConcatenator.


Forum|alt.badge.img
Hi all. I need to put values of all attributes from source table to one field in target table. Of course, i used StringConcatenator and everything works great. But problem is that i need to put only attributes with values. For example i have table with fields CITY, STREET, BLD_NUMBER:

 

 

        CITY         STREET    BLD_NUMBER

 

1. New-York   42 street               150

 

2.    Albany           null                    17

 

 

and strings wich i got

 

[CITY:New-York, STREET:42 street, BLD_NUMBER:150] - ok, that's what i need

 

[CITY:Albany, STREET:, BLD_NUMBER:150] - but i need string like this [CITY:Albany, BLD_NUMBER:150]

 

 

the question is how to get what i need? Thanks for answers

4 replies

sigtill
Supporter
Forum|alt.badge.img+24
  • Supporter
  • April 10, 2013
Have you tried the NullAttributeRemover?

Forum|alt.badge.img+2
  • April 10, 2013

If it's just Street that could be empty on the concatenated string use a StringReplacer with Text to find

 STREET:,

 

 

replacing with nothing

david_r
Celebrity
  • April 11, 2013
Hi,

 

 

here is a simple Python script that will concatenate an arbitrary list of attributes, ignoring empty attribute values (NULL or empty string).

 

 

-----

 

import fmeobjects   def FeatureProcessor(feature):     to_concatenate = ("CITY", "STREET", "BLD_NUMBER") # Modify as needed     join_string = "," # Modify as needed     result = join_string.join([feature.getAttribute(attr) \\         for attr in to_concatenate if feature.getAttribute(attr)])     feature.setAttribute("CONCATENATED", result)

 

-----

 

 

Modify the variable "to_concatenate" so that it contains the names of all the attributes to join (case sensitive!) and modify "join_string" to whatever delimiter you desire, either a single character or a string.

 

 

For the PythonCaller, add "CONCATENATED" to the parameter "Attributes to expose".

 

 

Sample results:

 

`CONCATENATED' has value `Albany,17'

 

`CONCATENATED' has value `New-York,42 street,150'

 

 

David

Forum|alt.badge.img
  • Author
  • April 12, 2013
Table with cities just for example. Real tables contain 3-30 different fields. Specify each field in each table it's kinda boring. And concatenated string must contain name of each field and their values. 

 

 

I like idea with NullAttributeRemover, but i don't know how to insert in string field's name constant of attribute that can be or not after NullAttributeRemover.

 

 

Maybe here possible use an user parameter which contain all attributes of feature or something like this. I am new one to FME and not sure about it.

 

 

Anyway, thanks for answers.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings