Skip to main content
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

 

pCITY: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
Have you tried the NullAttributeRemover?

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

 STREET:,

 

 

replacing with nothing
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(sfeature.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
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.

Reply