Skip to main content

Hi,

I'm having 2 lists: _listold (with 10 coordinates present (before)) & _listnew (with 4 coordinates (after).

I want to merge those 2 lists into 1 list but it should merge on the index in order except for the last index, last index of first list should be merged with last index of second list. Afterwards I want to explode the list, aggregate and pivot to get something like this:


beforeafter00112234567893

I've taken a look at the ListMerger and it merges the 2 lists but how I want, but I have no idea how to modify the python logic behind it (python is still Japanese to me :))

Anyone an idea how to get this part?

Hi Vat,

I don't really get wat your input is could you provide me a little test input dataset and the desired output? In the example above I cannot see the two lists you are talking about. I do also not understand what you mean with:

"it should merge on the index in order except for the last index, last
index of first list should be merged with last index of second list"

Could you try to explain it differently / with a small example?


Hi @vat, if I understand your requirement correctly, this workflow could help you.

[Edited]

  1. Save the number of elements of the two list attributes using the ListElementCounter (e.g. "_num_old" for _listold, "_num_new" for _listnew).
  2. Divide the feature flow into two streams; in the upper flow, explode the feature on the _listold{} with the ListExploder.
  3. In the lower flow, explode the feature on the _listnew{} with the ListExploder. Then seeing the element index, if it was the last element (i.e. element index = _num_new - 1), change the index to the last index of the _listold (_num_old - 1). The AttributeCreator with conditional value setting can be used to do that.
  4. Merge the lower flow (Supplier) to the upper flow (Requestor) with the FeatureMerger. Set the element index to "Join On" parameter. The features coming from the Merged port and NotMerged port form the required table.

Hi @vat, if I understand your requirement correctly, this workflow could help you.

[Edited]

  1. Save the number of elements of the two list attributes using the ListElementCounter (e.g. "_num_old" for _listold, "_num_new" for _listnew).
  2. Divide the feature flow into two streams; in the upper flow, explode the feature on the _listold{} with the ListExploder.
  3. In the lower flow, explode the feature on the _listnew{} with the ListExploder. Then seeing the element index, if it was the last element (i.e. element index = _num_new - 1), change the index to the last index of the _listold (_num_old - 1). The AttributeCreator with conditional value setting can be used to do that.
  4. Merge the lower flow (Supplier) to the upper flow (Requestor) with the FeatureMerger. Set the element index to "Join On" parameter. The features coming from the Merged port and NotMerged port form the required table.

Thanks Takashi, you response is exactly what I needed, now I need to stress test this if I have 1000's of lines with very complex mappings :)


If you don't mind using Python script...

# PythonCaller Script Example
# Assuming that the number of _oldlist{} elements is always
# greater than or equal to the number of _newlist{} elements.
class FeatureProcessor(object):
    def input(self,feature):
        oldList = feature.getAttribute('_oldlist{}')
        newList = feature.getAttribute('_newlist{}')
        oldEnd = len(oldList) - 1
        newEnd = len(newList) - 1
        for i, b in enumerate(oldList):
            feature.setAttribute('before', b)
            a = ''
            if i < newEnd:
                a = newListei]
            elif i == oldEnd:
                a = newListÂ-1]
            feature.setAttribute('after', a)
            self.pyoutput(feature)

FYI.


Reply