Python API: new setAttributeType() method for FMEFeature class


There already is a getAttributeType() method on the FMEFeature class, but it would also be nice to be able to set (=convert!) it, if this is feasible. This is useful if we want to enforce/maintain a certain character encoding (as discussed here), or if we want to convert an integer to a boolean, a numeric string to a real etc. etc.

The method could look like this:

setAttributeType(attrName, attrType, [attrEncoding])

Sets/converts an attribute into another type. Attribute type must be one of FME_ATTR_UNDEFINEDFME_ATTR_BOOLEANFME_ATTR_INT8FME_ATTR_UINT8FME_ATTR_INT16FME_ATTR_UINT16FME_ATTR_INT32FME_ATTR_UINT32FME_ATTR_REAL32FME_ATTR_REAL64FME_ATTR_REAL80FME_ATTR_STRINGFME_ATTR_ENCODED_STRINGFME_ATTR_INT64FME_ATTR_UINT64.
For FME_ATTR_ENCODED_STRING only, the user can specify a character encoding (e.g. 'iso-8895-1'). Otherwise, the encoding argument is ignored.

Parameters: 
  • attrName
     (string)
  • attrType
     (int)
  • attrEncoding
     (string, optional) - defaults to 'utf-8' if attrType is FME_ATTR_ENCODED_STRING and attrEncoding is not set 
Returns: 
None
Raises: 
  • FMEException
     - An exception is raised if an error occurred, e.g. when the conversion failed.

Yes, especially for dynamic writing workflows, very handy.