This session gives a short introduction for the usage of Python scripts in FME Desktop processes. First it will be demonstrated how to compute buildings’ roof heights at certain ground points with the PythonCaller and an external Python package. The second demo shows how to persist the FME logfile and the runtime statistics into a central database via Python shutdown script for all those who do not have a FME Server at hand (for now).
See more presentations and videos at: www.safe.com/fmeuc
2. Introduction
! Employed at con terra GmbH
since 2009
! Spatial ETL Professional
Services
! FME Certified Trainer since
2010
! FME Certified Professional
since 2013
CONNECT. TRANSFORM. AUTOMATE.
3. What is Python?
Python is an interpreted, object-oriented, high-level
programming language with dynamic semantics. Its high-level
built in data structures, combined with dynamic typing and
dynamic binding, make it very attractive for Rapid Application
Development, as well as for use as a scripting or glue
language to connect existing components together. Python's
simple, easy to learn syntax emphasizes readability and
therefore reduces the cost of program maintenance. Python
supports modules and packages, which encourages program
modularity and code reuse. The Python interpreter and the
extensive standard library are available in source or binary
form without charge for all major platforms, and can be freely
distributed.
Source: https://www.python.org/doc/essays/blurb/
4. What is Python?
! Interpreted language
! With dynamic typing
! Extensive standard library
! Available without charge for all major platforms
! Freely distributable
Included in every FME Desktop and
FME Server
5. Why use Python?
! Easy to learn
! Very „googlable“
! Thousands of additional libraries available
! Fast
! Comprehensive usage e.g.
! Esri ArcGIS
! Blender
6. Hello World in Python
#HelloWorld.py
print("Hello World!")
>>>
Hello World!
>>>
7. Where to find Python in FME
! Startup and Shutdown
Python Script
" Navigator -> Workspace
Parameters -> Advanced
8. Demo 1 – Log Statistics
Live Demo
! Use a Shutdown Python Script to log statistic
information into a central file or database
! Access several FME runtime variables via the fme
module:
import
fme
runtime
=
fme.elapsedRunTime
>>>
12.3
9. Where to find Python in FME
! PythonCreator and PythonCaller transformers
" QuickAdd or Transformer Gallery
10. Demo 2 – Handle Dynamic
Attributes
! Handle features with an arbitrary number of
attributes
! Leave features with a defined attribute set
! Name
! ID
! Create Attribute Container Features for each
attribute with
! referenceFID
! AttributName
! AttributValue
Live Demo
11. Where to find Python in FME
! Scripted Python Parameter
! Navigator -> User Parameters -> Private
Parameters
! Has to end with a return statement
12. Change Default Interpreter
! Python Options (Custom Interpreter)
" Tools -> FME Options -> Runtime
! Why?
! Need other python version <2.7
! Utilize external python packages from a different
interpreter, e.g. arcpy
14. Advanced Usage - FMEObjects
! Make sure to select
„Install FME SDK“ on
installation of FME
! API documentation
! <FMEHOME>fmeobjects
pythonapidoc
15. Demo 3: WorkspaceRunner
! Use the Python WorkspaceRunner interface to run
your FME workspaces:
! run(workspace)
! withParameters(workspace, parameters)
! promptRun(workspace)
Live Demo
16. Advanced Usage – Plugin SDK
! Code your own native transformer with Python
! API documentation
! <FMEHOME>pluginbuilderpythonapidoc
! Sample (available in FME 2015 Beta builds)
! <FMEHOME>pluginbuildersamplespython
17. Thank You!
! Questions?
! For more information:
! Tino Miegel, t.miegel@conterra.de
@TMiegel
! con terra GmbH, fme@conterra.de
! Python and FME Basics
http://fmepedia.safe.com/articles/How_To/Python-
and-FME-Basics
CONNECT. TRANSFORM. AUTOMATE.