How to access a layer's underlying data


This document was published with and applies to ArcGIS 9.3.
A 10 version also exists. A 9.2 version also exists.
Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime

Accessing a layer's underlying data

Layers are often an entry point to accessing data. While there are some special layer types with specific methods to access data, the common layer types implement the interfaces IFeatureLayer and IDisplayTable. IFeatureLayer provides access to the base FeatureClass that the layer is based on, while IDisplayTable provides access to the DisplayTable, which may include joined tables, and so on. The following example shows how to access the FeatureClass via IFeatureLayer:
 

[Java]
static IFeatureClass accessLayersData(ILayer layer)throws Exception
{
    IFeatureLayer featureLayer = (IFeatureLayer)layer;
    if (featureLayer != null)
        return featureLayer.getFeatureClass();
    else
        return null;

}
The next example demonstrates how to access the DisplayTable by using the IDisplayTable interface. Note that IDisplayTable also includes methods for querying and selecting features. Use these methods to ensure proper behavior when dealing with joined data. See the following:
 

[Java]
static ITable accessLayersDisplayTable(ILayer layer)throws Exception
{
    IDisplayTable displayTable = (IDisplayTable)layer;
    if (displayTable != null)
        return displayTable.getDisplayTable();
    else
        return null;

}