How to access a layer's underlying data


Summary 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 can include joined tables, and so on.

Accessing a layer's underlying data

The following are the two ways to access the underlying data in a layer.
  1. The following function returns the FeatureClass via IFeatureLayer:
[C#]
static IFeatureClass AccessLayersData(ILayer pLayer)
{
    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
    if (pFeatureLayer != null)
    {
        return pFeatureLayer.FeatureClass;
    }
    else
    {
        return null;
    }
}
[VB.NET]
Shared Function AccessLayersData(ByVal pLayer As ILayer) As IFeatureClass
Dim pFeatureLayer As IFeatureLayer = pLayer
If Not pFeatureLayer Is Nothing Then
    Return pFeatureLayer.FeatureClass
Else
    Return Nothing
End If
End Function
  1. The following function returns the DisplayTable by using the IDisplayTable interface: 
[C#]
static ITable AccessLayersDisplayTable(ILayer pLayer)
{
    IDisplayTable pDisplayTable = pLayer as IDisplayTable;
    if (pDisplayTable != null)
    {
        return pDisplayTable.DisplayTable;
    }
    else
    {
        return null;
    }
}
[VB.NET]
Shared Function AccessLayersDisplayTable(ByVal pLayer As ILayer) As ITable
Dim pDisplayTable As IDisplayTable = pLayer
If Not pDisplayTable Is Nothing Then
    Return pDisplayTable.DisplayTable
Else
    Return Nothing
End If
End Function
Note that IDisplayTable also includes methods for querying and selecting features. Use these methods to ensure proper behavior when dealing with joined data.






Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime