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


How to add rasters to a Mosaic dataset (ArcObjects .NET 10.5 SDK)

How to add rasters to a Mosaic dataset


Adding rasters to a Mosaic dataset

This topic shows how to add rasters to a Mosaic dataset. The Add Rasters operation requires a data crawler and a raster type. The data crawler is created in the function. Do the following steps to add rasters to a Mosaic dataset:
  1. Create a file crawler.
  2. Specify the source path.
  3. Specify whether to search subdirectories.
  4. Specify a file filter.
  5. Create an AddRastersParameters object.
  6. Specify the data crawler to use to crawl the data.
  7. Specify the raster type to use to add the data.
  8. Use the Mosaic dataset operation interface to add rasters to the Mosaic dataset.

    See the following code example:
[C#]
public void AddRastersToMD(IMosaicDataset theMosaicDataset, IRasterType
    theRasterType)
{
    // Create a file crawler.
    IDataSourceCrawler myCrawler=new FileCrawlerClass();
    // Specify the source path.
    ((IFileCrawler)myCrawler).Path=@"C:\TestData";
    // Specify whether to search subdirectories.
    ((IFileCrawler)myCrawler).Recurse=true;
    // Specify a file filter.
    ((IFileCrawler)myCrawler).Filters=".TIF";

    // The mosaic dataset operation interface is used to perform operations on 
    // a mosaic dataset.
    IMosaicDatasetOperation theMosaicDatasetOperation=(IMosaicDatasetOperation)
        (theMosaicDataset);
    // Create an AddRaster parameters object.
    IAddRastersParameters AddRastersArgs=new AddRastersParametersClass();
    // Specify the data crawler to use to crawl the data.
    AddRastersArgs.Crawler=myCrawler;
    // Specify the raster type to use to add the data.
    AddRastersArgs.RasterType=theRasterType;
    // Use the mosaic dataset operation interface to add 
    // rasters to the mosaic dataset.
    theMosaicDatasetOperation.AddRasters(AddRastersArgs, null);
}
[VB.NET]
Public Sub AddRastersToMD(ByVal theMosaicDataset As IMosaicDataset, ByVal theRasterType As IRasterType)
    ' Create a file crawler.
    Dim theCrawler As IDataSourceCrawler=New FileCrawler()
    Dim myFileCrawler As IFileCrawler=theCrawler
    ' Specify a file filter.
    myFileCrawler.Filters=".TIF"
    ' Specify whether to search subdirectories.
    myFileCrawler.Path="C:\TestData"
    ' Specify the source path.
    myFileCrawler.Recurse=True
    
    ' The mosaic dataset operation interface is used to perform operations on
    ' a mosaic dataset.
    Dim theMosaicDatasetOperation As IMosaicDatasetOperation =
    DirectCast((theMosaicDataset), IMosaicDatasetOperation)
    
    ' Create an AddRaster parameters object.
    Dim AddRastersArgs As IAddRastersParameters=New AddRastersParametersClass()
    ' Specify the data crawler to use to crawl the data.
    AddRastersArgs.Crawler=theCrawler
    ' Specify the raster type to use to add the data.
    AddRastersArgs.RasterType=theRasterType
    ' Use the mosaic dataset operation interface to add
    ' rasters to the mosaic dataset.
    theMosaicDatasetOperation.AddRasters(AddRastersArgs, Nothing)
End Sub


See Also:

How to open a Mosaic dataset
How to open and prepare a raster type




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 Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced