Some raster formats can contain multiple subdatasets inside a single file, for example the HDF format. This sample code shows how one can retrieve the HDF subdatasets using the IRasterDatasetJukebox interface.
How to use
- Reference libraries: ESRI.ArcGIS.DataSourcesRaster, ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.Geometry.
- Call this function from your code.
Public Function Subdataset(sPath As String, sHDFName As String) As IRasterDataset
'This example is used to query and save out the subdatasets of an HDF raster data.
'Open an HDF raster dataset
Dim pWorkspaceFact As IWorkspaceFactory
Dim pWs As IRasterWorkspace
Dim pRasterDS As IRasterDataset
Set pWorkspaceFact = New RasterWorkspaceFactory
Set pWs = pWorkspaceFact.OpenFromFile(sPath, 0)
Set pRasterDS = pWs.OpenRasterDataset(sHDFName)
'Use IRasterDatasetJukebox
Dim pHDFSubDataset As IRasterDataset
Dim pDatasetJukebox As IRasterDatasetJukebox
Set pDatasetJukebox = pRasterDS
Dim pSaveAs As ISaveAs
Dim DatasetCount As Integer, i As Integer
DatasetCount = pDatasetJukebox.SubdatasetCount
For i = 0 To DatasetCount - 1
'Get the ith sudataset as a raster dataset
pDatasetJukebox.subdataset = i
Set pHDFSubDataset = pDatasetJukebox
'Save the subdataset out
Set pSaveAs = pHDFSubDataset
pSaveAs.SaveAs "hdfsubimage" + i + ".img", pWs, "IMAGINE Image"
Next i
End Function