Skip to main content
Solved

Is there a way to read schema or create schema features attribute from a single feature?

  • September 4, 2018
  • 3 replies
  • 50 views

Forum|alt.badge.img

I am trying to read the results for a SQLExecutor. The transformer does not have the possibility to expose schema features. And I would need it (rather than reading the table from the DB with a FeatureReader)

following the advice from the answers for this question:

I am using Python to read the feature name and types and create a schema feature with the format

attribute{n}.fme_data_type

attribute{n}.name

import fme
import fmeobjects
# Template Function interface:
# When using this function, make sure its name is set as the value of
# the 'Class or Function to Process Features' transformer parameter
def processFeature(feature):
    feature_attr_names = feature.getAllAttributeNames()
    i = 0
    for feature_attr_name in feature_attr_names:
        feature.setAttribute('attribute{0}.fme_data_type'.format(i), feature.getAttributeType(feature_attr_name))
        feature.setAttribute('attribute{0}.name'.format(i), feature_attr_name)
        i+=1
    pass

When it comes to expose the attributes I create FME does not seem to be able to iterate the creation and I have to insert manually the numbers for every "n". If I do this the resulting schema attribute is created but with round brackets and not curly brackets, and fme_data_type is an number (that is the corresponding variable for FME_data_type as described here.

Has anyone ever managed to accomplish what I am trying to do and could help me?

Best answer by david_r

The easiest by far is probably to use the SchemaSetter from the FME Hub, it will do exactly this.

You can also look at the Python code inside to see how it's done.

View original

3 replies

david_r
Evangelist
  • Best Answer
  • September 4, 2018

The easiest by far is probably to use the SchemaSetter from the FME Hub, it will do exactly this.

You can also look at the Python code inside to see how it's done.


david_r
Evangelist
  • September 4, 2018

Here's a hint. This code:

'attribute{0}.fme_data_type'.format(5)

will return

'attribute5.fme_data_type'

But you need to preserve the {} brackets, like this:

'attribute{5}.fme_data_type'

So you need to use a triple bracket in the format string, like this:

'attribute{{{0}}}.fme_data_type'.format(5)

Forum|alt.badge.img
  • Author
  • September 4, 2018
david_r wrote:

Here's a hint. This code:

'attribute{0}.fme_data_type'.format(5)

will return

'attribute5.fme_data_type'

But you need to preserve the {} brackets, like this:

'attribute{5}.fme_data_type'

So you need to use a triple bracket in the format string, like this:

'attribute{{{0}}}.fme_data_type'.format(5)
Yes investigating the issue I realised I needed three braces and also that the SchemaSetter already does what I am looking for, it has an internal dictionary to map the integers to types. Thanks

 

 


Reply


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