Question

Python: Create FMENull feature with Name and Traits

  • 3 February 2020
  • 2 replies
  • 6 views

Badge +10

I am working on a workspace that receives a list of previously unknown attributes and their values. They come as a list of attributes: '_list{}.Property' and '_list{}.Value'. These sets need to become GeometryTraits on an FMENull geometry. Usually I would use a GeometryPropertySetter to create those traits, but since it is unknown upfront how many features these lists contain, I want to use a PythonCaller to loop through the list and set the traits.

 

 

I seem neither to be able to create an FMENull feature, nor to set it's geometry name or traits. Can anyone help me with a working code snippit?

2 replies

Userlevel 2
Badge +17

Hi @lars_de_vries, hope this helps.

import fmeobjects
def processFeature(feature):
    geom = fmeobjects.FMENull()
    geom.setName('name')
    properties = feature.getAttribute('_list{}.Property')
    values = feature.getAttribute('_list{}.Value')
    for p, v in zip(properties, values):
        geom.setTrait(p, v)
    feature.setGeometry(geom)

http://docs.safe.com/fme/html/fmepython/api/fmeobjects/geometry/_general/fmeobjects.FMEGeometry.html#fmeobjects.FMEGeometry

Badge +10

Hi @lars_de_vries, hope this helps.

import fmeobjects
def processFeature(feature):
    geom = fmeobjects.FMENull()
    geom.setName('name')
    properties = feature.getAttribute('_list{}.Property')
    values = feature.getAttribute('_list{}.Value')
    for p, v in zip(properties, values):
        geom.setTrait(p, v)
    feature.setGeometry(geom)

http://docs.safe.com/fme/html/fmepython/api/fmeobjects/geometry/_general/fmeobjects.FMEGeometry.html#fmeobjects.FMEGeometry

Thank you @takashi for your wonderfull solution! 

I tried something similar, but couldn't get it figured out.

Reply