TclCaller
运行工具命令语言(Tcl) command and assigns its return value to an attribute.
The Tcl command can operate on the feature’s geometry and/or attributes, using any of the built-in Tcl functions provided by the Tcl language, as well as any of the FME-provided Tcl facilities.
See the Tcl language reference manual (www.tcl.tk) and theFME Tcl Variables and Functionssection below for details of the capabilities.
Common Tcl examples usage include:
- Trim spaces from an attribute:
FME_SetAttribute trimmedAttribute [string trim [FME_GetAttribute originalAttribute]]
- Replace all non-numeric characters with spaces in an attribute:
FME_SetAttribute anAttribute [regsub -all {[^0-9]} [FME_GetAttribute anAttribute] {}]
Note that in this case, the return value is the number of substitutions actually made.
- Match a regular expression against an attribute:
regexp {^[A-Za-z]$} [FME_GetAttribute anAttribute]
This regular expression tests if the entire value of the attribute consists only of alphabetic characters.
Note that when matching regular expressions, the return value will be 1 if the expression matched, and 0 otherwise.
- Log a custom message to the log window:
FME_LogMessage fme_inform {This is my message}
The recommended way to manipulate feature attributes is through the functions that are provided for this purpose:
FME_GetAttribute attrName
FME_SetAttribute attrName newVal
FME_CopyAttribute destAttrName srcAttrName
FME_RenameAttribute destAttrName srcAttrName
FME_UnsetAttributes attrName1 [attrName2 attrName3 ...]
Parameters
Output Feature Parameters
The Tcl expression which will be evaluated for each feature.The value of the expression will be stored in theDestination Attribute。
Additional code may also be provided in theSource Codeeditor.This code will be compiled once at the beginning of the translation and so offers a more efficient option than providing extensive code in theTcl Expressionparameter.
A Tcl source file can optionally be provided.The file will be read before the Tcl command is executed.This can be used to reference Tcl functions kept in a common external file.
The attribute which will store the result of theTcl Expressionparameter after it is evaluated.
Exposes any attributes that are created by the Tcl code being executed so they can be used by other transformers.
Copy Control
It is possible to create multiple copies of a feature using theNumber of Copies Tcl Expressionparameter.This expression is evaluated in the context of the input feature.It returns a number to indicate how many instances of the feature are to be processed using the transformer'sTcl Expression。
If specified, theCopy Number Attributewill hold the copy number of each output feature.For example, if 3 copies of an input feature are made, the output copies will have 0, 1, and 2, respectively, assigned to their copy number attribute.The Tcl expressions can examine this attribute to determine which output feature number it is working on.
FME Tcl Variables and Functions
Four Tcl global variables provide a gateway between an FME feature and the Tcl script: FME_FeatureType, FME_CoordSys, FME_AttrEncoding, and FME_AttrNameEncoding variables.In order to use these in a Tcl procedure, they must be declared as global;otherwise, the variables will be considered to be local and will not affect or interact with the FME feature upon which the function is run.To use them in a function, use a pattern like:
proc doSomething {
global FME_FeatureType
全球FME_CoordSys
#其他函数去. .。
}
This global variable defines the name of the character encoding in which Tcl assumes a feature's attributes are specified when working with FME_GetAttribute and FME_SetAttribute functions.As Tcl works internally with UTF-8, this means that it will convert attribute values from the given encoding to UTF-8 when getting the value of attribute with FME_GetAttribute function, and will convert values from UTF-8 to the given encoding when setting the attribute value using FME_SetAttribute function.
The value of this variable does not impact the setting or retrieval of attributes when character encoding is known, either on the retrieved attribute or as directed by the arguments to FME_GetAttribute or FME_SetAttribute.
The default attribute encoding is the same as the default character encoding of the system on which FME is executing, and might be overridden by Tcl's built-in "encoding system" command.A complete list of supported encodings may be obtained by executing the command "encoding names".
The variable may be set, read, or unset:
set FME_AttrEncoding iso8859-2
puts $FME_AttrEncoding
unset FME_AttrEncoding
If FME_AttrEncoding is unset, or is set to be an empty string, it reverts to the default system encoding.
This function is used to determine if an attribute is present on a feature.
The syntax for FME_AttributeExists is:
FME_AttributeExists
如果 attribute was present on the feature, the value 1 is returned;otherwise, 0 is returned.
This function is used to determine if the value of an attribute is null.
The syntax for FME_IsAttributeNull is:
FME_IsAttributeNull
如果 attribute has a null value, the value 1 is returned;otherwise, 0 is returned.
This function is used to retrieve the names of all feature attributes and return them as a Tcl list.
The syntax for FME_AttributeNames is:
FME_AttributeNames
This global variable defines the name of the character encoding in which Tcl assumes a feature's attributes' names are specified when working with FME_GetAttribute and FME_SetAttribute functions.As Tcl works internally with UTF-8, this means that it will convert attribute names from UTF-8 to the given encoding system, and use the converted name when referring to the actual feature's attributes.
The default attribute encoding is the same as the default character encoding of the system on which FME is executing, and might be overridden by Tcl's built-in "encoding system" command.A complete list of supported encodings may be obtained by executing the command "encoding names".
The variable may be set, read, or unset:
set FME_AttrNameEncoding iso8859-2
puts $FME_AttrNameEncoding
unset FME_AttrNameEncoding
If FME_AttrNameEncoding is unset, or is set to be an empty string, it reverts to the default system encoding.
This global variable is set up to mirror the coordinate system of the feature.As with the FME_FeatureType variable, it can be set, read, and unset:
set FME_CoordSys UTM10-83
puts $FME_CoordSys
unset FME_CoordSys
In any Tcl procedure invoked by TclCaller, the FME_Coordinates function can be used to read and write the coordinates of the feature.It provides several options, as listed below:
dimension (2|3)
Sets the dimension of the feature - either 2 or 3.
numCoords
Returns the number of coordinates in the feature.
resetCoords
Removes all the current coordinates from the feature.
Note: Calling resetCoords has no effect on the fme_geometry or fme_type attributes.These must be reset or readjusted explicitly by the script so the feature is not left in an inconsistent state.
getCoord (x|y|z)
Returns the coordinate value for the specified axis at the specified
addCoord
Adds the coordinate specified to the end of the feature's geometry.
geomType
Returns the geometry type of the feature - it will be one of the values allowed for theFME Geometry Modelattributes:
fme_point
fme_line
fme_polygon
fme_donut
fme_aggregate
fme_undefined
geomType
Sets the geometry type of the feature to the passed-in value.No sanity checking is done.It is important that this be done with care since setting an incorrect geometry type can later hinder FME.
This function is used to copy a feature attribute.该属性的原始内部数据存储类型使用此功能保留。高精度浮点值时,这可能是显著。
The syntax for FME_CopyAttribute is:
FME_CopyAttribute
如果功能不包含属性的名称使用oldName,则函数什么都不做。它不会创建一个新的空白值属性。
该功能用于解码作为部分所述已编码的字符串Substituting Strings in Mapping Files。所述函数的结果是输入参数的一个副本,其中取代的串序列转换回它们所代表的字符。
对于FME_DecodeText的语法是:
FME_DecodeText
该功能用于生成如在部分所述已被编码的字符串Substituting Strings in Mapping Files。所述函数的结果是输入参数的一个副本,其中的特殊字符转换成干净地穿过FME的文件分析器,并且可以以任何ANSI字符集表示取代的串序列。
对于FME_EncodeText的语法是:
FME_EncodeText
此功能用于从Tcl过程中调用任何FME功能。这允许标准FME功能反复在同一个功能调用。
对于FME_Execute的语法是:
FME_Execute
任何其余的参数传递给函数。例如,@Generalize函数被调用是这样的:
FME_Execute期广义道格拉斯10
并且这将完成仿佛@Generalize(道格拉斯,10)分别在映射文件别处调用的相同的效果。
如果要调用的函数使特征被删除,翻译将被中止。该@Generalize功能可以做到这一点,如果要素的总长度小于传入的公差值。
这个全局变量建立镜像特征的特征类型。与其他变量,它可以设置,读取和取消设置:
集FME_FeatureType“跑车”
看跌期权$ FME_FeatureType
此功能可用于从Tcl过程中获得的属性上的特征值。
对于FME_GetAttribute的语法是:
FME_GetAttribute
如果属性是不存在的功能,一个空字符串作为返回值。
该FME_LogMessage功能用于将消息写入FME日志文件。它可以以两种方式之一进行调用:
FME_LogMessage
要么
FME_LogMessage
当使用第一种形式,该消息数必须存在于FME安装文件夹下的子文件夹中的消息文件。其余参数是用来填充任何%0%1,...%正参数持有者在消息中。例如,如果该消息是:
3011,打开文件%0为模式%1
然后FME_LogMessage可以被称为是这样的:
FME_LogMessage fme_inform 3011 /tmp/cacher.txt读
在第二种形式中,该消息是直接输出到日志文件中。
此功能用于重命名功能属性。该属性的原始内部数据存储类型使用此功能保留。高精度浮点值时,这可能是显著。
对于FME_RenameAttribute的语法是:
FME_RenameAttribute
如果功能不包含属性的名称使用oldName,则函数什么都不做。它不会创建一个新的空白值属性。
该功能用于设置上的特征的属性的值。
对于FME_SetAttribute的语法是:
FME_SetAttribute [-notranscode]
如果指定了-notranscode选项时,Tcl变量的字节被逐字拷贝到所得到的属性中,代替从Tcl的内部UTF-8编码的目标字符编码字符编码转换。当Tcl变量已知包含在一个特定的字符编码,而不是UTF-8字符的通常的序列字节数组,这是有用的。
得到的属性,通常会附上字符编码信息。如果
该功能用于设置上的特征为null的属性的值。如果属性不存在,它将被创建。
对于FME_SetAttributeNull的语法是:
FME_SetAttributeNull
如果属性不存在,它将被创建,其类型为字符串。
这个函数生成的FME临时文件夹中的临时文件名。
文件名是保证是一个独特的,新的文件。
注:FME将创建具有给定名称的空文件;您必须删除它,当你完成。
对于FME_TempFilename的语法是:
FME_TempFilename [
如果不提供前缀和后缀,文件名会返回在FME临时文件夹中的任意唯一命名的文件。(有关,其中该文件夹所在位置的信息,请参阅Temporary Folder Determination。)
如果提供了一个前缀,然后被用作临时文件夹内的文件名的开头部分,而后缀被用作结束部分。典型地,该后缀用于附加的延伸部,并且在这种情况下,就必须另外包括句号“”
例如,这个调用:
FME_TempFilename光栅巴纽
将返回类似:
C:/文件和设置/用户名/本地设置/温度/ rastera05921.png
此功能用于从特征中去除一个或多个属性。
对于FME_UnsetAttributes的语法是:
FME_UnsetAttributes
如果该功能并没有包含任何列出的属性不会产生任何错误。FME_UnsetAttributes简单地忽略未指定的功能属性任何参数。
Usage Notes
Note that due to FME parser limitations, a Tcl expression cannot contain a % character.If a % character is needed, then the expression should be coded as a Tcl procedure and put into an external file to be 'source'd in.Further note that theStringFormattertransformer provides a convenient way to access the Tcl 'format' command thereby sidestepping the % character issue for this situation.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace.More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers.To access a menu of these options, clickbeside the applicable parameter.For more information, seeTransformer Parameter Menu Options。
Transformer Categories
Search FME Knowledge Center
Search for samples and information about this transformer on theFME Knowledge Center。