This document is archived and information here might be outdated.  Recommended version.


How to access a layer's underlying data (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Working with layers and renderers > How to access a layer's underlying data (ArcObjects .NET 10.6 SDK)

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;
    }
    ArcGIS Desktop
    {
        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
    ArcGIS Desktop
    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;
    }
    ArcGIS Desktop
    {
        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
    ArcGIS Desktop
    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
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine