No geography when add rasters to a Mosaic dataset

403
2
07-25-2011 07:24 PM
gisscconsulting
New Contributor
I have a set of .tiff file and use this ESRI code to add them to mosaic dataset. The result show empty geography.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002wv000000


I noticed the field MinPS and MaxPS is empty when using the above code. Also this line does not even pass compiler
((IFileCrawler)myCrawler).Filters = ".TIF";


However, all works fine when I load all tiff manually.

Any one experienced the same issue? thanks

code

//Add raster to mosaic dataset
        public static  void AddRastersToMD(string filePath, string fileGDBPath, string mdName)
        {
            try
            {
   
                // Create a Raster Type Name object.
                IRasterTypeName theRasterTypeName = new RasterTypeNameClass();
                // Assign the name of the Raster Type to the name object.
                // the name for a built in Raster Type.
                theRasterTypeName.Name = "Raster Dataset";
                // Use the Open function from the IName interface to get the Raster Type object.
                IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open());

                IMosaicDataset theMosaicDataset = OpenMosaicDataset(fileGDBPath, mdName);

                // Create a file crawler.
                IDataSourceCrawler myCrawler = new FileCrawlerClass();
                // Specify the source path.
                ((IFileCrawler)myCrawler).Path = filePath;
                // 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();
                // Exclude duplicates
                AddRastersArgs.DuplicateItemsAction = esriDuplicateItemsAction.esriDuplicateItemsExclude;
           
                // 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);


            }
            catch (Exception ex)
            {
                Utility.Log(ex.ToString());
            }
      
        }
0 Kudos
2 Replies
Prashant_MukeshMangtani
Esri Contributor
When you use the Add Raster GPTool to add data to a mosaic dataset, it by default performs some added operations. If you scroll down a little in the tool, you will find that by default, the tool updates cellsize ranges and updates the boundary whenever you add data. These operations are something extra the tool does for you. So to do the same thing the GP Tool does, you would need to add data to the mosaic dataset, calculate cellsize ranges on it and the build boundary on the mosaic dataset.

The MinPS and MaxPS fields are used to define visibility ranges which help the mosaic dataset determine what raster's to show at what scales. The fields are populated when you calculate cell size ranges on the mosaic dataset by running the Calculate CellSize Ranges GP Tool or using the code below:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_compute_pixel_si...
To build boundary as well, you can run the corresponding GP Tool, or use the code below:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_build_a_boundary...

The statement to set the filter does not compile because the interface was changed. You don't need the file filter however, its optional. You can comment that statement out and it will still add your data; Or you can use the following statement to set a filter instead:
                // Specify a file filter.
                myCrawler.Filter = ".TIF";

Last but not least, if you are creating a mosaic dataset using code, you might want to use the sample we have at
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Create_a_Mosaic_...

The sample not only gives you an alternate way to have the raster dataset recommend the crawler instead of you creating one, it also performs all the necessary steps to have a complete usable Mosaic dataset.
Let me know if you have any more problems.
0 Kudos
gisscconsulting
New Contributor
Thanks. Add these two blocks taken from ESRI create mosaic dataset example code.
All works now.            

// Create a calculate cellsize ranges parameters object.
                ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass();
                // Use the mosaic dataset operation interface to calculate cellsize ranges.
                theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null);

                // Create a build boundary parameters object.
                IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass();
                // Set flags that control boundary generation.
                boundaryArgs.AppendToExistingBoundary = true;
                // Use the mosaic dataset operation interface to build boundary.
                theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null);
0 Kudos