English

How To: Build pyramids for raster data using VBA

Summary

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

Procedure

  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
    pRasterPyramid.Create
    MsgBox "Created Pyramid for " & pRasterDataset.CompleteName
    Else
    MsgBox "Pyramid already exists for " & pRasterDataset.CompleteName
    End If
    Set pRasterDataset = pEnumDataset.Next
    Loop