Пример #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 CreateMosaicDataset(ref IWorkspace fgdbWorkspace, string mosaicDatasetName,
                                                  ISpatialReference mosaicSrs, int mosaicDatasetBands, rstPixelType mosaicDatasetBits, string configKeyword)
        {
            IMosaicDataset theMosaicDataset = null;

            try
            {
                Console.WriteLine("Create Mosaic Dataset: " + mosaicDatasetName);

                if (mosaicSrs == null)
                {
                    ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();
                    //ISpatialReference mosaicSrs = spatialrefFactory.CreateProjectedCoordinateSystem(
                    //    (int)(esriSRProjCSType.esriSRProjCS_World_Mercator));
                    mosaicSrs = spatialrefFactory.CreateGeographicCoordinateSystem(
                        (int)(esriSRGeoCSType.esriSRGeoCS_WGS1984));
                }

                // 创建镶嵌数据集创建参数对象
                ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass();

                // 设置镶嵌数据集band数量.
                // 0 为默认设置
                if (mosaicDatasetBands != 0)
                {
                    creationPars.BandCount = mosaicDatasetBands;
                }
                // 设置象元类型.
                //  默认为 unknown
                if (mosaicDatasetBits != rstPixelType.PT_UNKNOWN)
                {
                    creationPars.PixelType = mosaicDatasetBits;
                }

                //创建栅格数据库扩展帮助类
                IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                // 查找扩展
                IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
                // 使用扩展创建新的镶嵌数据集, 需要提供空间参考和创建参数。
                theMosaicDataset = mosaicExt.CreateMosaicDataset(mosaicDatasetName,
                                                                 mosaicSrs, creationPars, configKeyword);
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception Caught while creating Mosaic Dataset: " + exc.Message);
                Console.WriteLine("Shutting down.");
                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }
            return(theMosaicDataset);
        }
Пример #3
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);
        }
Пример #4
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
            }
        }
