This document is archived and information here might be outdated.  Recommended version.


How to save a mosaic dataset to a raster dataset (ArcObjects .NET 10.4 SDK)

How to save a mosaic dataset to a raster dataset


Summary
A mosaic dataset represents a mosaic view of a collection of individual rasters. The sample provide an example if you want to save the mosaic dataset to a single raster dataset in a file format or a GDB raster.

Following example reads a mosaic dataset in a File geodatabase, and save it out to a raster dataset in the same geodatabase. you can also save it to any file format by changing the workspace and format string.
[C#]
//Open a File geodatabase workspace
IWorkspaceFactory workspaceFactory=new FileGDBWorkspaceFactoryClass();
IWorkspace wsGDB=workspaceFactory.OpenFromFile(@"c:\filegeodatabase.gdb", 0);

//Open a mosaic dataset using the MosaicWorkspaceExtensionHelper class
IMosaicWorkspaceExtensionHelper mosaicHelper=new
    MosaicWorkspaceExtensionHelperClass();
IMosaicWorkspaceExtension mosaicWs=mosaicHelper.FindExtension(wsGDB);
IMosaicDataset mosaic=mosaicWs.OpenMosaicDataset("myMosaicDataset");

//a mosaic dataset is a special type of function raster dataset
IFunctionRasterDataset functionDS=(IFunctionRasterDataset)mosaic;

//Use ISaveAs to write out a raster dataset. The size of a raster dataset can be exported from
//a mosaic is defined in the default properties of a mosaic dataset. Make sure the output size 
//is within the limit.
ISaveAs rasterSaveAs=(ISaveAs)functionDS;
rasterSaveAs.SaveAs("outRaster", wsGDB, "GDB");
[VB.NET]
'Open a File geodatabase workspace
Dim workspaceFactory As IWorkspaceFactory=New FileGDBWorkspaceFactory
Dim wsGDB As IWorkspace=workspaceFactory.OpenFromFile("c:\filegeodatabase.gdb", 0);

'Use MosaicWorkspaceExtensionHelper class to open a mosaic dataset
Dim mosaicHelper As IMosaicWorkspaceExtensionHelper=New MosaicWorkspaceExtensionHelperi
Dm mosaicWs As IMosaicWorkspaceExtension=mosaicHelper.FindExtension(wsGDB)
Dim mosaic As IMosaicDataset=mosaicWs.OpenMosaicDataset("myMosaicDataset")

'Mosaic dataset is a type of function raster dataset
Dim functionDS=CType(mosaic, IFunctionRasterDataset)

'Use ISaveAs to write out a raster dataset. The size of a raster dataset can be exported from
'a mosaic is defined in the default properties of a mosaic dataset. Make sure the output size
'is within the limit.

Dim rasterSaveAs=CType(functionDS, ISaveAs)
rasterSaveAs.SaveAs("outRaster", wsGDB, "GDB")






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic
ArcGIS for Desktop Basic ArcGIS for Desktop Standard
ArcGIS for Desktop Standard ArcGIS for Desktop Advanced
ArcGIS for Desktop Advanced Engine
Engine Developer Kit