This sample code demonstrates how compute the statistics of a raster band collection using IMultivariateOp::BandCollectionStats.
How to use
- Paste the code into VBA.
- Make sure the Spatial Analyst extension is checked.
- Add reference to ESRI SpatialAnalyst Object Library.
- Add reference to ESRI GeoAnalyst Object Library.
- Modify output workspace and the output file name in the code.
- Call the sub ComputeBandCollectionStatistics from another sub or function and pass the raster band collection.
Sub ComputeBandCollectionStatistics(pRasBandColl As IRasterBandCollection)
'Calculates the statistics for a raster band collection.
On Error GoTo ErrorHandler
'Create a MultivariateObject
Dim pMultivariateOp As IMultivariateOp
Set pMultivariateOp = New RasterMultivariateOp
'Open a RasterWorkspace
Dim pWSF As IWorkspaceFactory
Dim pWS As IWorkspace
Dim pRasWS As IRasterWorkspace
Set pWSF = New RasterWorkspaceFactory
Set pWS = pWSF.OpenFromFile("C:\temp\myworkspace", 0)
Set pRasWS = pWS
'Set output workspace
Dim pEnv As IRasterAnalysisEnvironment
Set pEnv = pMultivariateOp
Set pEnv.OutWorkspace = pRasWS
'Compute band collection statistics
Dim sStatOutFileName As String
sStatOutFileName = "BandCollStats.txt"
pMultivariateOp.BandCollectionStats pRasBandColl, sStatOutFileName, True
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub