Question

How to compare two lists and output different elements?

  • 20 November 2019
  • 7 replies
  • 91 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

Badge +21

Perhaps use the ListBasedFeatureMerger ?

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?

Userlevel 1
Badge +21

Presumably you want to avoid having to explode the lists?

Presumably you want to avoid having to explode the lists?

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

Userlevel 1
Badge +21

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

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.

Badge +3

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