Creating a mosaic layer
Do the following steps to create a mosaic layer:
- Open a mosaic dataset.
- Create a mosaic layer.
- 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(
"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 |