Skip to main content
Solved

copy feature in pythonCaller script

  • December 5, 2016
  • 3 replies
  • 108 views

How can I copy a  feature and its attributes(include geometry) in Python script within PythonCaller? The feature contains a list where the number of items in the list is in the attribute "counter". The idea is to copy the current feature when , change some the attribute values(not geometry), so I am afraid the ListExplode  is not what I need.

def __init__(self):
        self.feature_list = []
 
def input(self,feature):
        total = feature.getAttribute('counter') # num of items in the list
        from = feature.getAttribute('from')
        to = feature.getAttribute('to')
        for i in range(total):           
    # todo: copy feature?
    if some_conditions = True:
                new_feature = fmeobjects.FMEFeature()   # is this right?
                # todo: copy all attributes into new_feature?           
        # todo: change the attribute
                # add to feature_list
                self.feature_list.append(new_feature)

def close(self):
        for feature in self.feature_list:
            self.pyoutput(feature)

Best answer by david_r

If you need to preserve the geometry and only change a few attributes, you can do

new_feature = feature.clone()

Documentation under FMEFeature() here: http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html

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.

3 replies

david_r
Celebrity
  • Best Answer
  • December 5, 2016

If you need to preserve the geometry and only change a few attributes, you can do

new_feature = feature.clone()

Documentation under FMEFeature() here: http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html


david_r
Celebrity
  • December 5, 2016

Also, is there a particular reason for holding on to all the features and not outputting them before the close() method? You're effectively turning your PythonCaller into a blocking transformer like that.


  • Author
  • December 5, 2016

Also, is there a particular reason for holding on to all the features and not outputting them before the close() method? You're effectively turning your PythonCaller into a blocking transformer like that.

 

Now, it is not necessary any more. I will change that. Thanks!