Inheritance: IRasterFunction, IPersistVariant, IDocumentVersionSupportGEN, IXMLSerialize, IXMLVersionSupport
Example #1
0
        public static bool AddWatermarkDataToMD(string MDWorkspaceFolder, string MDName, string watermarkImagePath,
                                                double blendPercentage, esriWatermarkLocation watermarklocation, bool clearFunctions)
        {
            try
            {
                // Open MD
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory  mdWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace         mdWorkspace        = mdWorkspaceFactory.OpenFromFile(MDWorkspaceFolder, 0);
                IRasterWorkspaceEx workspaceEx        = (IRasterWorkspaceEx)(mdWorkspace);
                IMosaicDataset     mosaicDataset      = (IMosaicDataset)workspaceEx.OpenRasterDataset(
                    MDName);

                if (clearFunctions) // Clear functions already added to MD.
                {
                    mosaicDataset.ClearFunction();
                }

                // Create Watermark Function
                IRasterFunction rasterFunction = new CustomFunction.WatermarkFunction();
                // Create the Watermark Function Arguments object
                IWatermarkFunctionArguments rasterFunctionArguments =
                    new WatermarkFunctionArguments();
                // Set the WatermarkImagePath
                rasterFunctionArguments.WatermarkImagePath =
                    watermarkImagePath;
                // the blending percentage,
                rasterFunctionArguments.BlendPercentage = blendPercentage;
                // and the watermark location.
                rasterFunctionArguments.WatermarkLocation = watermarklocation;

                // Add function to MD.
                // This function takes the name of the property corresponding to the Raster
                // property of the Arguments object (in this case is it called Raster itself:
                // rasterFunctionArguments.Raster) as its third argument.
                mosaicDataset.ApplyFunction(rasterFunction, rasterFunctionArguments, "Raster");

                Console.WriteLine("Added Watermark to MD: " + MDName + ".");
                Console.WriteLine("Success.");
                return(true);
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception Caught while adding watermark to MD: " + exc.Message);
                Console.WriteLine("Failed.");
                return(false);
            }
        }
Example #2
0
        public static bool AddWatermarkToRD(IRasterDataset RasterDataset, string OutputFolder, string OutputName,
                                            string watermarkImagePath, double blendPercentage, esriWatermarkLocation watermarklocation)
        {
            try
            {
                // Create Watermark Function
                IRasterFunction rasterFunction = new CustomFunction.WatermarkFunction();
                // Create the Watermark Function Arguments object
                IWatermarkFunctionArguments rasterFunctionArguments =
                    new WatermarkFunctionArguments();
                // Set the WatermarkImagePath
                rasterFunctionArguments.WatermarkImagePath = watermarkImagePath;
                // the blending percentage,
                rasterFunctionArguments.BlendPercentage = blendPercentage;
                // and the watermark location.
                rasterFunctionArguments.WatermarkLocation = watermarklocation;
                // Set the Raster Dataset as the input raster
                rasterFunctionArguments.Raster = RasterDataset;

                // Create Function Dataset
                IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();
                // Create a Function Raster Dataset Name object
                IFunctionRasterDatasetName functionRasterDatasetName =
                    (IFunctionRasterDatasetName) new FunctionRasterDatasetName();
                // Set the path for the output Function Raster Dataset
                functionRasterDatasetName.FullName = System.IO.Path.Combine(OutputFolder, OutputName);
                functionRasterDataset.FullName     = (IName)functionRasterDatasetName;
                // Initialize the Function Raster Dataset with the function and
                // its arguments object
                functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

                // Save as Function Raster Dataset as an .afr file
                ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset;
                myTempDset.MakePermanent();

                Console.WriteLine("Generated " + OutputName + ".");
                Console.WriteLine("Success.");
                return(true);
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception Caught while adding watermark to Raster Dataset: " + exc.Message);
                Console.WriteLine("Failed.");
                return(false);
            }
        }
