English

How To: Add a raster catalog to ArcMap using VBA and ArcObjects

Summary

This document shows how to programmatically add a raster catalog to ArcMap.

Procedure

  1. Open ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Note:
    Code in the Project's ThisDocument code module will run only in the current map document. To store the code in all map documents, open the Normal.mxt ThisDocument code module instead.

  4. Paste the following code into the code module.

    Code:
    Sub AddRasterCatalog()
    Dim pWF As IWorkspaceFactory
    Set pWF = New ArcInfoWorkspaceFactory
    Dim pWS As IFeatureWorkspace

    'Open the INFO table.
    Set pWS = pWF.OpenFromFile("c:\temp", 0)
    Dim pTable As ITable
    Set pTable = pWS.OpenTable("MyTable")

    'Create and Update the Raster Table
    Dim pRT As IRasterCatalogTable
    Set pRT = New RasterCatalogTable
    Set pRT.Table = pTable
    pRT.Update

    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap

    'Create the Raster Layer and add it to ArcMap
    Dim pRLayer As IRasterCatalogLayer
    Set pRLayer = New RasterCatalogLayer
    pRLayer.Create pRT
    pRLayer.DisplayRasters = True
    pMap.AddLayer pRLayer
    pRLayer.Draw esridpgeograpy, pDoc.ActiveView.ScreenDisplay, Nothing
    pDoc.ActiveView.Refresh
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.