12
Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

Embed Size (px)

Citation preview

Page 1: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

Sep. 21-22, 2006v

Tcl and Mapping Files – Best PracticesPeter Laulund, National Survey and Cadastre, Denmark

FME Worldwide User Conference - Vancouver

Page 2: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 2

Agenda

Tcl plays a big role in my mapping files. It is used for batch processing dynamically writing part of the mapping file processing the features and pre and post processing the data.

In this presentation I will discuss different aspects of how I structure a mapping file, with special focus on TCL. 

Page 3: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 3

Demo Mapping File Structure

FmeViewer game.csv

PARAM.FME

MAIN.FME

SPIL.FMI

fme.exe

MAIN.FME

INIT.FMI

MAIN.FME

FLYT.FMI *.ffs

fme.exe

Page 4: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 4

Structure of Mapping File Complex

Build by modules Placed in a common structure ‘Metadata’ in tables ‘Transformation’ attributes with

common prefix ex. kms_ kms_feature_type, kms_feature_code

Page 5: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 5

Different Levels of Tcl in FME

FME_BEGIN/END_TCL

fmeObjects tcl

INCLUDE [ script ]

Tcl2 source … Tcl2( proc )

fme.exe script.tcl

Page 6: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 6

Command Line

Syntaks - Fme.exe script.tcl Used for batch processing and

chaining together more than one process together

proc spil::flyt {} { global header fil

lappend cmd fme.exe MAIN.FME --Modul FLYT …….. lappend cmd --from [ FME_GetAttribute from ] lappend cmd --to [ FME_GetAttribute to ] eval exec $cmd 2> NUL: eval exec fmeview.exe /ownffs ${::gsParth2App}spil/$fil &}

proc spil::flyt {} { global header fil

lappend cmd fme.exe MAIN.FME --Modul FLYT …….. lappend cmd --from [ FME_GetAttribute from ] lappend cmd --to [ FME_GetAttribute to ] eval exec $cmd 2> NUL: eval exec fmeview.exe /ownffs ${::gsParth2App}spil/$fil &}

Page 7: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 7

INCLUDE [ .. script …]

Used to initiate the mapping file putting in MACRO <name> <value> pairs Lookup tables _DEF lines INCLUDING Factory’s or modules

INCLUDE [ switch -- $(Modul) { \

SPIL { puts "MACRO SourceFormat TEXTLINE" } \ INIT { puts "MACRO DestFormat FFS" } \ FLYT { puts "MACRO SourceFormat FFS" ; \ puts "MACRO DestFormat FFS" }}]

INCLUDE [ switch -- $(Modul) { \

SPIL { puts "MACRO SourceFormat TEXTLINE" } \ INIT { puts "MACRO DestFormat FFS" } \ FLYT { puts "MACRO SourceFormat FFS" ; \ puts "MACRO DestFormat FFS" }}]

Page 8: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 8

Tcl2 and @Tcl()

Work on the feature and ‘dataset’ level Has a global namespace

proc init::tilpasBrik {id} {

variable brikPos

FME_Execute Bounds xmin xmax ymin ymax FME_Execute Offset [expr $brikPos($id,x) - [FME_GetAttribute xmax] + … ] [expr $brikPos($id,y) - [FME_GetAttribute ymin] + … ] FME_UnsetAttributes xmin xmax ymin ymax skak_font fme_text_size fme_text_string}

proc init::tilpasBrik {id} {

variable brikPos

FME_Execute Bounds xmin xmax ymin ymax FME_Execute Offset [expr $brikPos($id,x) - [FME_GetAttribute xmax] + … ] [expr $brikPos($id,y) - [FME_GetAttribute ymin] + … ] FME_UnsetAttributes xmin xmax ymin ymax skak_font fme_text_size fme_text_string}

Tcl2 set gsParth2App $(mf_root) ; \ set gx0 $(x0); set gy0 $(y0); set gdxy $(dxy) ; \ source $(FME_MF_DIR_UNIX)/TCL/$(Modul).TCL ;

Tcl2 set gsParth2App $(mf_root) ; \ set gx0 $(x0); set gy0 $(y0); set gdxy $(dxy) ; \ source $(FME_MF_DIR_UNIX)/TCL/$(Modul).TCL ;

Page 9: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 9

Tcl

Log fileFelter

R. Piepeline W. Piepeline Writer

Tcl script

Reader

Page 10: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 10

FME_BEGIN/END_TCL

Used to pre- and post-processing the translation creating directory’s and copying documentation

to dataset zipping the dataset emailing copying the data to a FTP server logging the translation to a database or file

Page 11: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 11

Conclusion

Tcl works on many levels in the mapping file

It gives a dynamic dimension to mapping files

You can manipulate both attributes and geometry

The global namespace means that Tcl is more than just a new function

It can integrate FME with other programs

Page 12: Sep. 21-22, 2006 v Tcl and Mapping Files – Best Practices Peter Laulund, National Survey and Cadastre, Denmark FME Worldwide User Conference - Vancouver

FME and TCL 12

Links

http://wiki.tcl.tk/ Wiki about tcl and tk with many examples

http://jamesthornton.com/tcl/8.4.2/ tcl and tk documentation