Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I try to learn from Oliver's corner instruction ftp://ftp.safe.com/fme/pyfme/OliversCorner.zip) . So for example I overwrite his #script 4 to StartupPython Script some below and set input data in workflow with name "Fruits":

class MyPythonFactory(object):
     def __init__(self):
         self.count_features = 0
         self.logger = pyfme.FMELogfile()

     def input(self,feature):
         self.count_features += 1

         # Accessing all attributes of a feature
         self.all_attributes = 'Tile'.getAllAttributeNames() # return a list with all attribute names as result
         self.all_attributes_count = len(self.all_attributes) # count attributes

         self.logger.log('Feature: '+ str(self.count_features),1)

         for i in range(self.all_attributes_count):
             self.attribute_name  = self.all_attributes[i]                     # get attribute name
             self.attribute_value = 'Tile'.getAttribute(self.attribute_name)  # get attribute value
             self.logger.log('Attribute: ' + str(self.attribute_name) + '\tValue: ' + str(self.attribute_value), 1)

         self.logger.log('\n',1)
         self.pyoutput('Tile')

     def close(self):
         self.logger.log('Total number of features: ' + str(self.count_features),1)

And according to this I should get following results in log file:

Feature: 1 Attribute: X_INT Value: 3333317 Attribute: ID Value: 1 Attribute: fme_type Value: fme_point Attribute: LASTNAME Value: von Goethe Attribute: Y_INT Value: 5684892 Attribute: fme_feature_type Value: points Attribute: fme_geometry Value: fme_point Attribute: SHAPE_GEOMETRY Value: shape_point Attribute: X_FLOAT Value: 3333317 Attribute: SURNAME Value: Johann Wolfgang Attribute: Y_FLOAT Value: 5684892

But I do not get any results of this script in logfile!

So my questions are:

  1. How script recognize which feature I will use If there are more? Is feature name actually name of input data for example, so I should use 'Fruits'?
  2. Do I have to replace word 'feature' in code with corresponding feature name in workbench?
share|improve this question
2  
Please provide a link to the original code that you are modifying. –  Chad Cooper Oct 6 '11 at 13:02
    
link is above. Thank you very much for suggestioN! –  Z77 Oct 6 '11 at 13:38
2  
Personally I have not been able to get a grasp of Python in FME either, except for scripted parameters. Thankfully they are rewriting the Python FME API (and actually documenting it this time) for FME 2012: fmepedia.safe.com/articles/FAQ/… –  blah238 Oct 6 '11 at 22:43
add comment

1 Answer 1

up vote 2 down vote accepted

That Python snippet is not appropriate for a Startup Python Script. It's purpose is to process features, so you need to place it in a PythonCaller transformer.

http://docs.safe.com/fme/html/FME_Transformers/content/transformers/pythoncaller.htm

Startup Python Scripts would not typically operate on features, but could be used to do more generic preparation before the workspace is run.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.