Skip to main content
Question

How to compare two lists and output different elements?

  • November 20, 2019
  • 7 replies
  • 737 views

bobo
Contributor
Forum|alt.badge.img+3
  • Contributor
  • 46 replies

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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

sigtill
Supporter
Forum|alt.badge.img+25
  • Supporter
  • 956 replies
  • November 20, 2019

Perhaps use the ListBasedFeatureMerger ?


bobo
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 46 replies
  • November 20, 2019

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+44
  • Influencer
  • 3427 replies
  • November 20, 2019

Presumably you want to avoid having to explode the lists?


bobo
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 46 replies
  • November 20, 2019

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+44
  • Influencer
  • 3427 replies
  • November 20, 2019

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


bobo
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 46 replies
  • November 20, 2019

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+22
  • Supporter
  • 53 replies
  • January 12, 2024

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.