Adding expression columns to a table – Pitney Bowes MapXtreme User Manual

Page 169

Advertising
background image

Chapter 8: Working with Data

Table Metadata (TableInfo)

MapXtreme v7.1

176

Developer Guide

7, 0")

ti.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(Robinson))

' Note we do not need to (nor should we) add a column of type Key.
' Every table automatically contains a column named "MI_Key".

Dim table As Table = Session.Current.Catalog.CreateTable(ti)

End Sub

Adding Expression Columns to a Table

Use the MapInfo.Data.Table.AddColumns method to add expression columns to a table. The form of
AddColumns that takes a Columns object creates temporary columns based on expressions
comprised of functions, operators, literal values, and other columns on the table. All instances of
Column in the columns argument must have an expression string specified.

L

TableAddColumns is not supported for the following table types: Server, View, Seamless,
AdoNet, ResultSet, or Drilldown. MapXtreme checks for the table and throws an exception if
it encounters one of these table types.

VB example:

Public Shared Sub MapInfo_Data_TableAddColumns(ByVal miTable As Table)

Dim NewCols As Columns = New Columns
NewCols.Add(New Column("PopDensity1990", "Pop_1990 / _

MI_Area(Obj, 'sq mi', 'Spherical')"))

NewCols.Add(New Column("PopDensity2000", "Pop_2000 / _

MI_Area(Obj, 'sq mi', 'Spherical')"))

miTable.AddColumns(NewCols)

End Sub

The expression string “Pop_1990 / MI_Area(Obj, 'sq mi', 'Spherical')” represents
derived information that will be placed in the temporary column. It says ‘For each record divide
population by area in square miles to yield the population density.’ The SQL function MI_Area () in
the expression will derive the area from the geometry of the record.

Using the AddColumns method may offer performance improvements in desktop applications where
the join can be performed once, rather than on each subsequent access (as in the case of a view).

For more information and code examples, see the MapInfo.Data.Table.AddColumns class in the
Developer Reference Help system.

For more information on creating expressions, see

Chapter 10: Creating Expressions

.

Advertising