/// <summary>
        /// Create the function raster dataset from the source images.
        /// </summary>
        /// <param name="dimPar">Parser for the dimap file.</param>
        /// <param name="pItemURI">ItemURi to use.</param>
        /// <returns>Function raster dataset created.</returns>
        private IFunctionRasterDataset GetFRD(DiMapParser dimPar, IItemURI pItemURI)
        {
            IFunctionRasterDataset opFrd = null;
            try
            {
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace workspace = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(pItemURI.Key), 0);
                IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspace;
                // Open the tif file associated with the .dim file as a raster dataset.
                string imagePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(pItemURI.Key),
                    pItemURI.Group + ".tif");
                string rpcPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(pItemURI.Key),
                    pItemURI.Group + ".rpc");
                IRasterDataset inputRasterDataset = null;
                if (File.Exists(imagePath))
                    inputRasterDataset = rasterWorkspace.OpenRasterDataset(pItemURI.Group + ".tif");
                else
                    return null;

                IFunctionRasterDataset intermedFrd = null;
                // If the file opes successfully, add a RasterInfo function on top.
                if (inputRasterDataset != null)
                {
                    // Create an Identity function dataset to get the raster info.
                    IRasterFunction identityFunction = new IdentityFunctionClass();
                    IFunctionRasterDataset idFrd = new FunctionRasterDatasetClass();
                    idFrd.Init(identityFunction, inputRasterDataset);
                    // Create a raster info function dataset.
                    IRasterFunction rasterInfoFunction = new RasterInfoFunctionClass();
                    IRasterInfoFunctionArguments rasterInfoFuncArgs = new RasterInfoFunctionArgumentsClass();
                    rasterInfoFuncArgs.Raster = inputRasterDataset;
                    rasterInfoFuncArgs.RasterInfo = idFrd.RasterInfo;
                    intermedFrd = new FunctionRasterDatasetClass();
                    intermedFrd.Init(rasterInfoFunction, rasterInfoFuncArgs);
                }
                else
                    return null;
                // Check if there is an RPC file associated with the image. If so
                // then add a geometric function to apply the rpc xform.
                if (File.Exists(rpcPath))
                    opFrd = ApplyRPC(rpcPath, (IRasterDataset)intermedFrd);

                // If no rpc pars exist or applying rpc fails, use the intermediate 
                // function raster dataset created.
                if (opFrd == null)
                    opFrd = intermedFrd;
                
                //IRasterFunction ebFunction = new ExtractBandFunctionClass();
                //IRasterFunctionArguments ebFuncArgs = new ExtractBandFunctionArgumentsClass();
                //ILongArray bandIDs = new LongArrayClass();
                //bandIDs.Add(2);
                //bandIDs.Add(1);
                //bandIDs.Add(0);
                ////bandIDs.Add(4);
                //((IExtractBandFunctionArguments)ebFuncArgs).BandIDs = bandIDs;
                //((IExtractBandFunctionArguments)ebFuncArgs).Raster = inputRasterDataset;
                //opFrd = new FunctionRasterDatasetClass();
                //opFrd.Init(ebFunction, ebFuncArgs);

                //if (opFrd == null)
                //{
                //    IRasterFunction identityFunction = new IdentityFunctionClass();
                //    opFrd = new FunctionRasterDatasetClass();
                //    opFrd.Init(identityFunction, inputRasterDataset);
                //}
            }
            catch (Exception exc)
            {
                string error = exc.Message;
            }
            return opFrd;
        }
        /// <summary>
        /// Parse the RPC parameters file associated with the image and create an RPCXform
        /// to bea applied to the inputDataset as a geomtric function.
        /// </summary>
        /// <param name="rpcPath">Path to the rpc parameters file.</param>
        /// <param name="inputDataset">Input dataset to apply the xform on.</param>
        /// <returns>Function raster dataset created.</returns>
        private IFunctionRasterDataset ApplyRPC(string rpcPath, IRasterDataset inputDataset)
        {
            IFunctionRasterDataset opFrd = null;
            try
            {
                // Open the RPC file and create Geometric transform
                IGeodataXform finalXForm = null;
                IRPCXform rpcXForm = GetRPCXForm(rpcPath);

                IFunctionRasterDataset idFrd = null;
                if (!(inputDataset is IFunctionRasterDataset))
                {
                    IRasterFunction identityFunction = new IdentityFunctionClass();
                    idFrd = new FunctionRasterDatasetClass();
                    idFrd.Init(identityFunction, inputDataset);
                }
                else
                    idFrd = (IFunctionRasterDataset)inputDataset;

                IRasterInfo datasetRasterInfo = idFrd.RasterInfo;
                IEnvelope datasetExtent = datasetRasterInfo.Extent;
                ISpatialReference datasetSrs = ((IGeoDataset)idFrd).SpatialReference;

                long dRows = datasetRasterInfo.Height;
                long dCols = datasetRasterInfo.Width;
                IEnvelope pixelExtent = new EnvelopeClass();
                pixelExtent.PutCoords(-0.5, 0.5 - dRows, -0.5 + dCols, 0.5);

                bool noAffineNeeded = ((IClone)pixelExtent).IsEqual((IClone)datasetExtent);
                if (!noAffineNeeded)
                {
                    // Tranform ground space to pixel space.
                    IAffineTransformation2D affineXform = new AffineTransformation2DClass();
                    affineXform.DefineFromEnvelopes(datasetExtent, pixelExtent);
                    IGeometricXform geoXform = new GeometricXformClass();
                    geoXform.Transformation = affineXform;
                    finalXForm = geoXform;
                }

                // Transform from pixel space back to ground space to set as the forward transform.
                IEnvelope groundExtent = ((IGeoDataset)idFrd).Extent;
                groundExtent.Project(datasetSrs);
                IAffineTransformation2D affineXform2 = new AffineTransformation2DClass();
                affineXform2.DefineFromEnvelopes(pixelExtent, groundExtent);
                IGeometricXform forwardXForm = new GeometricXformClass();
                forwardXForm.Transformation = affineXform2;
                rpcXForm.ForwardXform = forwardXForm;

                // Create the composite transform that changes ground values to pixel space
                // then applies the rpc transform which will transform them back to ground space.
                ICompositeXform compositeXForm = new CompositeXformClass();
                compositeXForm.Add(finalXForm);
                compositeXForm.Add(rpcXForm);
                finalXForm = (IGeodataXform)compositeXForm;

                // Then apply the transform on the raster using the geometric function.
                if (finalXForm != null)
                {
                    IRasterFunction geometricFunction = new GeometricFunctionClass();
                    IGeometricFunctionArguments geometricFunctionArgs = null;
                    // Get the geomtric function arguments if supplied by the user (in the UI).
                    if (myRasterTypeOperation != null &&
                        ((IRasterTypeProperties)myRasterTypeOperation).OrthorectificationParameters != null)
                        geometricFunctionArgs =
                        ((IRasterTypeProperties)myRasterTypeOperation).OrthorectificationParameters;
                    else
                        geometricFunctionArgs = new GeometricFunctionArgumentsClass();
                    // Append the xform to the existing ones from the image.
                    geometricFunctionArgs.AppendGeodataXform = true;
                    geometricFunctionArgs.GeodataXform = finalXForm;
                    geometricFunctionArgs.Raster = inputDataset;
                    opFrd = new FunctionRasterDatasetClass();
                    opFrd.Init(geometricFunction, geometricFunctionArgs);
                }
                return opFrd;
            }
            catch (Exception exc)
            {
                string error = exc.Message;
                return opFrd;
            }
        }
 public IFunctionRasterDataset createIdentityRaster(object inRaster,rstPixelType pType)
 {
     if (inRaster == null)
     {
         return null;
     }
     else
     {
         IFunctionRasterDataset trd = createIdentityRaster(inRaster);
         IRasterFunction rsFunc = new IdentityFunctionClass();
         rsFunc.Bind(trd);
         string tempAr = funcDir + "\\" + FuncCnt + ".afr";
         IFunctionRasterDataset frDset = new FunctionRasterDatasetClass();
         IFunctionRasterDatasetName frDsetName = new FunctionRasterDatasetNameClass();
         frDsetName.FullName = tempAr;
         frDset.FullName = (IName)frDsetName;
         rsFunc.PixelType = pType;
         //rsFunc.Update();
         frDset.Init(rsFunc, trd);
         return frDset;
     }
 }