Skip to main content
Best Answer

PythonCaller's output lost all attributes!

  • March 20, 2019
  • 6 replies
  • 54 views

dataninja
Forum|alt.badge.img

Hi everyone,

I have created a custom transformer to generate points using lat/lng using the following simple script. It works totally fine. However, it loses all of the attributes coming from my input file. Is there a way to retain it dynamically?

 

 

 

Best answer by takashi

You have created and returned a new FMEFeature instance in the script. FME won't propagate the attributes of the input feature to the new feature automatically.

If you need to preserve all the attributes in the input feature, you don't need to create a new feature.

Just set the geometry and the coordinate system to the input 'feature' and output it.

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.

6 replies

takashi
Celebrity
  • Best Answer
  • March 20, 2019

You have created and returned a new FMEFeature instance in the script. FME won't propagate the attributes of the input feature to the new feature automatically.

If you need to preserve all the attributes in the input feature, you don't need to create a new feature.

Just set the geometry and the coordinate system to the input 'feature' and output it.


david_r
Celebrity
  • March 20, 2019

I agree with @takashi. If, for some reason you really need to create a new copy of the incoming feature, you can replace the line

newFeature = fmeobjects.FMEFeature()

with

newFeature = feature.clone()

This will create a new feature as a clone of the incoming feature.


dataninja
Forum|alt.badge.img
  • Author
  • March 20, 2019

You have created and returned a new FMEFeature instance in the script. FME won't propagate the attributes of the input feature to the new feature automatically.

If you need to preserve all the attributes in the input feature, you don't need to create a new feature.

Just set the geometry and the coordinate system to the input 'feature' and output it.

Thanks Takashi,

newFeature = fmeobjects.FMEFeature() newFeature.setGeometry(FMEPoint(float(feature.getAttribute('lONGITUDE')), float(feature.getAttribute('lATITUDE'))))

so I am trying the following line instead but getting this error. Do you know why?

FMEFeature.setGeometry(FMEPoint(float(feature.getAttribute('lONGITUDE')), float(feature.getAttribute('lATITUDE'))))

 


dataninja
Forum|alt.badge.img
  • Author
  • March 20, 2019

I agree with @takashi. If, for some reason you really need to create a new copy of the incoming feature, you can replace the line

newFeature = fmeobjects.FMEFeature()

with

newFeature = feature.clone()

This will create a new feature as a clone of the incoming feature.

Thanks David for the tip!


dataninja
Forum|alt.badge.img
  • Author
  • March 20, 2019

You have created and returned a new FMEFeature instance in the script. FME won't propagate the attributes of the input feature to the new feature automatically.

If you need to preserve all the attributes in the input feature, you don't need to create a new feature.

Just set the geometry and the coordinate system to the input 'feature' and output it.

oh it should be feature instead of FMEFeature


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • March 20, 2019

It tends to be more straightforward to use the function interface rather than the class interface if you're just doing a one in one out process

import fme
import fmeobjects

def processFeature(feature):
    feature.setGeometry(fmeobjects.FMEPoint(float(feature.getAttribute('longitude')), float(feature.getAttribute('latitude'))))
    feature.setCoordSys(feature.getAttribute('coord_sys'))

 

Even easier to just use a vertex creator though :-)