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 saw a great interface to FME with Python there

What you guys are doing with it? I want ideas.

share|improve this question
add comment

5 Answers

up vote 8 down vote accepted

I'm just getting started with FME, and am using a shutdown script to copy my target FGDB to another location and to save out the log file:

import distutils.dir_util, shutil, os, time, locale

src = 'C:/Testing/FME/TPW/Third_Party_Wells.gdb'
dst = '//share/Data Services/GIS Data/Data/Third Party Wells/Third_Party_Wells.gdb'

distutils.dir_util.copy_tree(src, dst)

logfile = FME_LogFileName
shutil.copy(logfile, 'C:/temp/PRD_' + os.path.basename(logfile)[:-4] + '_' + time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime()) + '.log')

# Get features written counts
shl_count = str(FME_FeaturesWritten['ThirdPartyWellsSurface'])
bhl_count = str(FME_FeaturesWritten['ThirdPartyWellsBottom'])
lat_count = str(FME_FeaturesWritten['ThirdPartyWellsLaterals'])

# Write out features written counts to log
fm_log = open('C:/temp/PRD_Counts.log','a')
fm_log.write(time.strftime('%m/%d/%Y %I:%M:%S', time.localtime()) + ',' + shl_count + ',' + bhl_count + ',' + lat_count + ',' + str(FME_TotalFeaturesWritten) + '\n')

That's pretty basic, but there really is no limit I don't think. There are tons of ideas here as well.

EDIT: Added in code to get numbers of features written and push those out to CSV log file.

share|improve this answer
    
Sweet idea ! Thanks –  Philippe Lavoie Feb 3 '11 at 13:16
add comment

Have a look at Oliver's Python Corner. There's a ton of things you can do using Python in FME.

I often use the PythonCaller to make some attributemanipulations inside 1 transformer rather than using 10 different transformers (if elif elif else ..)

You can have very basic PythonCallers like this example which will convert all your attributes to uppercase values:

def upperAll(feature):
    for att in feature.getAttributeList():
        feature.setAttribute(att,feature.gettAttribute(att).upper())

I also use the PythonCaller to send emails in case of failure or interact with an FTP Server etc .. There are really no limits

Have fun and happy FMEing

Jeff

share|improve this answer
    
Oooohhhhh...I like the sound of this...never thought about using a PythonCaller that way! –  Chad Cooper Feb 7 '11 at 20:00
    
Extra question on this one... what program do you have to give access to port 25 (firewall) in order for the email to work? I struggled with this for a couple of weeks and then finally gave up. –  blord-castillo Apr 2 '12 at 10:46
add comment

Examples:

Custom Log

import os.path, time, os, datetime, main , sys, pyfme,shutil from pyfme import *

class expFeature(object): def init(self): self.logger = pyfme.FMELogfile() pass

def close(self):
        try:
            #folders creation
            os.makedirs(param_folder)
            #Log creation
            logFile = param_folder + timecreated +".log"
            FILE = open(logFile,"w")
            log=FMELogfile(logFile)
            log.log("Bla bla bla")

And Send Email:

message = MIMEMultipart()
message["From"]    = email_from
message["To"]      = email_to
message['Date']    = formatdate(localtime=True)
message["Subject"] = subject
message.attach( MIMEText(html, 'html') )
attachment = MIMEBase('application', "octet-stream")
attachment.set_payload( open(FileLog,"rb").read() )
Encoders.encode_base64(attachment)
attachment.add_header('Content-Disposition', 'attachment; filename="%s"' %       os.path.basename(FileLog))
message.attach(attachment)

smtp = smtplib.SMTP(smtpServer) 
smtp.sendmail(email_from, email_to, message.as_string())         
print "Successfully sent email"
smtp.close() 
share|improve this answer
add comment

Good example above: I'm currently writing an article for our knowledgebase called FMEPedia here: Python and FME Basics.

This includes some simple examples such as deleting a file before running a workspace with a start up script, manipulating features with a PythonCaller etc. There are also links to more complex examples.

Ken Bragg Safe Software

share|improve this answer
add comment

With FME Server 2012, it's possible to send an email automatically when the workbench finished.You don't need python for send an email. :) FME Server Configuration

share|improve this answer
    
But you do need FME Server. Much cheaper to use Python. –  Fezter Mar 2 at 22:48
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.