Build pyramids for raster data using VBA

Last Published: April 25, 2020


VBA code can loop through all the raster datasets in the specified workspace and build pyramids if necessary.


  1. Use a RasterWorkspaceFactory object to create a pointer to the location of the raster data.

    Dim pWorkspaceFactory As IWorkspaceFactory
    Dim pWorkspace As IWorkspace
    Dim pRasterDataset As IRasterDataset
    Dim pEnumDataset As IEnumDataset
    Set pWorkspaceFactory = New RasterWorkspaceFactory
    Set pWorkspace = pWorkspaceFactory.OpenFromFile("d:\data\raster", 0)

  2. Loop through all the raster datasets in the workspace and if pyramids are not present build them.

    Set pEnumDataset = pWorkspace.Datasets(esriDTRasterDataset)
    Set pRasterDataset = pEnumDataset.Next
    Do Until pRasterDataset Is Nothing
    'QI for IRasterPyramid from IRasterDataset
    Dim pRasterPyramid As IRasterPyramid
    Set pRasterPyramid = pRasterDataset
    If pRasterPyramid.Present = False Then
    MsgBox "Created Pyramid for " & pRasterDataset.CompleteName
    MsgBox "Pyramid already exists for " & pRasterDataset.CompleteName
    End If
    Set pRasterDataset = pEnumDataset.Next

Article ID:000002407

  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic