Creating a Mosaic dataset
Do the following steps to create a Mosaic dataset:
- Create a geodatabase workspace factory.
- Open the geodatabase.
- Create a spatial reference.
- Create the Mosaic dataset creation parameters object.
- Set the number of bands for the Mosaic dataset.
- Set the Mosaic dataset pixel type.
- Create the Mosaic workspace extension helper class.
- Find the correct extension from the workspace.
- Use the extension to create a Mosaic dataset with the spatial reference and the creation parameters.
See the following code example:
// Create a gdb workspace factory.
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
// Open the gdb.
IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(@"C:\testGdb.gdb", 0);
// Create Srs.
ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference mosaicSrs = spatialrefFactory.CreateProjectedCoordinateSystem((int)
(esriSRProjCSType.esriSRProjCS_World_Mercator));
// Create the mosaic dataset creation parameters object.
ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass
();
// Set the number of bands for the mosaic dataset.
creationPars.BandCount = 3;
// Set the pixel type of the mosaic dataset.
creationPars.PixelType = rstPixelType.PT_UCHAR;
// Create the mosaic workspace extension helper class.
IMosaicWorkspaceExtensionHelper mosaicExtHelper = new
MosaicWorkspaceExtensionHelperClass();
// Find the right extension from the workspace.
IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
// Use the extension to create a mosaic dataset, supplying the
// spatial reference and the creation parameters object previously created.
IMosaicDataset theMosaicDataset = mosaicExt.CreateMosaicDataset("testMD", mosaicSrs,
creationPars);
[VB.NET]
' Create a gdb workspace factory.
Dim workspaceFactory As IWorkspaceFactory = New FileGDBWorkspaceFactory()
' Open the gdb.
Dim fgdbWorkspace As IWorkspace = workspaceFactory.OpenFromFile("C:\testGdb.gdb", 0)
' Create Srs.
Dim spatialrefFactory As ISpatialReferenceFactory = New SpatialReferenceEnvironmentClass()
Dim mosaicSrs As ISpatialReference = spatialrefFactory.CreateProjectedCoordinateSystem(CInt((esriSRProjCSType.esriSRProjCS_World_Mercator)))
' Create the mosaic dataset creation parameters object.
Dim creationPars As ICreateMosaicDatasetParameters = New CreateMosaicDatasetParametersClass()
' Set the number of bands for the mosaic dataset.
creationPars.BandCount = 3
' Set the pixel type of the mosaic dataset.
creationPars.PixelType = rstPixelType.PT_UCHAR
' Create the mosaic workspace extension helper class.
Dim mosaicExtHelper As IMosaicWorkspaceExtensionHelper = New MosaicWorkspaceExtensionHelperClass()
' Find the right extension from the workspace.
Dim mosaicExt As IMosaicWorkspaceExtension = mosaicExtHelper.FindExtension(fgdbWorkspace)
' Use the extension to create a mosaic dataset, supplying the
' spatial reference and the creation parameters object previously created.
Dim theMosaicDataset As IMosaicDataset = mosaicExt.CreateMosaicDataset("testMD", mosaicSrs, creationPars)
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):
ESRI.ArcGIS.DataSourcesGDB ESRI.ArcGIS.DataSourcesRaster ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Geodatabase
Development licensing | Deployment licensing |
---|---|
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |