Class DBFWriterSetup

java.lang.Object
ca.spatial.table.DBFWriterSetup

public class DBFWriterSetup extends Object
This class provides a wizard to create and modify the schema that is used to write out the DBF file. The DBFWriter class can use the specification created by this class to transform and format a new output dataset based on the original source.

Use the constructor and the add and drop column methods to add or remove columns from the specification. Once the specification has been adjusted use the getDefinitions() method to retrieve the specification list. This can then be used with the DBFWriter.export(String, AttributeStore, ArrayList, int[], int, String, Observer) method to create a transformed copy of the dataset. For more precise control use the getWriter(java.lang.String) method to create a DBFWriter object, and write out selected rows using the DBFWriter.write(int, int) method.

See the DBFColumnSpec object for a description of the parameters for a column specification.

  • Constructor Details

    • DBFWriterSetup

      public DBFWriterSetup(AttributeStore source)
      Provide a AttributeStore data source. All columns will be added to the initial list.
      Parameters:
      source - the data source
    • DBFWriterSetup

      public DBFWriterSetup(AttributeStore source, int[] columns)
      Provide a AttributeStore data source and a list of column numbers. Only the columns in the input array will be added to the initial list.
      Parameters:
      source - the data source
      columns - an array of column numbers to include
    • DBFWriterSetup

      public DBFWriterSetup(AttributeStore source, String[] columns, String[] aliases)
      Provide a AttributeStore data source and a list of column names and aliases. Only the columns in the input array will be added to the initial list, along with the aliases.
      Parameters:
      source - the data source
      columns - An array of column names to include. These may be column names or expression.
      aliases - An array of names to use as column aliases
  • Method Details

    • getDefinitions

      public ArrayList<DBFColumnSpec> getDefinitions()
      Get the list of column definitions
    • getColumn

      public DBFColumnSpec getColumn(String alias)
      Get the column specification matching this alias
      Parameters:
      alias - The column name to match
    • keepColumns

      public DBFWriterSetup keepColumns(String[] columns)
      Prune out the list of definitions to keep only the definitions whose aliases exactly match the list of columns that are passed in.
      Parameters:
      columns - a list of names to keep. These are tested for exact matches with the aliases in the column specifications.
    • dropColumn

      public DBFWriterSetup dropColumn(String column)
      Drop all columns whose aliases exactly match with the column name.
    • dropColumns

      public DBFWriterSetup dropColumns(String[] columns)
      Drop all columns whose aliases exactly match with any of the column names that are provided
      Parameters:
      columns - an array of names that are tested against the aliases in the specification list.
    • dropColumns

      public DBFWriterSetup dropColumns()
      Drop all column specifications from the list
    • addColumn

      public DBFWriterSetup addColumn(String spec)
      Add a single specification to the list. The specification is parsed from the string as a comma separated list of name, alias, width, precision, type

      See the DBFColumnSpec object for a description of the parameters for a column specification.

      Parameters:
      spec - a string have a comma separated list of name, alias, width, precision, type
    • addColumns

      public DBFWriterSetup addColumns(String[] specs)
      Add a list of specifications. The specifications are parsed from each string as a comma separated list of name, alias, width, precision, type

      See the DBFColumnSpec object for a description of the parameters for a column specification.

      Parameters:
      specs - a array of strings have a comma separated list of name, alias, width, precision, type
    • addColumn

      public DBFWriterSetup addColumn(String name, String alias, String type, int width, int dec)
      Add a single specification to the list.

      See the DBFColumnSpec object for a description of the parameters for a column specification.

      Parameters:
      name - the column name or expression
      alias - the alias for the column
      width - the column width
      dec - the number of decimals of precision
      type - the data type
    • addColumn

      public DBFWriterSetup addColumn(DBFColumnSpec spec)
      Add a single specification to the list.
      Parameters:
      spec - The column specification
    • getSpec

      public static DBFColumnSpec getSpec(AttributeFormat f)
      Create a column specification from an AttributeFormat object
    • getSpec

      public static DBFColumnSpec getSpec(Expression ex)
      Create a column specification from an Expression object
    • addColumn

      public DBFWriterSetup addColumn(AttributeFormat f)
      Add a column based on an attribute format
    • addColumn

      public DBFWriterSetup addColumn(AttributeFormat f, String shortTableName)
      Add a column based on an attribute format and a short table name. This is used to disambiguate duplicate column names formed as a result of joins.
    • getWriter

      public DBFWriter getWriter(String filename) throws IOException, ParseException
      Get a DBFWriter object based on the current set of column specifications
      Throws:
      IOException
      ParseException