public static IRasterFunctionTemplate CreateNDVICustomTemplate(string bandIndices) { #region Setup Raster Function Vars IRasterFunctionVariable watermarkRasterRFV = new RasterFunctionVariableClass(); watermarkRasterRFV.Name = "Raster"; watermarkRasterRFV.IsDataset = true; IRasterFunctionVariable bandIndicesRFV = new RasterFunctionVariableClass(); bandIndicesRFV.Name = "BandIndices"; bandIndicesRFV.Value = bandIndices; bandIndicesRFV.IsDataset = false; #endregion #region Setup Raster Function Template // Create the NDVI Custom Function Arguments object IRasterFunctionArguments rasterFunctionArguments = new CustomFunction.NDVICustomFunctionArguments(); // Set the Band Indices rasterFunctionArguments.PutValue("BandIndices", bandIndicesRFV); // Set the Raster Dataset as the input raster rasterFunctionArguments.PutValue("Raster", watermarkRasterRFV); // Create the NDVI Custom Function IRasterFunction ndviCustomFunction = new CustomFunction.NDVICustomFunction(); IRasterFunctionTemplate ndviCustomFunctionTemplate = new RasterFunctionTemplateClass(); ndviCustomFunctionTemplate.Function = ndviCustomFunction; ndviCustomFunctionTemplate.Arguments = rasterFunctionArguments; #endregion return(ndviCustomFunctionTemplate); }
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); }
/// <summary> /// Create a Raster Type object given the name of the raster type (usually /// the same name as the one in the UI list of raster types). /// </summary> /// <param name="RasterTypeName">Name of the Raster Type object to create.</param> /// <returns>The Raster type object.</returns> public IRasterType CreateRasterType(string RasterTypeName) { // Create a new RasterType object and its corresponding name object. IRasterType theRasterType = new RasterTypeClass(); IRasterTypeName theRasterTypeName = new RasterTypeNameClass(); theRasterTypeName.Name = RasterTypeName; theRasterType.FullName = (IName)theRasterTypeName; // Set the properties for the raster type object. These are shown in the // 'General' tab of the raster type properties page. ((IRasterTypeProperties)theRasterType).Name = "DMCII Raster Type"; ((IRasterTypeProperties)theRasterType).Description = "Raster Type for DMCII data."; ((IRasterTypeProperties)theRasterType).DataSourceFilter = "*.dim"; ((IRasterTypeProperties)theRasterType).SupportsOrthorectification = true; // Create the Custom Raster Builder object IRasterBuilder customRasterBuilder = new DMCIIRasterBuilder(); // Set the Raster Builder of theRasterType to the above created builder. theRasterType.RasterBuilder = customRasterBuilder; // Enable the use of the Raster Type as a Raster Product. ((IRasterTypeProperties2)theRasterType).IsSensorRasterType = true; #region Set Product Templates // Create a new array of templates if needed. if (theRasterType.ItemTemplates == null) theRasterType.ItemTemplates = new ItemTemplateArrayClass(); // Add a 'Raw' template. IItemTemplate nullTemplate = new ItemTemplateClass(); nullTemplate.Enabled = false; nullTemplate.Name = "Raw"; ((IItemTemplate2)nullTemplate).IsSensorTemplate = true; ((IItemTemplate2)nullTemplate).SupportsEnhancement = false; theRasterType.ItemTemplates.Add(nullTemplate); // Add a 'Stretch' template. This is the default template. IItemTemplate strTemplate = new ItemTemplateClass(); strTemplate.Enabled = true; strTemplate.Name = "Stretch"; IRasterFunction stretchFunction = new StretchFunctionClass(); IStretchFunctionArguments stretchFunctionArgs = new StretchFunctionArgumentsClass(); stretchFunctionArgs.StretchType = esriRasterStretchType.esriRasterStretchMinimumMaximum; IRasterFunctionVariable rasterVar = new RasterFunctionVariableClass(); rasterVar.IsDataset = true; rasterVar.Name = "MS"; rasterVar.Aliases = new StrArrayClass(); rasterVar.Aliases.Add("MS"); rasterVar.Description = "Variable for input raster"; stretchFunctionArgs.Raster = rasterVar; IRasterFunctionTemplate stretchFunctionTemplate = new RasterFunctionTemplateClass(); stretchFunctionTemplate.Function = stretchFunction; stretchFunctionTemplate.Arguments = stretchFunctionArgs; strTemplate.RasterFunctionTemplate = stretchFunctionTemplate; ((IItemTemplate2)strTemplate).IsSensorTemplate = true; ((IItemTemplate2)strTemplate).SupportsEnhancement = true; theRasterType.ItemTemplates.Add(strTemplate); #endregion #region Set Product Types // Add Product types (called URI filters in the code). if (((IRasterTypeProperties)theRasterType).SupportedURIFilters == null) ((IRasterTypeProperties)theRasterType).SupportedURIFilters = new ArrayClass(); // Create and setup URI Filters IItemURIFilter allFilter = new URIProductNameFilterClass(); allFilter.Name = "All"; allFilter.SupportsOrthorectification = true; allFilter.SupportedTemplateNames = new StrArrayClass(); allFilter.SupportedTemplateNames.Add("Raw"); allFilter.SupportedTemplateNames.Add("Stretch"); IStringArray allProductNames = new StrArrayClass(); allProductNames.Add("L1T"); allProductNames.Add("L1R"); ((IURIProductNameFilter)allFilter).ProductNames = allProductNames; // The L1T filter does not support orthorectification. IItemURIFilter l1tFilter = new URIProductNameFilterClass(); l1tFilter.Name = "L1T"; l1tFilter.SupportsOrthorectification = false; l1tFilter.SupportedTemplateNames = new StrArrayClass(); l1tFilter.SupportedTemplateNames.Add("Raw"); l1tFilter.SupportedTemplateNames.Add("Stretch"); IStringArray l1tProductNames = new StrArrayClass(); l1tProductNames.Add("L1T"); ((IURIProductNameFilter)l1tFilter).ProductNames = l1tProductNames; IItemURIFilter l1rFilter = new URIProductNameFilterClass(); l1rFilter.Name = "L1R"; l1rFilter.SupportsOrthorectification = true; l1rFilter.SupportedTemplateNames = new StrArrayClass(); l1rFilter.SupportedTemplateNames.Add("Raw"); l1rFilter.SupportedTemplateNames.Add("Stretch"); IStringArray l1rProductNames = new StrArrayClass(); l1rProductNames.Add("L1R"); ((IURIProductNameFilter)l1rFilter).ProductNames = l1rProductNames; // Add them to the supported uri filters list ((IRasterTypeProperties)theRasterType).SupportedURIFilters.Add(allFilter); ((IRasterTypeProperties)theRasterType).SupportedURIFilters.Add(l1tFilter); ((IRasterTypeProperties)theRasterType).SupportedURIFilters.Add(l1rFilter); // Set 'All' as default theRasterType.URIFilter = allFilter; #endregion return theRasterType; }
static void Main(string[] args) { ESRI.ArcGIS.esriSystem.AoInitialize aoInit; #region Initialize License try { Console.WriteLine("Obtaining license"); ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); aoInit = new AoInitializeClass(); esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic); Console.WriteLine("Ready with license."); } catch (Exception exc) { // If it fails at this point, shutdown the test and ignore any subsequent errors. Console.WriteLine(exc.Message); return; } #endregion try { #region Specify input directory and dataset name // The directory which contains the Panchromatic Image. string panDir = @"C:\Data\QB\Pan"; // The directory which contains the Multispectral Image. string rgbDir = @"C:\Data\QB\MS"; string panImageName = "05JAN27104436-P1BS-005533787010_01_P002.TIF"; string rgbImageName = "05JAN27104436-M1BS-005533787010_01_P002.TIF"; // Output filename. string outputDataset = @"c:\Temp\QBTemplateCS.afr"; #endregion #region Initialize // Setup Workspaces. Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IRasterWorkspace panRasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(panDir, 0); IRasterWorkspace rgbRasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(rgbDir, 0); // Open Datasets IRasterDataset panDataset = panRasterWorkspace.OpenRasterDataset(panImageName); IRasterDataset rgbDataset = rgbRasterWorkspace.OpenRasterDataset(rgbImageName); #endregion #region Create Variables // Create one variable of type IRasterFunctionVariable for each // Raster Dataset opened above // Create a new Raster Function Variable IRasterFunctionVariable panVar = new RasterFunctionVariableClass(); // Set the name of the variable panVar.Name = "panImage"; // Describe the variable panVar.Description = "Panchromatic Image to be used for pansharpening"; // Specify whether it represents a dataset panVar.IsDataset = true; // Create a new Raster Function Variable IRasterFunctionVariable rgbVar = new RasterFunctionVariableClass(); // Set the name of the variable rgbVar.Name = "rgbImage"; // Describe the variable rgbVar.Description = "Multispectral Image to be used for pansharpening"; // Specify whether it represents a dataset rgbVar.IsDataset = true; #endregion #region Prepare the Pan Image // Setup statistics for each band IArray statsArrayPan = new ArrayClass(); IRasterStatistics statsPanBand = new RasterStatisticsClass(); statsPanBand.Minimum = 1; statsPanBand.Maximum = 2047; statsArrayPan.Add(statsPanBand); // Create the arguments object for the stretching function IStretchFunctionArguments stretchingPanFunctionArguements = new StretchFunctionArgumentsClass(); // Set the stretching type stretchingPanFunctionArguements.StretchType = esriRasterStretchType.esriRasterStretchMinimumMaximum; // Set the statistics created above stretchingPanFunctionArguements.Statistics = statsArrayPan; // Set the input raster, in this case, the variable for the Pan Image stretchingPanFunctionArguements.Raster = panVar; // Create the function object to stretch the Pan Image. IRasterFunction stretchingPanFunction = new StretchFunction(); // Create a Raster Function Template object for the stretch function IRasterFunctionTemplate stretchingPanFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template stretchingPanFunctionT.Function = (IRasterFunction)stretchingPanFunction; // Set the arguments for the function stretchingPanFunctionT.Arguments = stretchingPanFunctionArguements; #endregion #region Prepare the Multispectral (RGB) Image // Create an array which defines the order of bands ILongArray bandIDs = new LongArrayClass(); bandIDs.Add(2); bandIDs.Add(1); bandIDs.Add(0); // Create an Extract Band Function Arguments object IExtractBandFunctionArguments extractRgbBandFunctionArgs = (IExtractBandFunctionArguments) new ExtractBandFunctionArguments(); // Set the order of bands of the output extractRgbBandFunctionArgs.BandIDs = bandIDs; // Set the input raster, in this case the variable for the Multispectral Image extractRgbBandFunctionArgs.Raster = rgbVar; // Create the Extract Band Function object IRasterFunction extractRgbBandFunction = new ExtractBandFunction(); // Create a Raster Function Template object for the function created above IRasterFunctionTemplate extractRgbBandFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template extractRgbBandFunctionT.Function = (IRasterFunction)extractRgbBandFunction; // Set the arguments for the function extractRgbBandFunctionT.Arguments = extractRgbBandFunctionArgs; // Setup statistics for each band IArray statsArray = new ArrayClass(); IRasterStatistics statsMulBand1 = new RasterStatisticsClass(); statsMulBand1.Minimum = 100; statsMulBand1.Maximum = 1721; statsArray.Add(statsMulBand1); IRasterStatistics statsMulBand2 = new RasterStatisticsClass(); statsMulBand2.Minimum = 95; statsMulBand2.Maximum = 2047; statsArray.Add(statsMulBand2); IRasterStatistics statsMulBand3 = new RasterStatisticsClass(); statsMulBand3.Minimum = 34; statsMulBand3.Maximum = 2006; statsArray.Add(statsMulBand3); // Create a stretching function for the multispectral image IRasterFunction stretchingRGBFunction = new StretchFunction(); // Create an arguments object for the stretch function IStretchFunctionArguments stretchingRGBFunctionArguments = new StretchFunctionArgumentsClass(); // Set the type of stretchings to perform stretchingRGBFunctionArguments.StretchType = esriRasterStretchType.esriRasterStretchMinimumMaximum; // Set the statistics created above stretchingRGBFunctionArguments.Statistics = statsArray; // Set the extract band function template created above as the input stretchingRGBFunctionArguments.Raster = extractRgbBandFunctionT; // Create a Raster Function Template object for the function created above IRasterFunctionTemplate stretchingRGBFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template stretchingRGBFunctionT.Function = (IRasterFunction)stretchingRGBFunction; // Set the arguments for the function stretchingRGBFunctionT.Arguments = stretchingRGBFunctionArguments; #endregion #region Pansharpen the Pan Image with the Multispectral // Create a Raster Function Arguments object for the pansharpen function IPansharpeningFunctionArguments pansharpFunctionArguements = new PansharpeningFunctionArgumentsClass(); // Set the Panchromatic image which has been prepared above pansharpFunctionArguements.PanImage = stretchingPanFunctionT; // Set the Multispectral image which has been prepared above pansharpFunctionArguements.MSImage = stretchingRGBFunctionT; // Create a new pansharpen raster function object IRasterFunction pansharpenFunction = new PansharpeningFunction(); // Create a new pansharpen function arguments object IPansharpeningFunctionArguments pansharpenFunctionArguements = new PansharpeningFunctionArgumentsClass(); // Set the pansharpening type pansharpenFunctionArguements.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI; // Create an array of doubles that sets the weights for each band IDoubleArray weightsArray = new DoubleArrayClass(); weightsArray.Add(0.167); weightsArray.Add(0.166); weightsArray.Add(0.166); // and set it on the arguments object pansharpenFunctionArguements.Weights = weightsArray; // Create a Raster Function Template object for the pansharpen function IRasterFunctionTemplate rasterFunction = new RasterFunctionTemplateClass(); rasterFunction.Function = (IRasterFunction)pansharpenFunction; rasterFunction.Arguments = pansharpFunctionArguements; ((IRasterFunction)rasterFunction).PixelType = rstPixelType.PT_UCHAR; #endregion #region Resolve variables // Create a PropertySet object to set the values for the // Raster Function Variables created above IPropertySet variables = new PropertySet(); variables.SetProperty("panImage", panDataset); variables.SetProperty("rgbImage", rgbDataset); #endregion #region Create the Function Raster Dataset // Create the Function Raster Dataset Object for the Pansharpened Dataset IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset(); // Create a name object for the Function Raster Dataset. IFunctionRasterDatasetName functionRasterDatasetName = new FunctionRasterDatasetNameClass(); // Specify the output filename for the new dataset (including // the .afr extension at the end). functionRasterDatasetName.FullName = outputDataset; functionRasterDataset.FullName = (IName)functionRasterDatasetName; // Initialize the new Function Raster Dataset with the Raster Function // Template and the property set containing the variables and their values. functionRasterDataset.Init((IRasterFunction)rasterFunction, variables); ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset; myTempDset.MakePermanent(); #endregion #region Shutdown Console.WriteLine("Success."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } catch (Exception exc) { #region Shutdown Console.WriteLine("Exception Caught while creating Function Raster Dataset. " + exc.Message); Console.WriteLine("Failed."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } }
public static IRasterFunctionTemplate CreateNDVICustomTemplate(string bandIndices) { #region Setup Raster Function Vars IRasterFunctionVariable watermarkRasterRFV = new RasterFunctionVariableClass(); watermarkRasterRFV.Name = "Raster"; watermarkRasterRFV.IsDataset = true; IRasterFunctionVariable bandIndicesRFV = new RasterFunctionVariableClass(); bandIndicesRFV.Name = "BandIndices"; bandIndicesRFV.Value = bandIndices; bandIndicesRFV.IsDataset = false; #endregion #region Setup Raster Function Template // Create the NDVI Custom Function Arguments object IRasterFunctionArguments rasterFunctionArguments = new CustomFunction.NDVICustomFunctionArguments(); // Set the Band Indices rasterFunctionArguments.PutValue("BandIndices", bandIndicesRFV); // Set the Raster Dataset as the input raster rasterFunctionArguments.PutValue("Raster", watermarkRasterRFV); // Create the NDVI Custom Function IRasterFunction ndviCustomFunction = new CustomFunction.NDVICustomFunction(); IRasterFunctionTemplate ndviCustomFunctionTemplate = new RasterFunctionTemplateClass(); ndviCustomFunctionTemplate.Function = ndviCustomFunction; ndviCustomFunctionTemplate.Arguments = rasterFunctionArguments; #endregion return ndviCustomFunctionTemplate; }
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; }
static void Main(string[] args) { ESRI.ArcGIS.esriSystem.AoInitialize aoInit; #region Initialize License try { Console.WriteLine("Obtaining license"); ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); aoInit = new AoInitializeClass(); esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic); Console.WriteLine("Ready with license."); } catch (Exception exc) { // If it fails at this point, shutdown the test and ignore any subsequent errors. Console.WriteLine(exc.Message); return; } #endregion try { #region Specify input directory and dataset name // The directory which contains the Panchromatic Image. string panDir = @"C:\Data\QB\Pan"; // The directory which contains the Multispectral Image. string rgbDir = @"C:\Data\QB\MS"; string panImageName = "05JAN27104436-P1BS-005533787010_01_P002.TIF"; string rgbImageName = "05JAN27104436-M1BS-005533787010_01_P002.TIF"; // Output filename. string outputDataset = @"c:\Temp\QBTemplateCS.afr"; #endregion #region Initialize // Setup Workspaces. Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IRasterWorkspace panRasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(panDir, 0); IRasterWorkspace rgbRasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(rgbDir, 0); // Open Datasets IRasterDataset panDataset = panRasterWorkspace.OpenRasterDataset(panImageName); IRasterDataset rgbDataset = rgbRasterWorkspace.OpenRasterDataset(rgbImageName); #endregion #region Create Variables // Create one variable of type IRasterFunctionVariable for each // Raster Dataset opened above // Create a new Raster Function Variable IRasterFunctionVariable panVar = new RasterFunctionVariableClass(); // Set the name of the variable panVar.Name = "panImage"; // Describe the variable panVar.Description = "Panchromatic Image to be used for pansharpening"; // Specify whether it represents a dataset panVar.IsDataset = true; // Create a new Raster Function Variable IRasterFunctionVariable rgbVar = new RasterFunctionVariableClass(); // Set the name of the variable rgbVar.Name = "rgbImage"; // Describe the variable rgbVar.Description = "Multispectral Image to be used for pansharpening"; // Specify whether it represents a dataset rgbVar.IsDataset = true; #endregion #region Prepare the Pan Image // Setup statistics for each band IArray statsArrayPan = new ArrayClass(); IRasterStatistics statsPanBand = new RasterStatisticsClass(); statsPanBand.Minimum = 1; statsPanBand.Maximum = 2047; statsArrayPan.Add(statsPanBand); // Create the arguments object for the stretching function IStretchFunctionArguments stretchingPanFunctionArguements = new StretchFunctionArgumentsClass(); // Set the stretching type stretchingPanFunctionArguements.StretchType = esriRasterStretchType.esriRasterStretchMinimumMaximum; // Set the statistics created above stretchingPanFunctionArguements.Statistics = statsArrayPan; // Set the input raster, in this case, the variable for the Pan Image stretchingPanFunctionArguements.Raster = panVar; // Create the function object to stretch the Pan Image. IRasterFunction stretchingPanFunction = new StretchFunction(); // Create a Raster Function Template object for the stretch function IRasterFunctionTemplate stretchingPanFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template stretchingPanFunctionT.Function = (IRasterFunction)stretchingPanFunction; // Set the arguments for the function stretchingPanFunctionT.Arguments = stretchingPanFunctionArguements; #endregion #region Prepare the Multispectral (RGB) Image // Create an array which defines the order of bands ILongArray bandIDs = new LongArrayClass(); bandIDs.Add(2); bandIDs.Add(1); bandIDs.Add(0); // Create an Extract Band Function Arguments object IExtractBandFunctionArguments extractRgbBandFunctionArgs = (IExtractBandFunctionArguments) new ExtractBandFunctionArguments(); // Set the order of bands of the output extractRgbBandFunctionArgs.BandIDs = bandIDs; // Set the input raster, in this case the variable for the Multispectral Image extractRgbBandFunctionArgs.Raster = rgbVar; // Create the Extract Band Function object IRasterFunction extractRgbBandFunction = new ExtractBandFunction(); // Create a Raster Function Template object for the function created above IRasterFunctionTemplate extractRgbBandFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template extractRgbBandFunctionT.Function = (IRasterFunction)extractRgbBandFunction; // Set the arguments for the function extractRgbBandFunctionT.Arguments = extractRgbBandFunctionArgs; // Setup statistics for each band IArray statsArray = new ArrayClass(); IRasterStatistics statsMulBand1 = new RasterStatisticsClass(); statsMulBand1.Minimum = 100; statsMulBand1.Maximum = 1721; statsArray.Add(statsMulBand1); IRasterStatistics statsMulBand2 = new RasterStatisticsClass(); statsMulBand2.Minimum = 95; statsMulBand2.Maximum = 2047; statsArray.Add(statsMulBand2); IRasterStatistics statsMulBand3 = new RasterStatisticsClass(); statsMulBand3.Minimum = 34; statsMulBand3.Maximum = 2006; statsArray.Add(statsMulBand3); // Create a stretching function for the multispectral image IRasterFunction stretchingRGBFunction = new StretchFunction(); // Create an arguments object for the stretch function IStretchFunctionArguments stretchingRGBFunctionArguments = new StretchFunctionArgumentsClass(); // Set the type of stretchings to perform stretchingRGBFunctionArguments.StretchType = esriRasterStretchType.esriRasterStretchMinimumMaximum; // Set the statistics created above stretchingRGBFunctionArguments.Statistics = statsArray; // Set the extract band function template created above as the input stretchingRGBFunctionArguments.Raster = extractRgbBandFunctionT; // Create a Raster Function Template object for the function created above IRasterFunctionTemplate stretchingRGBFunctionT = new RasterFunctionTemplateClass(); // Set the function on the template stretchingRGBFunctionT.Function = (IRasterFunction)stretchingRGBFunction; // Set the arguments for the function stretchingRGBFunctionT.Arguments = stretchingRGBFunctionArguments; #endregion #region Pansharpen the Pan Image with the Multispectral // Create a Raster Function Arguments object for the pansharpen function IPansharpeningFunctionArguments pansharpFunctionArguements = new PansharpeningFunctionArgumentsClass(); // Set the Panchromatic image which has been prepared above pansharpFunctionArguements.PanImage = stretchingPanFunctionT; // Set the Multispectral image which has been prepared above pansharpFunctionArguements.MSImage = stretchingRGBFunctionT; // Create a new pansharpen raster function object IRasterFunction pansharpenFunction = new PansharpeningFunction(); // Create a new pansharpen function arguments object IPansharpeningFunctionArguments pansharpenFunctionArguements = new PansharpeningFunctionArgumentsClass(); // Set the pansharpening type pansharpenFunctionArguements.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI; // Create an array of doubles that sets the weights for each band IDoubleArray weightsArray = new DoubleArrayClass(); weightsArray.Add(0.167); weightsArray.Add(0.166); weightsArray.Add(0.166); // and set it on the arguments object pansharpenFunctionArguements.Weights = weightsArray; // Create a Raster Function Template object for the pansharpen function IRasterFunctionTemplate rasterFunction = new RasterFunctionTemplateClass(); rasterFunction.Function = (IRasterFunction)pansharpenFunction; rasterFunction.Arguments = pansharpFunctionArguements; ((IRasterFunction)rasterFunction).PixelType = rstPixelType.PT_UCHAR; #endregion #region Resolve variables // Create a PropertySet object to set the values for the // Raster Function Variables created above IPropertySet variables = new PropertySet(); variables.SetProperty("panImage", panDataset); variables.SetProperty("rgbImage", rgbDataset); #endregion #region Create the Function Raster Dataset // Create the Function Raster Dataset Object for the Pansharpened Dataset IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset(); // Create a name object for the Function Raster Dataset. IFunctionRasterDatasetName functionRasterDatasetName = new FunctionRasterDatasetNameClass(); // Specify the output filename for the new dataset (including // the .afr extension at the end). functionRasterDatasetName.FullName = outputDataset; functionRasterDataset.FullName = (IName)functionRasterDatasetName; // Initialize the new Function Raster Dataset with the Raster Function // Template and the property set containing the variables and their values. functionRasterDataset.Init((IRasterFunction)rasterFunction, variables); ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset; myTempDset.MakePermanent(); #endregion #region Shutdown Console.WriteLine("Success."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } catch (Exception exc) { #region Shutdown Console.WriteLine("Exception Caught while creating Function Raster Dataset. " + exc.Message); Console.WriteLine("Failed."); Console.WriteLine("Press any key..."); Console.ReadKey(); // Shutdown License aoInit.Shutdown(); #endregion } }