AggregateTable()

Summary

Groups records in a view and computes summary statistics.

Syntax

rslt = AggregateTable(string new_view, string input_view_set, string output_type, string output_filename, string aggregation_field_name, array output_fields, array options)

Argument Contents
new_view The desired name for the result view
input_view_set The name of the input view and selection set
output_type The type of file to create ("CSV", "dBASE", "FFA" or "FFB") or "MEM" to save to a memory table
output_filename The name of the output file
aggregation_field_name The field on which records are grouped
output_fields An array containing one element for each field in the output table. Each element is an array of three items, that indicates the statistic calculated, as shown below
Item Type Contents
1 String Name of a field in the input view
2 String Statistic: "SUM", "MIN", "MAX", "DOM" (DOMINANT), "AVG" (AVERAGE), "STDDEV" or "COUNT"
3 (optional) String Name of a field in the input view used in computing averages. Necessary only for averages; must be a numeric field
Option Type Contents
Missing as zero N/A No contents necessary. This option causes all missing numeric values in the input view to be treated as zeros in sum, average, min or max calculations

Returns

A string containing the name of the view of the new table.

Notes

  • The file types include FFA for fixed-format text (ASCII), FFB for fixed-format binary, and CSV for comma-separated text (values).

  • If MEM is specified, the output filename is ignored.

  • AggregateTable() takes the records in a view or selection set and groups them together based on the value of one of the fields in the view. Then, for each group, it computes the sum, min, max, dominant, or average value for any data field. The results are written to a new table file, and the table is opened to create a view.

  • For numeric fields, you must use the sum, min, max, or average statistic. By default, any missing numeric values in the input view result in a missing value.

  • For string-type input data fields, only the dominant mode is supported. This currently evaluates to the first value encountered for the chosen field.

  • The average statistic calculates weighted averages, and requires a weighting field (this is the optional third field listed above.)

  • The output table has one record for each value of the aggregation field.

  • The output table has one column containing the group value, plus one column for each statistic that is requested in output_fields.

  • The output_fields array cannot be null.

  • The name, width and number of decimals for all output fields are automatically determined. The name is determined as follows:

Statistic Prefix Example
Sum (none) Income
Min Low Low Income
Max High High Income
Average Avg Avg Income
  • If you are summing on a join to an aggregated table, the prefix "Total " will be added to fields whose names start with "High", "Low", "Avg", "N ", or "N_" to distinguish between one and more than one level of aggregation.

Example

// Aggregate a table and write the results to a memory table
flds = {{"Population","sum", },
{"Population","min", },
{"Population","max", },
{"HH Income","average", "Households"}}
rslt = AggregateTable("", "County Data|Selection", "MEM", "", "State ID", flds, null)

Error Codes

Error Type Meaning
Error The output_fields array does not have the correct format; one or more of the following input variables is null or invalid: new_view, output_type, output_filename, aggregation_field, output_fields; or a file I/O error occurred (e.g., out of disk space).
NotFound The input view or set does not exist, or the input aggregation field or one of the data fields does not exist.

See Also

Function Summary
ApplyOverlayTable() Computes attribute values for a view using information from an overlay table
ColumnAggregate() Performs a geographic overlay between two layers and aggregates tabular data
ComputeIntersectionPercentages() Intersects two or more area or line layers and computes the intersection percentages
MergeByValue() Creates districts by merging areas from a geographic file, based on the value of a field
SelfAggregate() Groups the records in a view, based on a field, to create an aggregate view