How to add an SDE for coverages layer to ArcMap


The code below demonstrates how to connect to an SDE for Coverages workspace, open a feature class in that workspace, and add it to ArcMap.

How to use

  1. Paste the code into your VBA Application.
  2. Change the workspace connection string and the feature class name to open.
  3. Call AddSDECoverageLayer.
[VBA]
Public Sub AddSDECoverageLayer()
    Dim pWorkFact As IWorkspaceFactory2
    Dim pFWorkspace As IFeatureWorkspace
    Dim pFClass As IFeatureClass
    Dim pFLayer As IFeatureLayer
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pAV As IActiveView
    
    'Open Feature Class
    Set pWorkFact = New SdeWorkspaceFactory
    Set pFWorkspace = pWorkFact.OpenFromString("server=luxor;instance=5156;user=avuser;password=avtest", 0)
    Set pFClass = pFWorkspace.OpenFeatureClass("cities")
    
    'Create new layer
    Set pFLayer = New FeatureLayer
    Set pFLayer.FeatureClass = pFClass
    pFLayer.Name = pFClass.AliasName
    
    'Add layer to map
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Set pAV = pMap
    pMap.AddLayer pFLayer
    pAV.Refresh
End Sub