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

How to create a mosaic layer (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Displaying raster data > How to create a mosaic layer

How to create a mosaic layer

This topic shows how to create a mosaic layer from a mosaic dataset and add it to a map.

Creating a mosaic layer

Do the following steps to create a mosaic layer:
  1. Open a mosaic dataset.
  2. Create a mosaic layer.
  3. Add it to the map.

    See the following code example:
public static void AddMosaicLayerToMap(string fileGDBPath, string mosaicDatasetName,
    string mxdPath)
    //Open a mosaic dataset.
    Type factoryType=Type.GetTypeFromProgID(
    IWorkspaceFactory workspaceFact=(IWorkspaceFactory)Activator.CreateInstance
    IWorkspace workspace=workspaceFact.OpenFromFile(fileGDBPath, 0);
    IMosaicWorkspaceExtensionHelper mosaicWorkspaceExtensionHelper=new
    IMosaicWorkspaceExtension mosaicWorkspaceExtension =
    IMosaicDataset mosaicDataset=mosaicWorkspaceExtension.OpenMosaicDataset

    //Create a mosaic layer.
    IMosaicLayer mosaicLayer=new MosaicLayerClass();

    //Add it to the map.
    IMapDocument mapDoc=new MapDocumentClass();
    mapDoc.Open(mxdPath, "");
    IMap map=mapDoc.ActiveView.FocusMap;
    mapDoc.Save(false, false);
Public Shared Sub AddMosaicLayerToMap(ByVal fileGDBPath As String, ByVal mosaicDatasetName As String, ByVal mxdPath As String)
'Open a mosaic dataset.
Dim factoryType As Type=Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")
Dim workspaceFact As IWorkspaceFactory=Activator.CreateInstance(factoryType)
Dim workspace As IWorkspace=workspaceFact.OpenFromFile(fileGDBPath, 0)
Dim mosaicWorkspaceExtensionHelper As IMosaicWorkspaceExtensionHelper=New MosaicWorkspaceExtensionHelperClass()
Dim mosaicWorkspaceExtension As IMosaicWorkspaceExtension=mosaicWorkspaceExtensionHelper.FindExtension(workspace)
Dim mosaicDataset As IMosaicDataset=mosaicWorkspaceExtension.OpenMosaicDataset(mosaicDatasetName)

'Create a mosaic layer.
Dim mosaicLayer As New MosaicLayerClass()

'Add it to the map.
Dim mapDoc As IMapDocument=New MapDocumentClass()
mapDoc.Open(mxdPath, "")
Dim pmap As IMap=mapDoc.ActiveView.FocusMap
pmap.AddLayer(CType(mosaicLayer, ILayer))
mapDoc.Save(False, False)
End Sub

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 Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic
Engine Developer Kit Engine