TableComposer (write ascii file)

From ObjectVision

Jump to: navigation, search

Configuration examples: TableComposer

Contents

Introduction

The TableComposer is a scriptblock using the Str StorageManager and a set of GeoDMS functions to write data from a delimited ASCII file.

The TableComposer is used to write data, use the TableChopper to read data from delimited ASCII file.

Example

container TableComposer
{
  unit<uint32> context := ExportDomain; // assume ExportDomain is a configured domain unit with two attributes as subitems: id & dist
  parameter<string> fieldlist            := 'id;Dist';
  parameter<string> fieldseparator := ';';
  parameter<string> filename         := '%LocalDataProjDir%/dist.csv';

   unit<uint32> field := range(uint32, 0,strcount(fieldlist, ';') +1)
   {
       attribute<string> name := ReadArray(FieldList, ., string, 0);
   }
  parameter<string> newline := '\n';
  parameter<string> header  := FieldList;
  attribute<string> body (context) := = AsList(
        +'string(context/' + field/name + ')',' + '+quote(fieldseparator)+' +'
     );
 
  parameter<string> result := header + newline + AsList(body, newline)
  ,  StorageName = "= filename"
  ,  StorageType   = "str";
}

Explanation

  • The context unit refers to the configured domain unit ExportDomain. All attributes to be exported need to be configured as direct subitems of this domain unit.
  • The fieldlist parameter configures the names of the attributes to be exported, semicolon delimited.
  • The fieldseparator parameter configures the separator used in the ASCII file between the fields. In most cases the semicolon is used.
  • The filename parameter configures the file name to be exported. In the example a placeholder for the file path is used.

When the TableComposer is used as a template to write multiple files, these first three items are often used as case parameters.

  • The field unit is the domain unit of the set of fields to be exported. In this example the cardinality of this domain is two, derived from the number of semicolons in the fieldlist string value. The field unit has one subitem: the name of the field (in this example: id and Dist). These names are read with the ReadArray function from the fieldlist string value.
  • A parameter newline is configured with as expression : \n. This code indicates a new line character and is used to split the contents of the resulting file over multiple lines.
  • The header parameter refers to the fieldlist parameter.
  • The body parameter will contain the actual primary data from the attributes to be exported. The contents of the attributes are concatenated, with the fieldseperator as delimiter (in the example a semicolon is used). With the AsList function, the concatenated values are combined to one string per element.
  • The result parameter combines the header, a new line and the body as a string parameter, separated by new lines. The StorageName and the StorageType properties are configured for the result parameter.

Optional extra lines

Other properties can also be exported to the delimited ASCII file. The example shows how to add an extra line between the header and the body with the metric of the attributes to be exported.

parameter<string> metric := =AsList(
       quote('[')+'+PropValue(
         ValuesUnit(context/' + field/name +')
         ,' + quote('metric') + '
      ) + ' + quote(']' )
      , '+' + quote(fieldseparator) + '+' 
   );

This parameter results in the metric of each exported attribute between square brackets, separated by the fieldseparator parameter.

To add this parameter to the resulting file, replace the configuration of the resulting parameter result by:

parameter<string> result := header + newline + metric + newline + AsList(body, newline )
,  StorageName = "=FileName"
,  StorageType = "str";
Personal tools