Adds a new Index to the IndexCollection and creates a new physical index on disk.

Namespace:  ESRI.ArcGISExplorer.Data

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public void Add(
	Index index
)
Visual Basic (Declaration)
Public Sub Add ( _
	index As Index _
)

Parameters

index
Type: ESRI.ArcGISExplorer.Data..::.Index

An Index object which represents a internally-managed table allowing any Row in a Table to be retrieved quickly.

Remarks

Indexes can not be added for data stored in an ArcSDE geodatabase.

The two most common reasons for the Add method to fail are:

  • A schema lock cannot be acquired on the Table, for example the feature class is currently being edited in ArcGIS Desktop.
  • A shapefile is contained in directory with read-only permissions.

For spatially enabled tables, it is possible to create a new spatial index against the Column storing the geometries (usually the Shape column) but the ArcGIS Explorer API does not provide any mechanism to specify the grid sizes for this index.

Examples

The code below, which would be suitable for a dockable window add-in, presents a scenario where the user can build an index against any column in the selected feature layer. The Add method is used to add the Index to the IndexCollection, thereby creating it on disk.
CopyC#
//Get first selected map item
MapItem firstSelectedMapItem = ESRI.ArcGISExplorer.Application.Application.SelectedItems[0];

//Exit if either no selection or if selection is not a FeatureLayer
if ((firstSelectedMapItem == null) || !(firstSelectedMapItem is FeatureLayer))
  return;

//Get selected feature layer
FeatureLayer someFeatureLayer = firstSelectedMapItem as FeatureLayer;

//Get the Table
Table someTable = someFeatureLayer.Table;

//Indexes cannot be created for ArcSDE data so check for this.
object dataContainer = someTable.RootDataContainer;
if (dataContainer is Geodatabase)
{
  Geodatabase gdb = dataContainer as Geodatabase;
  if (gdb.Type == GeodatabaseType.ArcSDE)
    return;
} 

//Get the IndexCollection for the Table
IndexCollection indexes = someTable.Indexes;

//Simulated code to represent a user selecting an item from a list of column names
System.Windows.Forms.ListBox columnsListBox = new System.Windows.Forms.ListBox();
string columnName = columnsListBox.SelectedItem.ToString();

//Check whether the column already participates in any indexes
if (indexes.FindIndexesByColumnName(columnName).Count == 0)
{
  try
  {
    //Create the new index
    string indexName = string.Format("idx_ {0}",columnName);
    Index newIndex = new Index(indexName, columnName); //if shapefile the index name parameter will be ignored
    //Add it to the IndexCollection
    indexes.Add(newIndex);
  }
  catch (Exception ex)
  {
    System.Windows.Forms.MessageBox.Show(string.Format("It was not possible to build an index for the {0} column: {1}",columnName, ex.Message));
  }
}
CopyVB.NET
'Get first selected map item
Dim firstSelectedMapItem As MapItem = ESRI.ArcGISExplorer.Application.Application.SelectedItems.Item(0)

'Exit if either no selection or if selection is not a FeatureLayer
If firstSelectedMapItem Is Nothing Or Not TypeOf firstSelectedMapItem Is FeatureLayer Then
  Return
End If

'Get selected feature layer
Dim someFeatureLayer As FeatureLayer = DirectCast(firstSelectedMapItem, FeatureLayer)

'Get the Table
Dim someTable As Table = someFeatureLayer.Table

'Indexes cannot be created for ArcSDE data so check for this.
Dim dataContainer As Object = someTable.RootDataContainer
If TypeOf dataContainer Is Geodatabase Then
  Dim gdb As Geodatabase = DirectCast(dataContainer, Geodatabase)
  If gdb.Type = GeodatabaseType.ArcSDE Then
    Return
  End If
End If

'Get the IndexCollection for the Table
Dim indexes As IndexCollection = someTable.Indexes

'Simulated code to represent a user selecting an item from a list of column names
Dim columnsListBox As System.Windows.Forms.ListBox = New System.Windows.Forms.ListBox()
Dim columnName As String = columnsListBox.SelectedItem.ToString()

'Check whether the column already participates in any indexes
If indexes.FindIndexesByColumnName(columnName).Count = 0 Then
  Try
    'Create the new index
    Dim indexName As String = String.Format("idx_ 0", columnName)
    Dim newIndex As Index = New Index(indexName, columnName) 'if shapefile the index name parameter will be ignored
    'Add it to the IndexCollection
    indexes.Add(newIndex)
  Catch ex As Exception
    System.Windows.Forms.MessageBox.Show(String.Format("It was not possible to build an index for the 0 column: 1", columnName, ex.Message))
  End Try
End If

See Also