Skip to main content
Question

merge 2 attributes from a list on a new attribute list


alc33
Contributor
Forum|alt.badge.img+10
  • Contributor

Hi !

I have a list named "coord" that contain 2 attributes "x" and "y". I would like to create an other attribute that concatate "x" and "y". For example :

line number 1 (one geometry) :

coord{0}.x = 1.25

coord{0}.y = 1.25

coord{1}.x = 2.25

coord{1}.y = 2.25

Résult :

coord{0}.x = 1.25

coord{0}.y = 1.25

coord{0}.all = 1.25;1.25

coord{1}.x = 2.25

coord{1}.y = 2.25

coord{1}.all = 2.25;2.25

Thanks for your help !

8 replies

panda
Enthusiast
Forum|alt.badge.img+18
  • Enthusiast
  • October 26, 2023

I was able to do it by using ListExploder and use Attribute Creator to create new attribute call combine and then put it back together using ListBuilder with Group Processing using ObjectID (or any unique number to that feature)

I compare the line after it put back together to make sure that element index actually go back to the correct place and it seem like it does (But definitely randomly check it in your case just to make sure)

 

Merge2att


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 27, 2023

Hi! Thanks for your answer. It work very well. Do you think it's possible to add a new attribute list using Python, to avoid geometry manipulation?


takashi
Influencer
  • October 27, 2023
alc33 wrote:

Hi! Thanks for your answer. It work very well. Do you think it's possible to add a new attribute list using Python, to avoid geometry manipulation?

Hi @alc33​ ,

PythonCaller with this script might help you.

class FeatureProcessor(object):
    def __init__(self):
        pass
        
    def input(self, feature: fmeobjects.FMEFeature):
        xs = feature.getAttribute('coord{}.x')
        ys = feature.getAttribute('coord{}.y')
        feature.setAttribute('coord{}.all', ['%s;%s' % (x, y) for x, y in zip(xs, ys)])
        self.pyoutput(feature)
 
    def has_support_for(self, support_type: int):
        return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
  
    def close(self):
        pass
 
    def process_group(self):
        pass

 

 


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 27, 2023
takashi wrote:

Hi @alc33​ ,

PythonCaller with this script might help you.

class FeatureProcessor(object):
    def __init__(self):
        pass
        
    def input(self, feature: fmeobjects.FMEFeature):
        xs = feature.getAttribute('coord{}.x')
        ys = feature.getAttribute('coord{}.y')
        feature.setAttribute('coord{}.all', ['%s;%s' % (x, y) for x, y in zip(xs, ys)])
        self.pyoutput(feature)
 
    def has_support_for(self, support_type: int):
        return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
  
    def close(self):
        pass
 
    def process_group(self):
        pass

 

 

@Takashi Iijima​ thanks for your answer !

I'm sorry but I have a termination message and I don't understand why?

I'm using FME 2020.2 and python 3.7+

Thank you.

 

image.png 


takashi
Influencer
  • October 27, 2023
takashi wrote:

Hi @alc33​ ,

PythonCaller with this script might help you.

class FeatureProcessor(object):
    def __init__(self):
        pass
        
    def input(self, feature: fmeobjects.FMEFeature):
        xs = feature.getAttribute('coord{}.x')
        ys = feature.getAttribute('coord{}.y')
        feature.setAttribute('coord{}.all', ['%s;%s' % (x, y) for x, y in zip(xs, ys)])
        self.pyoutput(feature)
 
    def has_support_for(self, support_type: int):
        return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
  
    def close(self):
        pass
 
    def process_group(self):
        pass

 

 

I think the script should work in FME 2020 too.

Most likely you have not created xs and ys (lists of x values and y values) from "coord{}.x" and "coord{}.y".

Check if these two lines are correct. 

        xs = feature.getAttribute('coord{}.x')
        ys = feature.getAttribute('coord{}.y')

 


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 30, 2023
takashi wrote:

Hi @alc33​ ,

PythonCaller with this script might help you.

class FeatureProcessor(object):
    def __init__(self):
        pass
        
    def input(self, feature: fmeobjects.FMEFeature):
        xs = feature.getAttribute('coord{}.x')
        ys = feature.getAttribute('coord{}.y')
        feature.setAttribute('coord{}.all', ['%s;%s' % (x, y) for x, y in zip(xs, ys)])
        self.pyoutput(feature)
 
    def has_support_for(self, support_type: int):
        return support_type == fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
  
    def close(self):
        pass
 
    def process_group(self):
        pass

 

 

You are right, the name of the list was different. It work very well! Thank you !


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 30, 2023

thank you very much @panda​ @Takashi Iijima​ !


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • October 31, 2023

Just a precision for the person that aren't used  to use pythoncaller (like me :) ). Before the code above you have to write :

import fme

import fmeobjects

This 2 lines are in the transformer at his opening.

 

And then, to see the new attribute in the others transformers, you have to use AttribueExposer.


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