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


How to create a mosaic layer (ArcObjects .NET 10.6 SDK)
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 (ArcObjects .NET 10.6 SDK)

How to create a mosaic layer


Summary
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:
[C#]
public static void AddMosaicLayerToMap(string fileGDBPath, string mosaicDatasetName,
    string mxdPath)
{
    //Open a mosaic dataset.
    Type factoryType=Type.GetTypeFromProgID(
        "esriDataSourcesGDB.FileGDBWorkspaceFactory");
    IWorkspaceFactory workspaceFact=(IWorkspaceFactory)Activator.CreateInstance
        (factoryType);
    IWorkspace workspace=workspaceFact.OpenFromFile(fileGDBPath, 0);
    IMosaicWorkspaceExtensionHelper mosaicWorkspaceExtensionHelper=new
        MosaicWorkspaceExtensionHelperClass();
    IMosaicWorkspaceExtension mosaicWorkspaceExtension =
        mosaicWorkspaceExtensionHelper.FindExtension(workspace);
    IMosaicDataset mosaicDataset=mosaicWorkspaceExtension.OpenMosaicDataset
        (mosaicDatasetName);

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

    //Add it to the map.
    IMapDocument mapDoc=new MapDocumentClass();
    mapDoc.Open(mxdPath, "");
    IMap map=mapDoc.ActiveView.FocusMap;
    map.AddLayer((ILayer)mosaicLayer);
    mapDoc.Save(false, false);
    mapDoc.Close();
}
[VB.NET]
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()
mosaicLayer.CreateFromMosaicDataset(mosaicDataset)

'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)
mapDoc.Close()
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