Skip to main content
Solved

copy feature in pythonCaller script


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

View original
Did this help you find an answer to your question?

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
david_r wrote:

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!

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