Пример #5
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;
        }
        public static void TestThumbnailBuilder(string rasterTypeName, string rasterTypeProductFilter,
            string rasterTypeProductName, string dataSource, string dataSourceFilter, string fgdbParentFolder,
            bool saveToArt, string customTypeFilePath, bool clearGdbDirectory)
        {
            try
            {
                string[] rasterProductNames = rasterTypeProductName.Split(';');
                string nameString = rasterTypeName.Replace(" ", "") + rasterTypeProductFilter.Replace(" ", "") +
                    rasterProductNames[0].Replace(" ", "");

                #region Directory Declarations
                string fgdbName = nameString + ".gdb";
                string fgdbDir = fgdbParentFolder + "\\" + fgdbName;
                string MosaicDatasetName = nameString + "MD";
                #endregion

                #region Global Declarations
                IMosaicDataset theMosaicDataset = null;
                IMosaicDatasetOperation theMosaicDatasetOperation = null;
                IMosaicWorkspaceExtensionHelper mosaicExtHelper = null;
                IMosaicWorkspaceExtension mosaicExt = null;
                #endregion

                #region Create File GDB
                Console.WriteLine("Creating File GDB: " + fgdbName);
                if (clearGdbDirectory)
                {
                    try
                    {
                        Console.WriteLine("Emptying Gdb folder.");
                        System.IO.Directory.Delete(fgdbParentFolder, true);
                        System.IO.Directory.CreateDirectory(fgdbParentFolder);
                    }
                    catch (System.IO.IOException EX)
                    {
                        Console.WriteLine(EX.Message);
                        return;
                    }
                }

                // Create a File Gdb
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory FgdbFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                FgdbFactory.Create(fgdbParentFolder,
                    fgdbName, null, 0);
                #endregion

                #region Create Mosaic Dataset
                try
                {
                    Console.WriteLine("Create Mosaic Dataset: " + MosaicDatasetName);
                    // Setup workspaces.
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    IWorkspace fgdbWorkspace = workspaceFactory.OpenFromFile(fgdbDir, 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();
                    // Create the mosaic workspace extension helper class.
                    mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                    // Find the right extension from the workspace.
                    mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
                    // Use the extension to create a new mosaic dataset, supplying the 
                    // spatial reference and the creation parameters object created above.
                    theMosaicDataset = mosaicExt.CreateMosaicDataset(MosaicDatasetName,
                        mosaicSrs, creationPars, "");
                    theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Error: Failed to create Mosaic Dataset : {0}.", 
                        MosaicDatasetName + " " + exc.Message);
                    return;
                }
                #endregion

                #region Create Custom 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 = 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("Error:Raster Type not found " + rasterTypeName);
                    return;
                }
                #endregion

                #region Prepare Raster Type
                // Set the URI Filter on the loaded raster type.
                if (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 == rasterTypeProductFilter)
                            theRasterType.URIFilter = productFilter;
                    }
                }
                // Enable the correct templates in the raster type.
                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;
                    }
                }
                ((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter;
                #endregion

                #region Save Custom Raster Type
                if (saveToArt)
                {
                    IRasterTypeProperties rasterTypeProperties = (IRasterTypeProperties)theRasterType;
                    IRasterTypeEnvironment rasterTypeHelper = new RasterTypeEnvironmentClass();
                    rasterTypeProperties.Name = customTypeFilePath;

                    IMemoryBlobStream ipBlob = rasterTypeHelper.SaveRasterType(theRasterType);
                    ipBlob.SaveToFile(customTypeFilePath);
                }
                #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", dataSourceFilter);
                // Specify whether to search subdirectories.
                crawlerProps.SetProperty("Recurse", true);
                // Specify the source path.
                crawlerProps.SetProperty("Source", dataSource);
                // Get the recommended crawler from the raster type based on the specified 
                // properties using the IRasterBuilder interface.
                // Pass on the Thumbnailtype to the crawler...
                IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps);
                #endregion

                #region Add Rasters
                try
                {                    
                    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 Thumbnail 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);
                }
                catch (Exception ex)
                {                    
                    Console.WriteLine("Error: Add raster Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Compute Pixel Size Ranges
                Console.WriteLine("Computing Pixel Size Ranges.");
                try
                {
                    // 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);
                }
                catch (Exception ex)
                {                    
                    Console.WriteLine("Error: Compute Pixel Size Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Building Boundary
                Console.WriteLine("Building Boundary");
                try
                {
                    // 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);
                }
                catch (Exception ex)
                {                    
                    Console.WriteLine("Error: Build Boundary Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Report
                Console.WriteLine("Successfully created MD: " + MosaicDatasetName + ". ");
                #endregion
            }
            catch (Exception exc)
            {                
                #region Report
                Console.WriteLine("Exception Caught in TestThumbnailBuilder: " + exc.Message);
                Console.WriteLine("Failed.");
                Console.WriteLine("Shutting down.");
                #endregion
            }
        }
        /// <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
            }
        }
        public static void TestThumbnailBuilder(string rasterTypeName, string rasterTypeProductFilter,
                                                string rasterTypeProductName, string dataSource, string dataSourceFilter, string fgdbParentFolder,
                                                bool saveToArt, string customTypeFilePath, bool clearGdbDirectory)
        {
            try
            {
                string[] rasterProductNames = rasterTypeProductName.Split(';');
                string   nameString         = rasterTypeName.Replace(" ", "") + rasterTypeProductFilter.Replace(" ", "") +
                                              rasterProductNames[0].Replace(" ", "");

                #region Directory Declarations
                string fgdbName          = nameString + ".gdb";
                string fgdbDir           = fgdbParentFolder + "\\" + fgdbName;
                string MosaicDatasetName = nameString + "MD";
                #endregion

                #region Global Declarations
                IMosaicDataset                  theMosaicDataset          = null;
                IMosaicDatasetOperation         theMosaicDatasetOperation = null;
                IMosaicWorkspaceExtensionHelper mosaicExtHelper           = null;
                IMosaicWorkspaceExtension       mosaicExt = null;
                #endregion

                #region Create File GDB
                Console.WriteLine("Creating File GDB: " + fgdbName);
                if (clearGdbDirectory)
                {
                    try
                    {
                        Console.WriteLine("Emptying Gdb folder.");
                        System.IO.Directory.Delete(fgdbParentFolder, true);
                        System.IO.Directory.CreateDirectory(fgdbParentFolder);
                    }
                    catch (System.IO.IOException EX)
                    {
                        Console.WriteLine(EX.Message);
                        return;
                    }
                }

                // Create a File Gdb
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory FgdbFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                FgdbFactory.Create(fgdbParentFolder,
                                   fgdbName, null, 0);
                #endregion

                #region Create Mosaic Dataset
                try
                {
                    Console.WriteLine("Create Mosaic Dataset: " + MosaicDatasetName);
                    // Setup workspaces.
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    IWorkspace        fgdbWorkspace    = workspaceFactory.OpenFromFile(fgdbDir, 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();
                    // Create the mosaic workspace extension helper class.
                    mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                    // Find the right extension from the workspace.
                    mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
                    // Use the extension to create a new mosaic dataset, supplying the
                    // spatial reference and the creation parameters object created above.
                    theMosaicDataset = mosaicExt.CreateMosaicDataset(MosaicDatasetName,
                                                                     mosaicSrs, creationPars, "");
                    theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Error: Failed to create Mosaic Dataset : {0}.",
                                      MosaicDatasetName + " " + exc.Message);
                    return;
                }
                #endregion

                #region Create Custom 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 = 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("Error:Raster Type not found " + rasterTypeName);
                    return;
                }
                #endregion

                #region Prepare Raster Type
                // Set the URI Filter on the loaded raster type.
                if (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 == rasterTypeProductFilter)
                        {
                            theRasterType.URIFilter = productFilter;
                        }
                    }
                }
                // Enable the correct templates in the raster type.
                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;
                        }
                    }
                }
                ((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter;
                #endregion

                #region Save Custom Raster Type
                if (saveToArt)
                {
                    IRasterTypeProperties  rasterTypeProperties = (IRasterTypeProperties)theRasterType;
                    IRasterTypeEnvironment rasterTypeHelper     = new RasterTypeEnvironmentClass();
                    rasterTypeProperties.Name = customTypeFilePath;

                    IMemoryBlobStream ipBlob = rasterTypeHelper.SaveRasterType(theRasterType);
                    ipBlob.SaveToFile(customTypeFilePath);
                }
                #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", dataSourceFilter);
                // Specify whether to search subdirectories.
                crawlerProps.SetProperty("Recurse", true);
                // Specify the source path.
                crawlerProps.SetProperty("Source", dataSource);
                // Get the recommended crawler from the raster type based on the specified
                // properties using the IRasterBuilder interface.
                // Pass on the Thumbnailtype to the crawler...
                IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps);
                #endregion

                #region Add Rasters
                try
                {
                    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 Thumbnail 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);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Add raster Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Compute Pixel Size Ranges
                Console.WriteLine("Computing Pixel Size Ranges.");
                try
                {
                    // 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);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Compute Pixel Size Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Building Boundary
                Console.WriteLine("Building Boundary");
                try
                {
                    // 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);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Build Boundary Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Report
                Console.WriteLine("Successfully created MD: " + MosaicDatasetName + ". ");
                #endregion
            }
            catch (Exception exc)
            {
                #region Report
                Console.WriteLine("Exception Caught in TestThumbnailBuilder: " + exc.Message);
                Console.WriteLine("Failed.");
                Console.WriteLine("Shutting down.");
                #endregion
            }
        }
Пример #9
0
        /// <summary>
        /// 连接镶嵌数据集
        /// </summary>
        /// <param name="WS">工作空间</param>
        /// <param name="Name">名称</param>
        public IMosaicDataset MosaicDataset(IWorkspace WS, string Name)
        {
            if (WS == null)
            {
                MessageBox.Show("请检查工作空间");
                return null;
            }

            IMosaicDataset MosaicDataset = null;
            try
            {
                IWorkspace2 WS2 = WS as IWorkspace2;
                IMosaicWorkspaceExtensionHelper MosaicWorkspaceExtensionHelper = new MosaicWorkspaceExtensionHelperClass();
                IMosaicWorkspaceExtension MosaicWorkspaceExtension = MosaicWorkspaceExtensionHelper.FindExtension(WS);
                MosaicDataset = MosaicWorkspaceExtension.OpenMosaicDataset(Name);

                //IRasterLayer RasterLayer = new RasterLayer();
                //RasterLayer.CreateFromDataset(MosaicDataset as IRasterDataset);

                return MosaicDataset;
            }
            catch
            {
                MessageBox.Show("工作空间或名称错误");
                return null;
            }
            //finally
            //{
            //    Marshal.FinalReleaseComObject(pMosaicDataset); //释放资源,释放内存了return的数据报错
            //}
        }
Пример #10
0
        private void btnChangeY_Click(object sender, EventArgs e)
        {
            maploaded = true;
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
            if ((cboBotYear.Text != "") && (cboTopYear.Text != ""))
            {
                label3.Text = cboTopYear.Text;
                label4.Text = cboBotYear.Text;
                if (!(topPublicMosaicLayer == null))
                {
                    //Delete old top layer, ??check still the same top to save time?
                    m_MapControl.ActiveView.FocusMap.DeleteLayer((ILayer)topPublicMosaicLayer);
                    m_MapControltop.ActiveView.FocusMap.DeleteLayer((ILayer)topPublicMosaicLayer);
                }
                if (!(botPublicMosaicLayer == null))
                {
                    //Delete old bot layer, ??check still the same bot to save time?
                    m_MapControl.ActiveView.FocusMap.DeleteLayer((ILayer)botPublicMosaicLayer);
                    m_MapControlbase.ActiveView.FocusMap.DeleteLayer((ILayer)botPublicMosaicLayer);
                }
                //This version, we will use mosaicdataset========================
                IMosaicWorkspaceExtensionHelper MosaicWsHelper = new MosaicWorkspaceExtensionHelperClass();
                IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
                string mosaicdatabase = ConfigurationManager.AppSettings["MosaicDatabase"];
                IWorkspace ws = workspaceFactory.OpenFromFile(mosaicdatabase, 0);
                IMosaicWorkspaceExtension mosaicWsExtension = MosaicWsHelper.FindExtension(ws);

                //BOT
                strBaseYr = "AmherstOrthoMosaic" + cboBotYear.Text;
                IMosaicDataset pMosaicDatasetBot = mosaicWsExtension.OpenMosaicDataset(strBaseYr);
                botPublicMosaicLayer = new MosaicLayerClass();
                botPublicMosaicLayer.CreateFromMosaicDataset(pMosaicDatasetBot);
                if (!(botPublicMosaicLayer == null))
                {
                    IFeatureLayer footprint = (IFeatureLayer)botPublicMosaicLayer.FootprintLayer;
                    ((ILayer)footprint).Visible = false;
                    ILayer botLayer = (ILayer)botPublicMosaicLayer;
                    botLayer.MinimumScale = 6000;
                    m_MapControl.ActiveView.FocusMap.AddLayer(botLayer);
                    m_MapControlbase.ActiveView.FocusMap.AddLayer(botLayer);
                }
                //TOP
                strTopYr = "AmherstOrthoMosaic" + cboTopYear.Text;
                IMosaicDataset pMosaicDatasetTop = mosaicWsExtension.OpenMosaicDataset(strTopYr);
                topPublicMosaicLayer = new MosaicLayerClass();
                topPublicMosaicLayer.CreateFromMosaicDataset(pMosaicDatasetTop);
                if (!(topPublicMosaicLayer == null))
                {
                    IFeatureLayer footprint = (IFeatureLayer)topPublicMosaicLayer.FootprintLayer;
                    ((ILayer)footprint).Visible = false;
                    ILayer topLayer = (ILayer)topPublicMosaicLayer;
                    topLayer.MinimumScale = 6000;
                    m_MapControl.ActiveView.FocusMap.AddLayer(topLayer);
                    m_MapControltop.ActiveView.FocusMap.AddLayer(topLayer);
                    ILayerEffectProperties lepSwip = m_CommandsEnvironment as ILayerEffectProperties;
                    lepSwip.SwipeLayer = topLayer;
                    //===possible problem toplayer is not public variable any more
                }

                IFeatureLayer featurelayerParcel = new FeatureLayerClass();
                featurelayerParcel.FeatureClass = featureClassParcels;
                featurelayerParcel.Name = "parcels";
                featurelayerParcel.MinimumScale = 6000;
                featurelayerParcel.Visible = false;
                IRgbColor pLColor = new RgbColorClass();
                pLColor.Red = 255;
                pLColor.Green = 255;
                pLColor.Blue = 255;

                ISimpleFillSymbol pSFS = new SimpleFillSymbolClass();
                ICartographicLineSymbol pCLineS = new CartographicLineSymbolClass();
                pCLineS.Color = pLColor;
                ILineProperties lineProperties = pCLineS as ILineProperties;
                lineProperties.Offset = 0;
                System.Double[] hpe = new System.Double[4];
                hpe[0] = 7;
                hpe[1] = 2;
                hpe[2] = 1;
                hpe[3] = 2;

                ITemplate template = new TemplateClass();
                template.Interval = 3;
                for (int i = 0; i < hpe.Length; i = i + 2)
                {
                    template.AddPatternElement(hpe[i], hpe[i + 1]);
                }
                lineProperties.Template = template;
                pCLineS.Width = 1;
                pCLineS.Cap = esriLineCapStyle.esriLCSButt;
                pCLineS.Join = esriLineJoinStyle.esriLJSBevel;
                pCLineS.Color = pLColor;
                pSFS.Outline = pCLineS;
                pSFS.Style = esriSimpleFillStyle.esriSFSHollow;

                IGeoFeatureLayer pGFL = (IGeoFeatureLayer)featurelayerParcel;
                ISimpleRenderer pRend = pGFL.Renderer as ISimpleRenderer;
                pRend.Symbol = pSFS as ISymbol;

                if ((Helper.FindMyFeatureLayer(m_MapControl.ActiveView.FocusMap, "parcels") == null))
                {
                    if (!(featurelayerParcel == null))
                    {
                        m_MapControl.ActiveView.FocusMap.AddLayer(featurelayerParcel);
                        m_MapControltop.ActiveView.FocusMap.AddLayer(featurelayerParcel);
                        m_MapControlbase.ActiveView.FocusMap.AddLayer(featurelayerParcel);
                    }
                }
                else
                {
                    //is this temp necessary???????
                    IFeatureLayer parcellayertemp = Helper.FindMyFeatureLayer(m_MapControl.ActiveView.FocusMap, "parcels");
                    m_MapControl.ActiveView.FocusMap.MoveLayer(parcellayertemp, 0);
                    m_MapControltop.ActiveView.FocusMap.MoveLayer(parcellayertemp, 0);
                    m_MapControlbase.ActiveView.FocusMap.MoveLayer(parcellayertemp, 0);
                }
                //MessageBox.Show("Top aerophoto is taken on: " + cboTopYear.Text + ".\r\nBottom areophoto is taken on: " + cboBotYear.Text + ".");
            }
            else
            {
                MessageBox.Show("Please select two years to compare");

            }
            GeneratePageLayout();
            System.Windows.Forms.Cursor.Current = Cursors.Default;
        }
 public IMosaicDataset openMosaicDataset(IWorkspace wks, string mosaicDatasetName)
 {
     IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
     IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(wks);
     IMosaicDataset mosaicDset = mosaicExt.OpenMosaicDataset(mosaicDatasetName);
     return mosaicDset;
 }
 public IMosaicDataset createMosaicDataset(IWorkspace wks, ISpatialReference spatialReference, string mosaicDataSetName, rstPixelType pType, int numBands)
 {
     ICreateMosaicDatasetParameters crParam = new CreateMosaicDatasetParametersClass();
     crParam.BandCount = numBands;
     crParam.PixelType = pType;
     IMosaicWorkspaceExtensionHelper mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
     IMosaicWorkspaceExtension mosaicExt = mosaicExtHelper.FindExtension(wks);
     IMosaicDataset mosaicDset = mosaicExt.CreateMosaicDataset(mosaicDataSetName, spatialReference,(ICreateMosaicDatasetParameters)crParam,"");
     return mosaicDset;
 }
Пример #13
0
        IMosaicDataset GetMosaicDataset(string pFGDBPath,string pMDame)
        {
            IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
                  IWorkspace pFgdbWorkspace = pWorkspaceFactory.OpenFromFile(pFGDBPath, 0);

                  IMosaicWorkspaceExtensionHelper pMosaicExentionHelper = new
                      MosaicWorkspaceExtensionHelperClass();

                  IMosaicWorkspaceExtension pMosaicExtention = pMosaicExentionHelper.FindExtension(pFgdbWorkspace);

                  return pMosaicExtention.OpenMosaicDataset(pMDame);
        }
Пример #14
0
        /// <summary>
        /// 创建镶嵌数据集
        /// </summary>
        /// <param name="pFGDBPath"></param>
        /// <param name="pMDame"></param>
        /// <param name="pSrs"></param>
        /// <returns></returns>
        IMosaicDataset CreateMosaicDataset(string pFGDBPath, string pMDame, ISpatialReference pSrs )
        {
            IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();

                  IWorkspace pFgdbWorkspace = pWorkspaceFactory.OpenFromFile(pFGDBPath, 0);

                  ICreateMosaicDatasetParameters pCreationPars = new CreateMosaicDatasetParametersClass();

                  pCreationPars.BandCount = 3;

                  pCreationPars.PixelType = rstPixelType.PT_UCHAR;

                  IMosaicWorkspaceExtensionHelper pMosaicExentionHelper = new  MosaicWorkspaceExtensionHelperClass();

                  IMosaicWorkspaceExtension pMosaicExtention = pMosaicExentionHelper.FindExtension(pFgdbWorkspace);

                  return pMosaicExtention.CreateMosaicDataset(pMDame, pSrs, pCreationPars, "");
        }