Example #3
0
        public static IRasterFunctionTemplate CreateWatermarkTemplate(string watermarkImagePath,
                                                                      double blendPercentage, esriWatermarkLocation watermarklocation)
        {
            #region Setup Raster Function Vars
            IRasterFunctionVariable watermarkRasterRFV = new RasterFunctionVariableClass();
            watermarkRasterRFV.Name      = "Raster";
            watermarkRasterRFV.IsDataset = true;
            IRasterFunctionVariable watermarkImagePathRFV = new RasterFunctionVariableClass();
            watermarkImagePathRFV.Name      = "WatermarkImagePath";
            watermarkImagePathRFV.Value     = watermarkImagePath;
            watermarkImagePathRFV.IsDataset = false;
            IRasterFunctionVariable watermarkBlendPercRFV = new RasterFunctionVariableClass();
            watermarkBlendPercRFV.Name  = "BlendPercentage";
            watermarkBlendPercRFV.Value = blendPercentage;
            IRasterFunctionVariable watermarkLocationRFV = new RasterFunctionVariableClass();
            watermarkLocationRFV.Name  = "Watermarklocation";
            watermarkLocationRFV.Value = watermarklocation;
            #endregion

            #region Setup Raster Function Template
            // Create the Watermark Function Arguments object
            IRasterFunctionArguments rasterFunctionArguments =
                new CustomFunction.WatermarkFunctionArguments();
            // Set the WatermarkImagePath
            rasterFunctionArguments.PutValue("WatermarkImagePath", watermarkImagePathRFV);
            // the blending percentage,
            rasterFunctionArguments.PutValue("BlendPercentage", watermarkBlendPercRFV);
            // and the watermark location.
            rasterFunctionArguments.PutValue("WatermarkLocation", watermarkLocationRFV);
            // Set the Raster Dataset as the input raster
            rasterFunctionArguments.PutValue("Raster", watermarkRasterRFV);

            IRasterFunction         watermarkFunction         = new CustomFunction.WatermarkFunction();
            IRasterFunctionTemplate watermarkFunctionTemplate = new RasterFunctionTemplateClass();
            watermarkFunctionTemplate.Function  = watermarkFunction;
            watermarkFunctionTemplate.Arguments = rasterFunctionArguments;
            #endregion

            return(watermarkFunctionTemplate);
        }
        public static IRasterFunctionTemplate CreateWatermarkTemplate(string watermarkImagePath, 
            double blendPercentage, esriWatermarkLocation watermarklocation)
        {
            #region Setup Raster Function Vars
            IRasterFunctionVariable watermarkRasterRFV = new RasterFunctionVariableClass();
            watermarkRasterRFV.Name = "Raster";
            watermarkRasterRFV.IsDataset = true;
            IRasterFunctionVariable watermarkImagePathRFV = new RasterFunctionVariableClass();
            watermarkImagePathRFV.Name = "WatermarkImagePath";
            watermarkImagePathRFV.Value = watermarkImagePath;
            watermarkImagePathRFV.IsDataset = false;
            IRasterFunctionVariable watermarkBlendPercRFV = new RasterFunctionVariableClass();
            watermarkBlendPercRFV.Name = "BlendPercentage";
            watermarkBlendPercRFV.Value = blendPercentage;
            IRasterFunctionVariable watermarkLocationRFV = new RasterFunctionVariableClass();
            watermarkLocationRFV.Name = "Watermarklocation";
            watermarkLocationRFV.Value = watermarklocation;
            #endregion

            #region Setup Raster Function Template
            // Create the Watermark Function Arguments object
            IRasterFunctionArguments rasterFunctionArguments =
                new CustomFunction.WatermarkFunctionArguments();
            // Set the WatermarkImagePath
            rasterFunctionArguments.PutValue("WatermarkImagePath", watermarkImagePathRFV);
            // the blending percentage,
            rasterFunctionArguments.PutValue("BlendPercentage", watermarkBlendPercRFV);
            // and the watermark location.
            rasterFunctionArguments.PutValue("WatermarkLocation", watermarkLocationRFV);
            // Set the Raster Dataset as the input raster
            rasterFunctionArguments.PutValue("Raster", watermarkRasterRFV);

            IRasterFunction watermarkFunction = new CustomFunction.WatermarkFunction();
            IRasterFunctionTemplate watermarkFunctionTemplate = new RasterFunctionTemplateClass();
            watermarkFunctionTemplate.Function = watermarkFunction;
            watermarkFunctionTemplate.Arguments = rasterFunctionArguments;
            #endregion

            return watermarkFunctionTemplate;
        }
        public static bool AddWatermarkDataToMD(string MDWorkspaceFolder, string MDName, string watermarkImagePath, 
            double blendPercentage, esriWatermarkLocation watermarklocation, bool clearFunctions)
        {
            try
            {
                // Open MD
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory mdWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace mdWorkspace = mdWorkspaceFactory.OpenFromFile(MDWorkspaceFolder, 0);
                IRasterWorkspaceEx workspaceEx = (IRasterWorkspaceEx)(mdWorkspace);
                IMosaicDataset mosaicDataset = (IMosaicDataset)workspaceEx.OpenRasterDataset(
                    MDName);

                if (clearFunctions) // Clear functions already added to MD.
                    mosaicDataset.ClearFunction();

                // Create Watermark Function
                IRasterFunction rasterFunction = new CustomFunction.WatermarkFunction();
                // Create the Watermark Function Arguments object
                IWatermarkFunctionArguments rasterFunctionArguments =
                    new WatermarkFunctionArguments();
                // Set the WatermarkImagePath
                rasterFunctionArguments.WatermarkImagePath =
                    watermarkImagePath;
                // the blending percentage,
                rasterFunctionArguments.BlendPercentage = blendPercentage;
                // and the watermark location.
                rasterFunctionArguments.WatermarkLocation = watermarklocation;

                // Add function to MD.
                // This function takes the name of the property corresponding to the Raster 
                // property of the Arguments object (in this case is it called Raster itself: 
                // rasterFunctionArguments.Raster) as its third argument.
                mosaicDataset.ApplyFunction(rasterFunction, rasterFunctionArguments, "Raster");

                Console.WriteLine("Added Watermark to MD: " + MDName + ".");
                Console.WriteLine("Success.");
                return true;
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception Caught while adding watermark to MD: " + exc.Message);
                Console.WriteLine("Failed.");
                return false;
            }
        }
        public static bool AddWatermarkToRD(IRasterDataset RasterDataset, string OutputFolder, string OutputName,
            string watermarkImagePath, double blendPercentage, esriWatermarkLocation watermarklocation)
        {
            try
            {
                // Create Watermark Function
                IRasterFunction rasterFunction = new CustomFunction.WatermarkFunction();
                // Create the Watermark Function Arguments object
                IWatermarkFunctionArguments rasterFunctionArguments =
                    new WatermarkFunctionArguments();
                // Set the WatermarkImagePath
                rasterFunctionArguments.WatermarkImagePath = watermarkImagePath;
                // the blending percentage,
                rasterFunctionArguments.BlendPercentage = blendPercentage;
                // and the watermark location.
                rasterFunctionArguments.WatermarkLocation = watermarklocation;
                // Set the Raster Dataset as the input raster
                rasterFunctionArguments.Raster = RasterDataset;

                // Create Function Dataset
                IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();
                // Create a Function Raster Dataset Name object
                IFunctionRasterDatasetName functionRasterDatasetName =
                    (IFunctionRasterDatasetName)new FunctionRasterDatasetName();
                // Set the path for the output Function Raster Dataset
                functionRasterDatasetName.FullName = System.IO.Path.Combine(OutputFolder, OutputName);
                functionRasterDataset.FullName = (IName)functionRasterDatasetName;
                // Initialize the Function Raster Dataset with the function and 
                // its arguments object
                functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

                // Save as Function Raster Dataset as an .afr file
                ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset;
                myTempDset.MakePermanent();

                Console.WriteLine("Generated " + OutputName + ".");
                Console.WriteLine("Success.");
                return true;
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception Caught while adding watermark to Raster Dataset: " + exc.Message);
                Console.WriteLine("Failed.");
                return false;
            }
        }