Skip to main content
Question

How to compare two lists and output different elements?

  • November 20, 2019
  • 7 replies
  • 543 views

I've got two identical line/point features, each of them has a list of all attributes created by Aggregator. I want to compare these two list, some elements are same and some are not and number of elements may not be same. Matcher or ChangeDetector can do comparing part but can not out which elements are different. Is there a way to compare two lists and output different elements? Or can I just compare attributes of two features without creating lists?

7 replies

sigtill
Contributor
Forum|alt.badge.img+24
  • Contributor
  • November 20, 2019

Perhaps use the ListBasedFeatureMerger ?


  • Author
  • November 20, 2019
sigtill wrote:

Perhaps use the ListBasedFeatureMerger ?

I read the help document and I don't think it is what I wanted, maybe you can show me an example?


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • November 20, 2019

Presumably you want to avoid having to explode the lists?


  • Author
  • November 20, 2019
ebygomm wrote:

Presumably you want to avoid having to explode the lists?

I can live with that, and the list was created based on the attribute.


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • November 20, 2019
bobo wrote:

I can live with that, and the list was created based on the attribute.

Do you want to compare the attributes of each feature, or the attribute values of each feature? Or both?

I think a changedetector might be able to help you here. As it will provide a list of the differences


  • Author
  • November 20, 2019
ebygomm wrote:

Do you want to compare the attributes of each feature, or the attribute values of each feature? Or both?

I think a changedetector might be able to help you here. As it will provide a list of the differences

Attribute values of each feature mainly, if the attributes between two feature are not same, then just skip the comparing part and just output a message in a newly created attribute.


verdoodtdries
Supporter
Forum|alt.badge.img+18

Assuming you have two lists where the only difference is the number of elements. In that situation one can detect the additional elements using Python.

# Get  FME-list into a Python-list
myList1 = feature.getAttribute('myList1{}')
myList2 = feature.getAttribute('myList2{}')
 
# Cast list to set
# Substract set
# Cast to list again
myDifference  = list(set(myList2) - set(myList1))

Note that it is possible to convert your FME-list into a Python-list.


Reply


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