Skip to main content
Solved

How to create a string from several records with same ID in one attribute?


Forum|alt.badge.img

Hi,

I have two non-spatial features and need to bring together the string values from several records in one attribute.

For example:

FK1

IDState1CH2US3AU4IT5FR

FK2

IDNarrative1B11B21B32C12C23D33D43D53D7

I need to get follow result:

IDStateNarrative1CHB1, B2, B32USC1, C23AUD3, D4, D5, D7

How can I do it with FME?

Thanks for help

Best answer by erik_jan

You can use an Aggregator (concatenate Narrative and group by ID) on the second dataset and then use a FeatureMerger to merge that dataset to the first.

View original
Did this help you find an answer to your question?

6 replies

redgeographics
Celebrity
Forum|alt.badge.img+49

Use a ListBuilder on the 2nd dataset, set to group by ID, and then a ListConcatenator on the Narrative attribute. Then a FeatureMerger to match it with the 1st dataset


takashi
Influencer
  • July 11, 2017

Hi @zoran68, the FeatureMerger with "Generate List" option can be used to merge multiple FK2 records as list elements to a FK1 record having the same ID. You can then use the ListConcatenator to concatenate the list elements using any delimiter (e.g. comma).


redgeographics
Celebrity
Forum|alt.badge.img+49
redgeographics wrote:

Use a ListBuilder on the 2nd dataset, set to group by ID, and then a ListConcatenator on the Narrative attribute. Then a FeatureMerger to match it with the 1st dataset

Never mind, I messed up my answer and as I was trying to get it right @takashi came up with the right one.

 


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • Best Answer
  • July 11, 2017

You can use an Aggregator (concatenate Narrative and group by ID) on the second dataset and then use a FeatureMerger to merge that dataset to the first.


danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • July 11, 2017

Hi @zoran68, i created the template file with your case using the FeatureMerger.

Thanksworkspace-list.fmwt


takashi
Influencer
  • July 11, 2017

off-topic: I'm exploring more effective usage of XQuery expressions in FME workspaces. This might be a typical example.

0684Q00000ArKagQAF.png

ROOT Template:

let $r := <root>{fme:process-features("SUB")}</root>
return {
    "ID": fme:get-attribute("ID"),
    "State": fme:get-attribute("State"),
    "Narrative": fn:string-join({for $v in $r/sub/@Narrative return $v}, ",")
}

SUB Template:

<sub Narrative="{fme:get-attribute("Narrative")}" />


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