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_UNDEFINED, FME_ATTR_BOOLEAN, FME_ATTR_INT8, FME_ATTR_UINT8, FME_ATTR_INT16, FME_ATTR_UINT16, FME_ATTR_INT32, FME_ATTR_UINT32, FME_ATTR_REAL32, FME_ATTR_REAL64, FME_ATTR_REAL80, FME_ATTR_STRING, FME_ATTR_ENCODED_STRING, FME_ATTR_INT64, FME_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.
(string)attrName
(int)attrType
(string, optional) - defaults to 'utf-8' if attrType is FME_ATTR_ENCODED_STRING and attrEncoding is not setattrEncoding
None
Raises:
- An exception is raised if an error occurred, e.g. when the conversion failed.FMEException
Yes, especially for dynamic writing workflows, very handy.