Пример #1
0
        public IMosaicDataset OpenMosaicDataset(ref IWorkspace fgdbWorkspace, string mosaicDatasetName)
        {
            IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
            IMosaicWorkspaceExtension       mosaicExt       = mosaicExtHelper.FindExtension(fgdbWorkspace);

            Console.WriteLine("Opening Mosaic Dataset");

            IMosaicDataset theMosaicDataset = mosaicExt.OpenMosaicDataset(mosaicDatasetName);

            return(theMosaicDataset);
        }
Пример #2
0
        public IMosaicDataset OpenMosaicDataset(IWorkspace pWorks, string pMosaicDatasetName)
        {
            IMosaicDataset pMosicDataset = null;
            IMosaicWorkspaceExtensionHelper pMosaicWsExHelper = new MosaicWorkspaceExtensionHelperClass();

            IMosaicWorkspaceExtension pMosaicWsExt = pMosaicWsExHelper.FindExtension(pWorks);

            if (pMosaicWsExt != null)
            {
                try
                {
                    pMosicDataset = pMosaicWsExt.OpenMosaicDataset(pMosaicDatasetName);
                }
                catch (Exception ex)
                {
                    return(pMosicDataset);
                }
            }

            return(pMosicDataset);
        }
Пример #3
0
        /// <summary>
        /// Create a Mosaic Dataset in the geodatabase provided using the parameters defined by MDParamaters.
        /// </summary>
        /// <param name="gdbWorkspace">Geodatabase to create the Mosaic dataser in.</param>
        public void CreateMosaicDataset(IWorkspace gdbWorkspace)
        {
            try
            {
                #region Global Declarations
                IMosaicDataset                  theMosaicDataset          = null;
                IMosaicDatasetOperation         theMosaicDatasetOperation = null;
                IMosaicWorkspaceExtensionHelper mosaicExtHelper           = null;
                IMosaicWorkspaceExtension       mosaicExt = null;
                #endregion

                #region CreateMosaicDataset
                try
                {
                    Console.WriteLine("Create Mosaic Dataset: " + MDParameters.mosaicDatasetName + ".amd");
                    /// Setup workspaces.
                    /// Create Srs
                    ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();

                    // Create the mosaic dataset creation parameters object.
                    ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass();
                    // Set the number of bands for the mosaic dataset.
                    // If defined as zero leave defaults
                    if (MDParameters.mosaicDatasetBands != 0)
                    {
                        creationPars.BandCount = MDParameters.mosaicDatasetBands;
                    }
                    // Set the pixel type of the mosaic dataset.
                    // If defined as unknown leave defaults
                    if (MDParameters.mosaicDatasetBits != rstPixelType.PT_UNKNOWN)
                    {
                        creationPars.PixelType = MDParameters.mosaicDatasetBits;
                    }
                    // Create the mosaic workspace extension helper class.
                    mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                    // Find the right extension from the workspace.
                    mosaicExt = mosaicExtHelper.FindExtension(gdbWorkspace);

                    // Default is none.
                    if (MDParameters.productDefinitionKey.ToLower() != "none")
                    {
                        // Set the product definition keyword and properties.
                        // (The property is called band definition keyword and band properties in the object).
                        ((ICreateMosaicDatasetParameters2)creationPars).BandDefinitionKeyword = MDParameters.productDefinitionKey;
                        MDParameters.productDefinitionProps = SetBandProperties(MDParameters.productDefinitionKey);
                        if (MDParameters.productDefinitionProps.Count == 0)
                        {
                            Console.WriteLine("Setting production definition properties failed.");
                            return;
                        }
                        ((ICreateMosaicDatasetParameters2)creationPars).BandProperties = MDParameters.productDefinitionProps;
                    }

                    // Use the extension to create a new mosaic dataset, supplying the
                    // spatial reference and the creation parameters object created above.
                    theMosaicDataset = mosaicExt.CreateMosaicDataset(MDParameters.mosaicDatasetName,
                                                                     MDParameters.mosaicDatasetSrs, creationPars, MDParameters.configKeyword);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Exception Caught while creating Mosaic Dataset: " + exc.Message);
                    return;
                }
                #endregion

                #region OpenMosaicDataset
                Console.WriteLine("Opening Mosaic Dataset");
                theMosaicDataset = null;
                // Use the extension to open the mosaic dataset.
                theMosaicDataset = mosaicExt.OpenMosaicDataset(MDParameters.mosaicDatasetName);
                // The mosaic dataset operation interface is used to perform operations on
                // a mosaic dataset.
                theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset);
                #endregion

                #region Preparing Raster Type
                Console.WriteLine("Preparing Raster Type");
                // Create a Raster Type Name object.
                IRasterTypeName theRasterTypeName = new RasterTypeNameClass();
                // Assign the name of the Raster Type to the name object.
                // The Name field accepts a path to an .art file as well
                // the name for a built in Raster Type.
                theRasterTypeName.Name = MDParameters.rasterTypeName;
                // Use the Open function from the IName interface to get the Raster Type object.
                IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open());
                if (theRasterType == null)
                {
                    Console.WriteLine("Raster Type not found " + MDParameters.rasterTypeName);
                }

                // Set the URI Filter on the loaded raster type.
                if (MDParameters.rasterTypeProductFilter != "")
                {
                    // Get the supported URI filters from the raster type object using the
                    // raster type properties interface.
                    IArray         mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters;
                    IItemURIFilter productFilter = null;
                    for (int i = 0; i < mySuppFilters.Count; ++i)
                    {
                        // Set the desired filter from the supported filters.
                        productFilter = (IItemURIFilter)mySuppFilters.get_Element(i);
                        if (productFilter.Name == MDParameters.rasterTypeProductFilter)
                        {
                            theRasterType.URIFilter = productFilter;
                        }
                    }
                }
                // Enable the correct templates in the raster type.
                string[] rasterProductNames = MDParameters.rasterTypeProductName.Split(';');
                bool     enableTemplate     = false;
                if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != ""))
                {
                    // Get the supported item templates from the raster type.
                    IItemTemplateArray templateArray = theRasterType.ItemTemplates;
                    for (int i = 0; i < templateArray.Count; ++i)
                    {
                        // Go through the supported item templates and enable the ones needed.
                        IItemTemplate template = templateArray.get_Element(i);
                        enableTemplate = false;
                        for (int j = 0; j < rasterProductNames.Length; ++j)
                        {
                            if (template.Name == rasterProductNames[j])
                            {
                                enableTemplate = true;
                            }
                        }
                        if (enableTemplate)
                        {
                            template.Enabled = true;
                        }
                        else
                        {
                            template.Enabled = false;
                        }
                    }
                }

                if (MDParameters.dataSourceSrs != null)
                {
                    ((IRasterTypeProperties)theRasterType).SynchronizeParameters.DefaultSpatialReference =
                        MDParameters.dataSourceSrs;
                }
                #endregion

                #region Add DEM To Raster Type
                if (MDParameters.rasterTypeAddDEM && ((IRasterTypeProperties)theRasterType).SupportsOrthorectification)
                {
                    // Open the Raster Dataset
                    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    IRasterWorkspace  rasterWorkspace  = (IRasterWorkspace)workspaceFactory.OpenFromFile(
                        System.IO.Path.GetDirectoryName(MDParameters.rasterTypeDemPath), 0);;
                    IRasterDataset myRasterDataset = rasterWorkspace.OpenRasterDataset(
                        System.IO.Path.GetFileName(MDParameters.rasterTypeDemPath));

                    IGeometricFunctionArguments geometricFunctionArguments =
                        new GeometricFunctionArgumentsClass();
                    geometricFunctionArguments.DEM = myRasterDataset;
                    ((IRasterTypeProperties)theRasterType).OrthorectificationParameters =
                        geometricFunctionArguments;
                }
                #endregion

                #region Preparing Data Source Crawler
                Console.WriteLine("Preparing Data Source Crawler");
                // Create a new property set to specify crawler properties.
                IPropertySet crawlerProps = new PropertySetClass();
                // Specify a file filter
                crawlerProps.SetProperty("Filter", MDParameters.dataSourceFilter);
                // Specify whether to search subdirectories.
                crawlerProps.SetProperty("Recurse", true);
                // Specify the source path.
                crawlerProps.SetProperty("Source", MDParameters.dataSource);
                // Get the recommended crawler from the raster type based on the specified
                // properties using the IRasterBuilder interface.
                IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps);
                #endregion

                #region Add Rasters
                Console.WriteLine("Adding Rasters");
                // Create a AddRaster parameters object.
                IAddRastersParameters AddRastersArgs = new AddRastersParametersClass();
                // Specify the data crawler to be used to crawl the data.
                AddRastersArgs.Crawler = theCrawler;
                // Specify the raster type to be used to add the data.
                AddRastersArgs.RasterType = theRasterType;
                // Use the mosaic dataset operation interface to add
                // rasters to the mosaic dataset.
                theMosaicDatasetOperation.AddRasters(AddRastersArgs, null);
                #endregion

                #region Compute Pixel Size Ranges
                Console.WriteLine("Computing Pixel Size Ranges");
                // 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);
                #endregion

                #region Building Boundary
                Console.WriteLine("Building Boundary");
                // 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);
                #endregion

                if (MDParameters.buildOverviews)
                {
                    #region Defining Overviews
                    Console.WriteLine("Defining Overviews");
                    // Create a define overview parameters object.
                    IDefineOverviewsParameters defineOvArgs = new DefineOverviewsParametersClass();
                    // Use the overview tile parameters interface to specify the overview factor
                    // used to generate overviews.
                    ((IOverviewTileParameters)defineOvArgs).OverviewFactor = 3;
                    // Use the mosaic dataset operation interface to define overviews.
                    theMosaicDatasetOperation.DefineOverviews(defineOvArgs, null);
                    #endregion

                    #region Compute Pixel Size Ranges
                    Console.WriteLine("Computing Pixel Size Ranges");
                    // Calculate cell size ranges to update the Min/Max pixel sizes.
                    theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null);
                    #endregion

                    #region Generating Overviews
                    Console.WriteLine("Generating Overviews");
                    // Create a generate overviews parameters object.
                    IGenerateOverviewsParameters genPars = new GenerateOverviewsParametersClass();
                    // Set properties to control overview generation.
                    IQueryFilter genQuery = new QueryFilterClass();
                    ((ISelectionParameters)genPars).QueryFilter = genQuery;
                    genPars.GenerateMissingImages = true;
                    genPars.GenerateStaleImages   = true;
                    // Use the mosaic dataset operation interface to generate overviews.
                    theMosaicDatasetOperation.GenerateOverviews(genPars, null);
                    #endregion
                }

                #region Report
                Console.WriteLine("Success.");
                #endregion
            }
            catch (Exception exc)
            {
                #region Report
                Console.WriteLine("Exception Caught in CreateMD: " + exc.Message);
                Console.WriteLine("Shutting down.");
                #endregion
            }
        }