Question

coordinate system transformation

  • 8 August 2013
  • 5 replies
  • 1 view

Badge
When using the Reprojector transformer FME logs the transformation in the log file. Below is an example from a log file:   Reprojector: Using transformation `NAD27_to_NAD83_Canada_FME,Forward(Grid File Interpolation,EPSG:1313)' when reprojecting from LL-27 to EPSG:4326   Is there any way to ``capture`` the transformation used in an attribute or anything that can be written out?   Thanks,   CA

5 replies

Userlevel 2
Badge +17
Hi,

 

 

This may not be an ideal solution, but it's possible to collect only the messages which match with a specific condition using Python.

 

A PythonCaller with this script, for example, provides a functionality to collect every message which starts with "Reprojector:".

 

----- import fmeobjects   g_messageList = []   # Callback function to collect every message # which starts with "Reprojector:". def collectMessages(severity, message):     if message.startswith('Reprojector:'):         g_messageList.append(message)   class LogCallbackSetter(object):     def __init__(self):         # Set the callback function to log file object.         logger = fmeobjects.FMELogFile()         logger.setCallBack(collectMessages)              def input(self, feature):         self.pyoutput(feature)              def close(self):         pass

 

-----

 

 

Insert the PythonCaller before the Reprojector, then you can refer to the messages stored in "g_messageList" using Shutdown Python Script or another PythonCaller.

 

 

Example 1: This shutdown script writes the messages into a text file.

 

----- f = open('C:/tmp/messages.log', 'w') for msg in g_messageList:     f.write('%s\\n' % msg) f.close()

 

-----

 

 

Example 2: A PythonCaller with this script adds the messages to each feature as a list attribute. In this case, a FeatureHolder should be inserted between the Reprojector and this PythonCaller in order to complete collecting messages.

 

-----

 

import fmeobjects   class MessageExtractor(object):     def __init__(self):         pass              def input(self, feature):         feature.setAttribute('messages{}', g_messageList)         self.pyoutput(feature)              def close(self):         pass

 

-----

 

 

Takashi
Userlevel 2
Badge +17
Correction: There is no need to use a FeatureMerger in Example 2.

 

 

Example 3: This script can be used instead of Example 2.

 

-----

 

import fmeobjects   def setMessages(feature):     feature.setAttribute('messages{}', g_messageList) -----

 

 

Takashi
Userlevel 2
Badge +17
... Correction to the Correction (:-( Replace "FeatureMerger" with "FeatureHolder".
Userlevel 4
Badge +13
You could also just read the log file and extract the info, that is if you dont need it for the same translation.
Badge
Thanks Takashi.

 

 

That looks like it will do exactly what I need.

 

 

CA

Reply