Beyond 49x Transformers: Don't be afraid of (the) Python!

17
CONNECT. TRANSFORM. AUTOMATE. Beyond 49x Transformers: Don't be afraid of (the) Python! Tino Miegel Software Engineer

description

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

Transcript of Beyond 49x Transformers: Don't be afraid of (the) Python!

CONNECT. TRANSFORM. AUTOMATE.

Beyond 49x Transformers: Don't be afraid of (the) Python! Tino Miegel Software Engineer

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.

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/

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

Why use Python?

!  Easy to learn !  Very „googlable“ !  Thousands of additional libraries available !  Fast !  Comprehensive usage e.g.

!  Esri ArcGIS !  Blender

Hello World in Python

#HelloWorld.py

print("Hello World!")

>>> Hello World! >>>

Where to find Python in FME

!  Startup and Shutdown Python Script " Navigator -> Workspace

Parameters -> Advanced

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  

Where to find Python in FME

!  PythonCreator and PythonCaller transformers " QuickAdd or Transformer Gallery

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

Where to find Python in FME

!  Scripted Python Parameter !  Navigator -> User Parameters -> Private

Parameters !  Has to end with a return statement

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

Order of Evaluation

1.  Scripted Python Parameter 2.  Startup Python Script 3.  Workspace logic

1.  Reader 2.  Transformer chain 3.  Writer

4.  Shutdown Python Script

Advanced Usage - FMEObjects

!  Make sure to select „Install FME SDK“ on installation of FME

!  API documentation !  <FMEHOME>\fmeobjects

\python\apidoc

Demo 3: WorkspaceRunner

!  Use the Python WorkspaceRunner interface to run your FME workspaces: !  run(workspace)  !  withParameters(workspace, parameters) !  promptRun(workspace) Live Demo

Advanced Usage – Plugin SDK

!  Code your own native transformer with Python !  API documentation

!  <FMEHOME>\pluginbuilder\python\apidoc !  Sample (available in FME 2015 Beta builds)

!  <FMEHOME>\pluginbuilder\samples\python

Thank You!

!  Questions?

!  For more information: !  Tino Miegel, [email protected]

@TMiegel !  con terra GmbH, [email protected]

!  Python and FME Basics http://fmepedia.safe.com/articles/How_To/Python-and-FME-Basics

CONNECT. TRANSFORM. AUTOMATE.