Пример #1
0
        /// <summary>
        /// 读取栅格数据。
        /// </summary>
        public static float[,] ReadRaster(IRasterLayer rasterLayer, float nullValue)
        {
            int columnCount = rasterLayer.ColumnCount;
            int rowCount    = rasterLayer.RowCount;

            IRaster2 raster  = rasterLayer.Raster as IRaster2;
            IPnt     fromPnt = new PntClass();

            fromPnt.SetCoords(0, 0);
            IPnt blockSize = new PntClass();

            blockSize.SetCoords(columnCount, rowCount);
            IPixelBlock pixedBlock = ((IRaster)raster).CreatePixelBlock(blockSize);

            rasterLayer.Raster.Read(fromPnt, pixedBlock);

            float[,] data = new float[rowCount, columnCount];

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    object value = pixedBlock.GetVal(0, j, i);
                    if (value != null)
                    {
                        data[i, j] = Convert.ToSingle(value);
                    }
                    else
                    {
                        data[i, j] = nullValue;
                    }
                }
            }
            return(data);
        }
Пример #2
0
        //public IFeatureClass createPolygons3()
        //{
        //    createFeatureClass();

        //}
        public IFeatureClass createPolygons2()
        {
            createFeatureClass();
            IRasterProps           rsProp   = (IRasterProps)inputRaster;
            int                    bndCnt   = ((IRasterBandCollection)inputRaster).Count;
            IPnt                   rsPnt    = rsProp.MeanCellSize();
            double                 cellArea = rsPnt.X * rsPnt.Y;
            double                 tCells   = minArea / cellArea;
            IFunctionRasterDataset sDset    = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells);

            FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function;
            IRaster2               rs2   = (IRaster2)rsUtil.createRaster(sDset);
            IRasterCursor          rsCur = rs2.CreateCursorEx(null);
            IRasterDomainExtractor dExt  = new RasterDomainExtractorClass();

            do
            {
                IPixelBlock            pb     = rsCur.PixelBlock;
                IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset);
                IRaster rs          = rsUtil.createRaster(pbDset);
                int     numClusters = rFunc.NumClusters;
                for (int c = 0; c < numClusters; c++)
                {
                    IFunctionRasterDataset fd  = rsUtil.calcEqualFunction(pbDset, c);
                    IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0);
                    IPolygon polys             = dExt.ExtractDomain(rsUtil.createRaster(fd2), true);
                }
            } while (rsCur.Next() == true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);



            return(outftr);
        }
Пример #3
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.


                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IRaster mosRs   = (IRaster)mos;
                IPnt    pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
                IPixelBlock pb = mosRs.CreatePixelBlock(pntSize);
                mosRs.Read(pTlc, pb);
                for (int i = 0; i < pb.Planes; i++)
                {
                    pPixelBlock.set_SafeArray(i, pb.get_SafeArray(i));
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of mosaic Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
Пример #4
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int  pBHeight = pPixelBlock.Height;
         int  pBWidth  = pPixelBlock.Width;
         IPnt pbSize   = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb);
         IPixelBlock3          outPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array          outArr        = (System.Array)outPixelBlock.get_PixelData(0);
         System.Array[]        inArr         = new System.Array[inrs.RasterInfo.BandCount];
         IRasterBandCollection rsBc          = (IRasterBandCollection)inrs;
         for (int b = 0; b < inrs.RasterInfo.BandCount; b++)
         {
             IRasterBand rsB  = rsBc.Item(b);
             IRawPixels  rPix = (IRawPixels)rsB;
             IPixelBlock pb   = rPix.CreatePixelBlock(pbSize);
             rPix.Read(pTlc, pb);
             inArr[b] = (System.Array)pb.get_SafeArray(b);
         }
         updateOutArr(outPixelBlock, inArr, outArr);
         outPixelBlock.set_PixelData(0, outArr);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #5
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.


                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IRaster2     rs2 = (IRaster2)pRaster;
                double       pX, pY;
                rs2.PixelToMap(System.Convert.ToInt32(pTlc.X), System.Convert.ToInt32(pTlc.Y), out pX, out pY);
                //Console.WriteLine("After Read");
                int       pBHeight = pPixelBlock.Height;
                int       pBWidth  = pPixelBlock.Width;
                IEnvelope env      = new EnvelopeClass();
                env.PutCoords(pX, pY - pBHeight, pX + pBWidth, pY);
                updateWithMergedValues(env, ipPixelBlock);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of merge Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
Пример #6
0
        private void adjustXTableRst(IGeometry iGeometry)
        {
            double        tN    = 0;
            IRaster       rs    = rsUtil.createRaster(rsUtil.clipRasterFunction(rstMap, iGeometry, ESRI.ArcGIS.DataSourcesRaster.esriRasterClippingType.esriRasterClippingOutside));
            IRasterCursor rsCur = ((IRaster2)rs).CreateCursorEx(null);

            while (rsCur.Next())
            {
                IPixelBlock pb = rsCur.PixelBlock;
                for (int r = 0; r < pb.Height; r++)
                {
                    for (int c = 0; c < pb.Width; c++)
                    {
                        object vlObj = pb.GetVal(0, c, r);
                        if (vlObj == null)
                        {
                            continue;
                        }
                        else
                        {
                            string vl      = vlObj.ToString();
                            int    vlIndex = olabels.IndexOf(vl);
                            nCnts[vlIndex] = nCnts[vlIndex] + 1;
                            tN            += 1;
                        }
                    }
                }
            }
            updateXTable(tN);
        }
Пример #7
0
        /// <summary>
        /// Get the pixel values in a region of the input raster.
        /// </summary>
        /// <param name="tlCorner"></param>
        /// <param name="brCorner"></param>
        /// <param name="raster"></param>
        /// <returns></returns>
        public static double[,] GetValues(Position tlCorner, Position brCorner, IRaster raster)
        {
            int colCount = brCorner.Column - tlCorner.Column + 1;
            int rowCount = brCorner.Row - tlCorner.Row + 1;

            IPnt regionSize = new PntClass();

            regionSize.SetCoords(colCount, rowCount);
            IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
            IPnt        tl         = new PntClass();

            tl.SetCoords(tlCorner.Column, tlCorner.Row);
            raster.Read(tl, pixelBlock);

            double[,] values = new double[colCount, rowCount];
            for (int x = 0; x < colCount; x++)
            {
                for (int y = 0; y < rowCount; y++)
                {
                    Pixel cell = Editor.Edits[x + tlCorner.Column, y + tlCorner.Row];

                    if (cell == null)
                    {
                        values[x, y] = Convert.ToDouble(pixelBlock.GetVal(0, x, y));
                    }
                    else
                    {
                        values[x, y] = cell.NewValue;
                    }
                }
            }
            return(values);
        }
Пример #8
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int  pBHeight = pPixelBlock.Height;
                int  pBWidth  = pPixelBlock.Width;
                IPnt pbSize   = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)inrsBandsCoef.CreatePixelBlock(pbSize);//independent variables
                inrsBandsCoef.Read(pTlc, (IPixelBlock)outPb);
                int          pBRowIndex   = 0;
                int          pBColIndex   = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                System.Array pValues = (System.Array)ipPixelBlock.get_PixelData(0);//(System.Array)(td);
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] xVls = new double[outPb.Planes];
                        bool     ndT  = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(coefnBand));
                            object pObj = outPb.GetVal(coefnBand, k, i);

                            if (pObj == null)
                            {
                                ndT = false;
                                break;
                            }
                            float pixelValue = Convert.ToSingle(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            int c = cluster.computNew(xVls);
                            pValues.SetValue(c, k, i);
                        }
                    }
                }
                ipPixelBlock.set_PixelData(0, pValues);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Cluster Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
Пример #9
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            //try
            //{
            //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
            myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
            int          pBHeight = pPixelBlock.Height;
            int          pBWidth = pPixelBlock.Width;
            IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
            IPnt         pbBigSize = new PntClass();
            IPnt         pbBigLoc = new PntClass();
            int          pbBigWd = pBWidth + clms - 1;
            int          pbBigHt = pBHeight + rws - 1;
            int          l, t;

            l = clms / 2;
            t = rws / 2;
            //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
            pbBigSize.SetCoords(pbBigWd, pbBigHt);
            pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
            IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);

            myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
            updatePixelRectangle(ipPixelBlock, pbBig);
            //}
            //catch (Exception e)
            //{
            //Console.WriteLine(e.ToString());
            //System.Windows.Forms.MessageBox.Show(e.ToString());
            //Console.WriteLine(pTlc.X.ToString() + ":" + pTlc.Y.ToString());

            //}
        }
Пример #10
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;
         IRaster2     inRs2 = (IRaster2)inrs;
         IRaster2     outRs2 = (IRaster2)outrs;
         double       mx, my;
         outRs2.PixelToMap((int)pTlc.X, (int)pTlc.Y, out mx, out my);
         int clm, rw;
         inRs2.MapToPixel(mx, my, out clm, out rw);
         IPnt pntLoc  = new PntClass();
         pntLoc.SetCoords(clm, rw);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
         IPixelBlock3 pBIn = (IPixelBlock3)inrs.CreatePixelBlock(pntSize);
         inrs.Read(pntLoc, (IPixelBlock)pBIn);
         for (int p = 0; p < pPixelBlock.Planes; p++)
         {
             pPixelBlock3.set_PixelData(p, pBIn.get_PixelData(p));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #11
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            double vl         = 0;
            float  pixelValue = 0f;

            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
                #region Load log object
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    float        noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                    System.Array dArr        = (System.Array)pb3.get_PixelData(nBand);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            vl = System.Convert.ToDouble(dArr.GetValue(c, r));
                            if (rasterUtil.isNullData(System.Convert.ToSingle(vl), noDataValue))
                            {
                                continue;
                            }
                            pixelValue = System.Convert.ToSingle(getFunctionValue(vl));
                            dArr.SetValue(pixelValue, c, r);
                        }
                    }
                    pb3.set_PixelData(nBand, dArr);
                    //unsafe
                    //{
                    //    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    //    int lng = dArr.Length;
                    //    fixed (float* dValue = (float[,])dArr)
                    //    {
                    //        for (int i = 0; i < lng; i++)
                    //        {
                    //            pixelValue = *(dValue + i);
                    //            if (rasterUtil.isNullData(pixelValue, noDataValue))
                    //            {
                    //                continue;
                    //            }
                    //            pixelValue = System.Convert.ToSingle(getFunctionValue(pixelValue));
                    //            *(dValue + i) = pixelValue;

                    //        }
                    //        pb3.set_PixelData(nBand, dArr);
                    //    }
                    //}
                }
                #endregion
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
                throw myExc;
            }
        }
Пример #12
0
        private void updateWithMergedValues(IEnvelope env, IPixelBlock3 ipPixelBlock)
        {
            System.Array[]        outPixelValuesArr   = new System.Array[ipPixelBlock.Planes];
            List <System.Array[]> inPixelValuesArrLst = new List <System.Array[]>();
            List <System.Array>   inPixelNoDataArrLst = new List <System.Array>();
            IPnt pntSize = new PntClass();

            pntSize.SetCoords(ipPixelBlock.Width, ipPixelBlock.Height);
            ISpatialFilter spFlt = new SpatialFilterClass();

            spFlt.Geometry      = (IGeometry)env;
            spFlt.GeometryField = ftrCls.ShapeFieldName;
            spFlt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelOverlaps;
            IFeatureCursor fCur   = ftrCls.Search(spFlt, false);
            int            fIndex = ftrCls.FindField("catIndex");
            IFeature       ftr    = fCur.NextFeature();

            for (int i = 0; i < ipPixelBlock.Planes; i++)
            {
                outPixelValuesArr[i] = (System.Array)ipPixelBlock.get_PixelData(i);
            }
            while (ftr != null)
            {
                int         rsIndex = System.Convert.ToInt32(ftr.get_Value(fIndex));
                IRaster     rs = inrs[rsIndex];
                IPixelBlock inputPb = rs.CreatePixelBlock(pntSize);
                IRaster2    rs2 = (IRaster2)rs;
                int         pClm, pRw;
                rs2.MapToPixel(env.XMin, env.YMax, out pClm, out pRw);
                IPnt tlc = new PntClass();
                tlc.SetCoords(pClm, pRw);
                rs.Read(tlc, inputPb);
                System.Array[] inPixelValuesArr = new System.Array[inputPb.Planes];
                for (int i = 0; i < inputPb.Planes; i++)
                {
                    inPixelValuesArr[i] = (System.Array)inputPb.get_SafeArray(i);
                }
                inPixelNoDataArrLst.Add((System.Array)((IRasterProps)rs).NoDataValue);
                inPixelValuesArrLst.Add(inPixelValuesArr);
                ftr = fCur.NextFeature();
            }
            for (int i = 0; i < outPixelValuesArr.Length; i++)
            {
                for (int r = 0; r < ipPixelBlock.Height; r++)
                {
                    for (int c = 0; c < ipPixelBlock.Width; c++)
                    {
                        double vl = getValue(i, c, r, inPixelValuesArrLst, inPixelNoDataArrLst);
                        outPixelValuesArr[i].SetValue(vl, c, r);
                    }
                }
            }
            for (int i = 0; i < outPixelValuesArr.Length; i++)
            {
                ipPixelBlock.set_PixelData(i, outPixelValuesArr[i]);
            }
        }
Пример #13
0
        public void Filter(IPixelBlock pPixelBlock)
        {
            try
            {
                IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;

                byte[] lookup = new byte[8] {
                    128, 64, 32, 16, 8, 4, 2, 1
                };

                //get number of bands
                int plane = pPixelBlock.Planes;

                //loop through each band
                for (int i = 0; i < plane; i++)
                {
                    //get nodata mask array
                    byte[] outputArray = (byte[])pPixelBlock3.get_NoDataMaskByRef(i);

                    //loop through each pixel in the pixelblock and do calculation
                    for (int x = 0; x < pPixelBlock.Width; x++)
                    {
                        for (int y = 0; y < pPixelBlock.Height; y++)
                        {
                            //get index in the nodata mask byte array
                            int ind = x + y * (pPixelBlock.Width);

                            //get nodata mask byte
                            byte nd = outputArray[ind / 8];

                            //get pixel value and check if it is nodata
                            object tempVal = pPixelBlock3.GetVal(i, x, y);

                            if (tempVal != null) //not nodata pixel
                            {
                                //convert pixel value to int and compare with nodata range

                                int curVal = Convert.ToInt32(tempVal);
                                if (curVal >= minNodataValue && curVal <= maxNodataValue)
                                {
                                    outputArray[ind / 8] = (byte)(nd & ~lookup[ind % 8]);
                                }
                            }
                        }
                    }
                    //set nodata mask array
                    pPixelBlock3.set_NoDataMask(i, outputArray);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #14
0
        //获取最大最小栅格值
        private void SetMaxMinValue(int flag)
        {
            if (flag == 1)
            {
                textBoxMax.Text = "高:255";
                textBoxMin.Text = "低:0";
                return;
            }
            uint valueMax = 50;
            uint valueMin = 50;

            IRasterLayer pRasterLayer = m_layer as IRasterLayer;
            IRaster      pRaster      = pRasterLayer.Raster;
            IRasterProps pRasterProps = pRaster as IRasterProps;
            int          Height       = pRasterProps.Height;
            int          Width        = pRasterProps.Width;
            double       dX           = pRasterProps.MeanCellSize().X;
            double       dY           = pRasterProps.MeanCellSize().Y; //栅格的高度
            IEnvelope    extent       = pRasterProps.Extent;           //当前栅格数据集的范围
            rstPixelType pixelType    = pRasterProps.PixelType;        //当前栅格像素类型
            IPnt         pntSize      = new PntClass();

            pntSize.SetCoords(dX, dY);


            IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize);
            IPnt        pnt        = new PntClass();

            for (int i = 0; i < Height; i += 10)
            {
                for (int j = 0; j < Width; j += 10)
                {
                    pnt.SetCoords(i, j);
                    pRaster.Read(pnt, pixelBlock);
                    if (pixelBlock != null)
                    {
                        object obj  = pixelBlock.GetVal(0, 0, 0);
                        uint   temp = Convert.ToUInt32(obj);

                        if (temp > valueMax)
                        {
                            valueMax = temp;
                        }
                        else if (temp < valueMin)
                        {
                            valueMin = temp;
                        }
                    }
                }
            }
            textBoxMax.Text = "高:" + valueMax.ToString();
            textBoxMin.Text = "低:" + valueMin.ToString();
        }
Пример #15
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int          pBHeight = pPixelBlock.Height;
         int          pBWidth = pPixelBlock.Width;
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         IPnt         pbBigSize = new PntClass();
         IPnt         pbBigLoc = new PntClass();
         int          pbBigWd = pBWidth + clms;
         int          pbBigHt = pBHeight + rws;
         int          l, t;
         l = (clms - 1) / 2;
         t = (rws - 1) / 2;
         //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
         pbBigSize.SetCoords(pbBigWd, pbBigHt);
         pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
         IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
         myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
         for (int nBand = 0; nBand < pbBig.Planes; nBand++)
         {
             System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
             rstPixelType rsp         = ipPixelBlock.get_PixelType(nBand);
             //System.Array pixelValuesBig = (System.Array)(pbBig.get_PixelData(nBand));
             for (int r = 0; r < pBHeight; r++)
             {
                 for (int c = 0; c < pBWidth; c++)
                 {
                     object objVl = ipPixelBlock.GetVal(nBand, c, r);
                     if (objVl == null)
                     {
                         continue;
                     }
                     else
                     {
                         float  outVl = System.Convert.ToSingle(getTransformedValue(pbBig, c + l, r + t, nBand));
                         object newVl = rasterUtil.getSafeValue(outVl, rsp);
                         //Console.WriteLine(outVl.ToString());
                         pixelValues.SetValue(newVl, c, r);
                     }
                 }
             }
             ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #16
0
        /// <summary>
        /// 读取数据并记录非空数据的行列号。
        /// </summary>
        public static float[,] ReadRasterAndGetNotNullRowColumn(IRasterLayer rasterLayer, out StructRasterMetaData structRasterMetaData,
                                                                out List <int> notNullRows, out List <int> notNullColumns)
        {
            int rowCount, columnCount;

            notNullRows    = new List <int>();
            notNullColumns = new List <int>();

            structRasterMetaData.ColumnCount = rasterLayer.ColumnCount;
            columnCount = structRasterMetaData.ColumnCount;
            structRasterMetaData.RowCount = rasterLayer.RowCount;
            rowCount = structRasterMetaData.RowCount;

            IEnvelope visiableExtent = rasterLayer.VisibleExtent;

            structRasterMetaData.XMin        = visiableExtent.XMin;
            structRasterMetaData.XMax        = visiableExtent.XMax;
            structRasterMetaData.YMin        = visiableExtent.YMin;
            structRasterMetaData.YMax        = visiableExtent.YMax;
            structRasterMetaData.NoDataValue = -9999f;

            IRaster2 raster  = rasterLayer.Raster as IRaster2;
            IPnt     fromPnt = new PntClass();

            fromPnt.SetCoords(0, 0);
            IPnt blockSize = new PntClass();

            blockSize.SetCoords(columnCount, rowCount);
            IPixelBlock pixelBlock = ((IRaster)raster).CreatePixelBlock(blockSize);

            rasterLayer.Raster.Read(fromPnt, pixelBlock);
            float[,] data = new float[rowCount, columnCount];

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    object value = pixelBlock.GetVal(0, j, i);
                    if (value != null)
                    {
                        data[i, j] = Convert.ToSingle(value);
                        notNullRows.Add(i);
                        notNullColumns.Add(j);
                    }
                    else
                    {
                        data[i, j] = structRasterMetaData.NoDataValue;
                    }
                }
            }
            return(data);
        }
        public void Filter(IPixelBlock pPixelBlock)
        {
            try
            {
                IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;

                byte[] lookup = new byte[8] { 128, 64, 32, 16, 8, 4, 2, 1 };

                //get number of bands
                int plane = pPixelBlock.Planes;

                //loop through each band
                for (int i = 0; i < plane; i++)
                {
                    //get nodata mask array
                    byte[] outputArray = (byte[])pPixelBlock3.get_NoDataMaskByRef(i);

                    //loop through each pixel in the pixelblock and do calculation
                    for (int x = 0; x < pPixelBlock.Width; x++)
                    {
                        for (int y = 0; y < pPixelBlock.Height; y++)
                        {
                            //get index in the nodata mask byte array
                            int ind = x + y * (pPixelBlock.Width);

                            //get nodata mask byte 
                            byte nd = outputArray[ind / 8];

                            //get pixel value and check if it is nodata
                            object tempVal = pPixelBlock3.GetVal(i, x, y);

                            if (tempVal != null) //not nodata pixel
                            {
                                //convert pixel value to int and compare with nodata range

                                int curVal = Convert.ToInt32(tempVal);
                                if (curVal >= minNodataValue && curVal <= maxNodataValue)
                                {
                                    outputArray[ind / 8] = (byte)(nd & ~lookup[ind % 8]);
                                }
                            }
                        }
                    }
                    //set nodata mask array
                    pPixelBlock3.set_NoDataMask(i, outputArray);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #18
0
        /// <summary>
        /// Gets value of pixel at the specified position.
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="raster"></param>
        /// <returns></returns>
        public static double GetValue(Position pos, IRaster raster)
        {
            IPnt regionSize = new PntClass();

            regionSize.SetCoords(1, 1);
            IPixelBlock pixelBlock = raster.CreatePixelBlock(regionSize);
            IPnt        tl         = new PntClass();

            tl.SetCoords(pos.Column, pos.Row);
            raster.Read(tl, pixelBlock);

            return(Convert.ToDouble(pixelBlock.GetVal(0, 0, 0)));
        }
Пример #19
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         getTransformedValue(ref pPixelBlock);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #20
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int          pBHeight = pPixelBlock.Height;
         int          pBWidth = pPixelBlock.Width;
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         IPnt         pbBigSize = new PntClass();
         IPnt         pbBigLoc = new PntClass();
         int          pbBigWd = pBWidth + clms;
         int          pbBigHt = pBHeight + rws;
         int          l, t;
         l = clms / 2;
         t = rws / 2;
         pbBigSize.SetCoords(pbBigWd, pbBigHt);
         pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
         IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
         myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
         noDataValue = float.MinValue;//System.Convert.ToSingle(noDataValueArr.GetValue(0));
         for (int nBand = 0; nBand < ipPixelBlock.Planes; nBand++)
         {
             rstPixelType pbt         = ipPixelBlock.get_PixelType(nBand);
             System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
             for (int r = 0; r < pBHeight; r++)
             {
                 for (int c = 0; c < pBWidth; c++)
                 {
                     object inVlobj = ipPixelBlock.GetVal(nBand, c, r);
                     if (inVlobj == null)
                     {
                         continue;
                     }
                     else
                     {
                         updateGLCMDic(pbBig, c, r, nBand);
                         float  outVl = System.Convert.ToSingle(getTransformedValue(countDic));
                         object newVl = rasterUtil.getSafeValue(outVl, pbt);
                         pixelValues.SetValue(newVl, c, r);
                     }
                 }
             }
             ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #21
0
        private void createDictionaryArray()
        {
            IEnvelope env1 = referenceRaster.RasterInfo.Extent;
            IEnvelope env2 = transformRaster.RasterInfo.Extent;

            env1.Intersect(env2);
            clipGeo = (IGeometry)env1;
            IFunctionRasterDataset minRs = rsUtil.calcArithmaticFunction(referenceRaster, transformRaster, esriRasterArithmeticOperation.esriRasterMinus);

            clipRs = rsUtil.clipRasterFunction(minRs, clipGeo, esriRasterClippingType.esriRasterClippingOutside);
            IPnt pntSize = new PntClass();

            pntSize.SetCoords(512, 512);
            IRasterCursor rsCur = ((IRaster2)rsUtil.createRaster(clipRs)).CreateCursorEx(pntSize);
            int           pCnt  = rsCur.PixelBlock.Planes;

            do
            {
                IPixelBlock pbMinBlock = rsCur.PixelBlock;
                for (int r = 0; r < pbMinBlock.Height; r++)
                {
                    for (int c = 0; c < pbMinBlock.Width; c++)
                    {
                        for (int p = 0; p < pCnt; p++)
                        {
                            object vlObj = pbMinBlock.GetVal(p, c, r);
                            if (vlObj == null)
                            {
                                continue;
                            }
                            else
                            {
                                int vl = System.Convert.ToInt32(vlObj);
                                Dictionary <int, int> cDic = difDic[p];
                                int cnt = 0;
                                if (!cDic.TryGetValue(vl, out cnt))
                                {
                                    cDic.Add(vl, 1);
                                }
                                else
                                {
                                    cDic[vl] = cnt + 1;
                                }
                                cellCount[p] += 1;
                            }
                        }
                    }
                }
            } while (rsCur.Next() == true);
        }
Пример #22
0
        private IPixelBlock GetAllPixelBlock(int width, int height)
        {
            IRaster pRaster = GetRaster();
            IPnt    pnt     = new PntClass();

            pnt.SetCoords(0, 0);
            IPnt pntSize = new PntClass();

            pntSize.SetCoords(width, height);
            IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize);

            pRaster.Read(pnt, pixelBlock);
            return(pixelBlock);
        }
Пример #23
0
        void t_Tick(object sender, EventArgs e)
        {
            try
            {
                if (VariableMaintainer.IsNeedRefresh)
                {
                    string       simulationLayerName  = VariableMaintainer.CurrentFoucsMap.get_Layer(0).Name;
                    IRasterLayer simulationImageLayer = new RasterLayerClass();
                    if (VariableMaintainer.CurrentModel == EnumCurrentModel.Simulation_CA_LogisticRegression)
                    {
                        simulationImageLayer.CreateFromFilePath(VariableMaintainer.CurrentFormLogisticCAWizard.OutputFolder + @"\" + simulationLayerName);
                        ArcGISOperator.WriteRaster(simulationImageLayer, VariableMaintainer.CurrentFormLogisticCAWizard.SimulationImage);
                    }
                    else if (VariableMaintainer.CurrentModel == EnumCurrentModel.Simulation_CA_ANN)
                    {
                        simulationImageLayer.CreateFromFilePath(VariableMaintainer.CurrentFormANNCAWizard.OutputFolder + @"\" + simulationLayerName);
                        ArcGISOperator.WriteRaster(simulationImageLayer, VariableMaintainer.CurrentFormANNCAWizard.SimulationImage);
                    }
                    else if (VariableMaintainer.CurrentModel == EnumCurrentModel.Simulation_CA_DT)
                    {
                        simulationImageLayer.CreateFromFilePath(VariableMaintainer.CurrentFormDTCAWizard.OutputFolder + @"\" + simulationLayerName);
                        ArcGISOperator.WriteRaster(simulationImageLayer, VariableMaintainer.CurrentFormDTCAWizard.SimulationImage);
                    }

                    IRasterLayer l       = ArcGISOperator.GetRasterLayerByName(simulationLayerName);
                    IRaster2     raster  = simulationImageLayer.Raster as IRaster2;
                    IPnt         fromPnt = new PntClass();
                    fromPnt.SetCoords(0, 0);
                    IPnt blockSize = new PntClass();
                    blockSize.SetCoords(simulationImageLayer.ColumnCount, simulationImageLayer.RowCount);
                    IPixelBlock pixelBlock = ((IRaster)raster).CreatePixelBlock(blockSize);
                    l.Raster.Read(fromPnt, pixelBlock);
                    ((IRasterEdit)l.Raster).Refresh();

                    IActiveView activeView = VariableMaintainer.CurrentFoucsMap as IActiveView;
                    activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    VariableMaintainer.IsNeedRefresh = false;
                }

                if (VariableMaintainer.IsSimulationFinished)
                {
                    VariableMaintainer.CurrentTimer.Stop();
                    VariableMaintainer.IsSimulationFinished = false;
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }
Пример #24
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int  pBHeight = pPixelBlock.Height;
         int  pBWidth  = pPixelBlock.Width;
         IPnt pbSize   = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         myFunctionHelperCoef.Read(pTlc, null, myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
         int          pBRowIndex   = 0;
         int          pBColIndex   = 0;
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array outArr       = (System.Array)ipPixelBlock.get_PixelData(0);
         rstPixelType pty          = ipPixelBlock.get_PixelType(0);
         double[]     vArr         = new double[outPb.Planes];
         for (int i = pBRowIndex; i < pBHeight; i++)
         {
             for (int k = pBColIndex; k < pBWidth; k++)
             {
                 bool checkVl = true;
                 for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                 {
                     object vlObj = outPb.GetVal(0, k, i);
                     if (vlObj == null)
                     {
                         checkVl = false;
                         break;
                     }
                     vArr[coefnBand] = System.Convert.ToDouble(vlObj);
                 }
                 if (checkVl)
                 {
                     double tVl   = glm.computeNew(vArr);
                     object newVl = rasterUtil.getSafeValue(tVl, pty);
                     outArr.SetValue(newVl, k, i);
                 }
             }
         }
         ipPixelBlock.set_PixelData(0, outArr);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of GLM Function. " + exc.Message, exc);
         Console.WriteLine(exc.ToString());
     }
 }
Пример #25
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         //System.Windows.Forms.MessageBox.Show("Read resized raster");
         int          pBHeight     = pPixelBlock.Height;
         int          pBWidth      = pPixelBlock.Width;
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         IPnt         pbBigSize    = new PntClass();
         IPnt         pbBigLoc     = new PntClass();
         int          pbBigWd      = pBWidth * cells;
         int          pbBigHt      = pBHeight * cells;
         pbBigSize.SetCoords(pbBigWd, pbBigHt);
         pbBigLoc.SetCoords((pTlc.X * cells), (pTlc.Y * cells));
         IPixelBlock pbOrig = myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
         //System.Windows.Forms.MessageBox.Show("Read original Raster");
         myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, pbOrig);
         IPixelBlock3 pbBig = (IPixelBlock3)pbOrig;
         //int cnt = 0;
         for (int nBand = 0; nBand < ipPixelBlock.Planes; nBand++)
         {
             //Console.WriteLine(ipPixelBlock.get_PixelType(nBand).ToString());
             //object noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
             //System.Array pixelValuesBig = (System.Array)(pbBig.get_PixelData(nBand));
             rstPixelType pTy         = pbBig.get_PixelType(nBand);
             System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
             for (int r = 0; r < pBHeight; r++)
             {
                 for (int c = 0; c < pBWidth; c++)
                 {
                     object objVl = ipPixelBlock.GetVal(nBand, c, r);
                     if (objVl != null)
                     {
                         object outVl = getTransformedValue(pbBig, nBand, c, r, cells);
                         object newVl = rasterUtil.getSafeValue(outVl, pTy);
                         //System.Windows.Forms.MessageBox.Show(outVl.ToString());
                         pixelValues.SetValue(newVl, c, r);
                     }
                 }
             }
             ipPixelBlock.set_PixelData(nBand, pixelValues);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
Пример #26
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int  pBHeight = pPixelBlock.Height;
         int  pBWidth  = pPixelBlock.Width;
         IPnt pbSize   = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         IPixelBlock3          ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array[]        inArr        = new System.Array[inrsBands.RasterInfo.BandCount];
         IRasterBandCollection rsBc         = (IRasterBandCollection)inrsBands;
         for (int p = 0; p < inArr.Length; p++)
         {
             IRasterBand  rsB = rsBc.Item(p);
             IRawPixels   rP  = (IRawPixels)rsB;
             IPixelBlock  pb  = rP.CreatePixelBlock(pbSize);
             IPixelBlock3 pb3 = (IPixelBlock3)pb;
             rP.Read(pTlc, pb);
             inArr[p] = (System.Array)pb3.get_PixelData(0);
         }
         System.Array outArr = (System.Array)pPixelBlock.get_SafeArray(0);
         rstPixelType rsPt   = pPixelBlock.get_PixelType(0);
         for (int r = 0; r < ipPixelBlock.Height; r++)
         {
             for (int c = 0; c < ipPixelBlock.Width; c++)
             {
                 object outVlObj = ipPixelBlock.GetVal(0, c, r);
                 if (outVlObj != null)
                 {
                     float outVl;
                     if (getOutPutVl(inArr, c, r, out outVl))
                     {
                         object newVl = rasterUtil.getSafeValue(outVl, rsPt);//convertVl(outVl,rsPt);
                         outArr.SetValue(newVl, c, r);
                     }
                 }
             }
         }
         ipPixelBlock.set_PixelData(0, outArr);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of localMean Function. " + exc.Message, exc);
         Console.Write(exc.ToString());
         throw myExc;
     }
 }
Пример #27
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         pFilt.Filter(pPixelBlock);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
     }
 }
Пример #28
0
        private double[][] getValues(IPoint pnt, out double[] rwVls)
        {
            rwVls = new double[bndCnt];
            double[][] outJagArr = new double[(geoerro * geoerro)][];
            for (int i = 0; i < outJagArr.Length; i++)
            {
                outJagArr[i] = new double[bndCnt];
            }
            IRasterBandCollection rsBc = (IRasterBandCollection)FunctionRasterDataset;
            IRasterBand           rsB;
            IPnt pSize = new PntClass();

            pSize.SetCoords(geoerro, geoerro);
            IPnt      pLoc = new PntClass();
            int       clm, rw;
            IGeometry geo      = (IGeometry)FunctionRasterDataset.RasterInfo.Extent;
            IPoint    ul       = FunctionRasterDataset.RasterInfo.Extent.UpperLeft;
            IPnt      cellSize = FunctionRasterDataset.RasterInfo.CellSize;
            int       sub      = (geoerro / 2);

            rsUtil.getClmRw(ul, cellSize, pnt, out clm, out rw);
            int nclm = clm - sub;
            int nrw  = rw - sub;

            pLoc.SetCoords(System.Convert.ToDouble(nclm), System.Convert.ToDouble(nrw));
            for (int i = 0; i < bndCnt; i++)
            {
                rsB = rsBc.Item(i);
                IRawPixels  rpix = (IRawPixels)rsB;
                IPixelBlock pb   = rpix.CreatePixelBlock(pSize);
                rpix.Read(pLoc, pb);
                int pbCnt = 0;
                for (int r = 0; r < pb.Height; r++)
                {
                    for (int c = 0; c < pb.Width; c++)
                    {
                        object vlObj = pb.GetVal(0, c, r);
                        if (vlObj != null)
                        {
                            outJagArr[pbCnt][i] = System.Convert.ToDouble(vlObj);
                        }
                        pbCnt++;
                    }
                }
            }
            rwVls = outJagArr[(geoerro * geoerro / 2)];
            return(outJagArr);
        }
Пример #29
0
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="xIndex">水平方向的序号</param>
        /// <param name="yIndex">垂直方向的序号</param>
        /// <returns>获取的值,如果为null,表明该位置没有数据</returns>
        public object Read(int xIndex, int yIndex)
        {
            IRaster pRaster = GetRaster();
            IPnt    pnt     = new PntClass();

            pnt.SetCoords(xIndex, yIndex);
            IPnt pntSize = new PntClass();

            pntSize.SetCoords(1, 1);
            IPixelBlock pixelBlock = pRaster.CreatePixelBlock(pntSize);

            pRaster.Read(pnt, pixelBlock);
            object obj = pixelBlock.GetVal(0, 0, 0);

            return(obj);
        }
Пример #30
0
        private void getRasterMatrix()
        {
            n = 0;
            List <double[]>       inputMatrixLst = new List <double[]>();
            IRaster2              rs2            = (IRaster2)InRaster;
            IRasterBandCollection rsbc           = (IRasterBandCollection)rs2;
            IRasterProps          rsp            = (IRasterProps)rs2;
            //System.Array nDataVlArr = (System.Array)rsp.NoDataValue;
            IRasterCursor rsCur = rs2.CreateCursorEx(null);
            IPixelBlock   pb    = null;
            Random        rand  = new Random();

            do
            {
                pb = rsCur.PixelBlock;
                for (int r = 0; r < pb.Height; r++)
                {
                    for (int c = 0; c < pb.Width; c++)
                    {
                        object vlObj = pb.GetVal(0, c, r);
                        if (vlObj == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (rand.NextDouble() <= prop)
                            {
                                double[] vlBandArr = new double[rsbc.Count];
                                double   vl        = System.Convert.ToDouble(vlObj);
                                vlBandArr[0] = vl;
                                for (int p = 1; p < pb.Planes; p++)
                                {
                                    vlObj = pb.GetVal(p, c, r);
                                    vl    = System.Convert.ToDouble(vlObj);

                                    vlBandArr[p] = vl;
                                }
                                inputMatrixLst.Add(vlBandArr);
                                n++;
                            }
                        }
                    }
                }
            } while (rsCur.Next() == true);
            inputMatrix = inputMatrixLst.ToArray();
        }
Пример #31
0
        private void getRasterMatrix()
        {
            n = 0;
            List <double[]>       inputMatrixLst = new List <double[]>();
            IRaster2              rs2            = (IRaster2)InRaster;
            IRasterBandCollection rsbc           = (IRasterBandCollection)rs2;
            IRasterProps          rsp            = (IRasterProps)rs2;

            System.Array  nDataVlArr = (System.Array)rsp.NoDataValue;
            IRasterCursor rsCur      = rs2.CreateCursorEx(null);
            IPixelBlock   pb         = null;

            System.Array[] pbArrs = new System.Array[rsbc.Count];
            Random         rand   = new Random();

            do
            {
                pb = rsCur.PixelBlock;
                for (int i = 0; i < pb.Planes; i++)
                {
                    pbArrs[i] = (System.Array)pb.get_SafeArray(i);
                }
                for (int r = 0; r < pb.Height; r++)
                {
                    for (int c = 0; c < pb.Width; c++)
                    {
                        if (rand.NextDouble() <= prop)
                        {
                            double[] vlBandArr = new double[rsbc.Count];
                            for (int p = 0; p < pb.Planes; p++)
                            {
                                System.Array pbArr = pbArrs[p];
                                double       vl    = System.Convert.ToDouble(pbArr.GetValue(c, r));
                                if (rasterUtil.isNullData(vl, nDataVlArr.GetValue(p)))
                                {
                                    vl = 0;
                                }
                                vlBandArr[p] = vl;
                            }
                            inputMatrixLst.Add(vlBandArr);
                            n++;
                        }
                    }
                }
            } while (rsCur.Next() == true);
            inputMatrix = inputMatrixLst.ToArray();
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IRaster mosRs = (IRaster)mos;
                IPnt pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
                IPixelBlock pb = mosRs.CreatePixelBlock(pntSize);
                mosRs.Read(pTlc, pb);
                for (int i = 0; i < pb.Planes; i++)
                {
                    pPixelBlock.set_SafeArray(i, pb.get_SafeArray(i));
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of mosaic Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] outArr = new System.Array[bndCnt];
                int pbHeight = ipPixelBlock.Height;
                int pbWidth = ipPixelBlock.Width;
                for (int p = 0; p < ipPixelBlock.Planes; p++)
                {
                    outArr[p] = (System.Array)ipPixelBlock.get_PixelData(p);
                }

                for (int r = 0; r < pbHeight; r++)
                {
                    for (int c = 0; c < pbWidth; c++)
                    {
                        object vlObj = ipPixelBlock.GetVal(0,c,r);
                        if (vlObj!=null)
                        {
                            float vl = System.Convert.ToSingle(vlObj);
                            getOutPutVl(ipPixelBlock, outArr, vl, c, r);
                        }

                    }
                }
                for (int p = 0; p < ipPixelBlock.Planes; p++)
                {
                    ipPixelBlock.set_PixelData(p, outArr[p]);
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of localMean Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                float noDataVl = System.Convert.ToSingle(noDataValueArr.GetValue(0));
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;//inrsBandsCoef
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                myFunctionHelper.Read(pTlc, null, myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] pArr = new System.Array[outPb.Planes];
                for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                {
                    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                    pArr[coefnBand] = pixelValues;
                }
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    System.Array outArr = (System.Array)ipPixelBlock.get_PixelData(nBand);
                    rstPixelType pty = ipPixelBlock.get_PixelType(nBand);
                    for (int i = pBRowIndex; i < pBHeight; i++)
                    {
                        for (int k = pBColIndex; k < pBWidth; k++)
                        {

                            float[] IntSlpArr = slopes[nBand];
                            double sumVls = IntSlpArr[0];
                            for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                            {
                                double noDataValue = System.Convert.ToDouble(noDataValueArr.GetValue(coefnBand));
                                double pixelValue = Convert.ToDouble(pArr[coefnBand].GetValue(k, i));
                                if (rasterUtil.isNullData(pixelValue, noDataValue))
                                {
                                    sumVls = noDataVl;
                                    break;
                                }

                                double slp = System.Convert.ToDouble(IntSlpArr[coefnBand + 1]);
                                sumVls += pixelValue * slp;
                            }
                            if (sumVls < censored) sumVls = censored;
                            object newVl = rasterUtil.getSafeValue(sumVls, pty);
                            outArr.SetValue(newVl, k, i);
                        }
                    }
                    ipPixelBlock.set_PixelData(nBand, outArr);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Tobit Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IRaster2 rs2 = (IRaster2)pRaster;
                double pX,pY;
                rs2.PixelToMap(System.Convert.ToInt32(pTlc.X), System.Convert.ToInt32(pTlc.Y), out pX, out pY);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IEnvelope env = new EnvelopeClass();
                env.PutCoords(pX, pY - pBHeight, pX + pBWidth, pY);
                updateWithMergedValues(env,ipPixelBlock);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of merge Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
         {
             //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
             object dArr = vPb.get_PixelData(nBand);
             pb3.set_PixelData(nBand,dArr);
         }
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method PixelBlock To Raster Function. " + exc.Message, exc);
         throw myExc;
     }
 }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int pBHeight = pPixelBlock.Height;
         int pBWidth = pPixelBlock.Width;
         IPnt pbSize = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         IPixelBlock3 inputPb = (IPixelBlock3)myFunctionHelperInput.Raster.CreatePixelBlock(pbSize);//independent variables
         myFunctionHelperInput.Read(pTlc, null, myFunctionHelperInput.Raster, (IPixelBlock)inputPb);
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(0);
         createRegions(inputPb, pixelValues);
         ipPixelBlock.set_PixelData(0,pixelValues);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of the Region Group function Function. " + exc.Message, exc);
         Console.WriteLine(exc.ToString());
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                switch (landType)
                {
                    #region Area
                    case rasterUtil.landscapeType.AREA:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxAreaRectangle nHMax = new neighborhoodHelperLandscapeMaxAreaRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef,inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinAreaRectangle nHMin = new neighborhoodHelperLandscapeMinAreaRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:
                                neighborhoodHelperLandscapeSumAreaRectangle nHSum = new neighborhoodHelperLandscapeSumAreaRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanAreaRectangle nHMean = new neighborhoodHelperLandscapeMeanAreaRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeAreaRectangle nHMode = new neighborhoodHelperLandscapeModeAreaRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianAreaRectangle nHMed = new neighborhoodHelperLandscapeMedianAreaRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceAreaRectangle nHVar = new neighborhoodHelperLandscapeVarianceAreaRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdAreaRectangle nHSTD = new neighborhoodHelperLandscapeStdAreaRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueAreaRectangle nHUniq = new neighborhoodHelperLandscapeUniqueAreaRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyAreaRectangle nHEnt = new neighborhoodHelperLandscapeEntropyAreaRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityAreaRectangle nHProb = new neighborhoodHelperLandscapeProbabilityAreaRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    #region edge
                    case rasterUtil.landscapeType.EDGE:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxEdgeRectangle nHMax = new neighborhoodHelperLandscapeMaxEdgeRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinEdgeRectangle nHMin = new neighborhoodHelperLandscapeMinEdgeRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:
                                neighborhoodHelperLandscapeSumEdgeRectangle nHSum = new neighborhoodHelperLandscapeSumEdgeRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanEdgeRectangle nHMean = new neighborhoodHelperLandscapeMeanEdgeRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeEdgeRectangle nHMode = new neighborhoodHelperLandscapeModeEdgeRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianEdgeRectangle nHMed = new neighborhoodHelperLandscapeMedianEdgeRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceEdgeRectangle nHVar = new neighborhoodHelperLandscapeVarianceEdgeRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdEdgeRectangle nHSTD = new neighborhoodHelperLandscapeStdEdgeRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueEdgeRectangle nHUniq = new neighborhoodHelperLandscapeUniqueEdgeRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyEdgeRectangle nHEnt = new neighborhoodHelperLandscapeEntropyEdgeRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityEdgeRectangle nHProb = new neighborhoodHelperLandscapeProbabilityEdgeRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    #region ratio
                    case rasterUtil.landscapeType.RATIO:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxRatioRectangle nHMax = new neighborhoodHelperLandscapeMaxRatioRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinRatioRectangle nHMin = new neighborhoodHelperLandscapeMinRatioRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:

                                neighborhoodHelperLandscapeSumRatioRectangle nHSum = new neighborhoodHelperLandscapeSumRatioRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanRatioRectangle nHMean = new neighborhoodHelperLandscapeMeanRatioRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeRatioRectangle nHMode = new neighborhoodHelperLandscapeModeRatioRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianRatioRectangle nHMed = new neighborhoodHelperLandscapeMedianRatioRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceRatioRectangle nHVar = new neighborhoodHelperLandscapeVarianceRatioRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdRatioRectangle nHSTD = new neighborhoodHelperLandscapeStdRatioRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueRatioRectangle nHUniq = new neighborhoodHelperLandscapeUniqueRatioRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyRatioRectangle nHEnt = new neighborhoodHelperLandscapeEntropyRatioRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityRatioRectangle nHProb = new neighborhoodHelperLandscapeProbabilityRatioRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    default:
                        neighborhoodHelperLandscapeUniqueRegionsRectangle nHReg = new neighborhoodHelperLandscapeUniqueRegionsRectangle();
                        nHReg.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                        break;

                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of landscape Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] cArr = new System.Array[ipPixelBlock.Planes];
                for (int outBand = 0; outBand < ipPixelBlock.Planes; outBand++)
                {
                    System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(outBand);//(System.Array)(td);
                    cArr[outBand] = pixelValues;
                }

                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        bool ndT = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            object pObj = outPb.GetVal(coefnBand, k, i);
                            if (pObj==null)
                            {
                                ndT = false;
                                break;
                            }
                            double pixelValue = Convert.ToDouble(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            try
                            {
                                double[] pp = lm.computNew(xVls);
                                for (int p = 0; p < pp.Length; p++)
                                {
                                    double pVl = pp[p];
                                    object spVl = rasterUtil.getSafeValue(pVl,ipPixelBlock.get_PixelType(p));
                                    cArr[p].SetValue(spVl, k, i);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());
                                for (int p = 0; p < ipPixelBlock.Planes; p++)
                                {
                                    cArr[p].SetValue(0, k, i);
                                }
                            }
                        }
                        else
                        {
                            for (int p = 0; p < ipPixelBlock.Planes; p++)
                            {
                                cArr[p].SetValue(0, k, i);
                            }
                        }

                    }
                }
                for(int i=0;i<ipPixelBlock.Planes;i++)
                {
                    ipPixelBlock.set_PixelData(i,cArr[i]);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Regression Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc, null,myFunctionHelperCoef.Raster,(IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                System.Array pValues = (System.Array)ipPixelBlock.get_PixelData(0);//(System.Array)(td);
                rstPixelType pTyp = ipPixelBlock.get_PixelType(0);
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] xVls = new double[outPb.Planes];
                        bool ndT = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(coefnBand));
                            object pObj = outPb.GetVal(coefnBand, k, i);

                            if (pObj == null)
                            {
                                ndT = false;
                                break;
                            }
                            double pixelValue = Convert.ToDouble(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            int c = cluster.computNew(xVls);
                            object newVl = rasterUtil.getSafeValue(c, pTyp);
                            pValues.SetValue(newVl, k, i);
                        }

                    }
                }
                ipPixelBlock.set_PixelData(0, pValues);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Cluster Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The watermark image is then blended to the bottom right corner of the pixel block. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            BitmapData wMBitmapData = null;
            double pixelValue = 0.0;
            int wmRow = 0;
            int wmCol = 0;
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);

                int wMBandOffset = 0;

                #region Reference Raster Properties
                // Get the pixel type of the reference raster to see if 
                // it is compatible (8 bit).
                IRasterProps referenceProps = (IRasterProps)pRaster;
                if (referenceProps.PixelType != rstPixelType.PT_UCHAR &&
                    referenceProps.PixelType != rstPixelType.PT_CHAR)
                {
                    throw new System.Exception(
                        "Function can only be applied to 8bit data.");
                }

                #endregion

                #region Load watermark image object
                // Create new image object for the watermark image.
                myWatermarkImage = new Bitmap(myWatermarkImagePath);
                // Read number of bands of the watermark image.
                if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                    wMBandOffset = 4;
                else
                {
                    if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
                        wMBandOffset = 3;
                    else
                    {
                        throw new System.Exception(
                            "Invalid bitmap. Please provide one with 8bits per band in ARGB or RGB format.");
                    }
                }
                #endregion

                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                int wMHeight = myWatermarkImage.Height;
                int wMWidth = myWatermarkImage.Width;
                int wMRowIndex = 0;
                int wMColIndex = 0;
                int pBRowIndex = 0;
                int pBColIndex = 0;
                int endRow = 0;
                int endCol = 0;
                bool waterStartCol = false;
                bool waterStartRow = false;

                // Calculate the row/column values that specify where to start the blending.
                #region Calculate Indices
                /// If the number of rows of the pixelblock are more than the watermark image
                endRow = pBHeight;
                if (pBHeight >= wMHeight)
                {
                    /// Set the row index to start blending in the pixelblock.
                    switch (myWatermarkLocation)
                    {
                        case esriWatermarkLocation.esriWatermarkTopLeft:
                            {
                                pBRowIndex = 0;
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkTopRight:
                            {
                                pBRowIndex = 0;
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkCenter:
                            {
                                pBRowIndex = (pBHeight / 2) - (wMHeight / 2);
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomLeft:
                            {
                                pBRowIndex = pBHeight - wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomRight:
                            {
                                pBRowIndex = pBHeight - wMHeight;
                                break;
                            }
                        default:
                            break;
                    }

                    if (myWatermarkLocation == esriWatermarkLocation.esriWatermarkCenter)
                    {
                        pBRowIndex = (pBHeight / 2) - (wMHeight / 2);
                        endRow = pBRowIndex + wMHeight;
                    }
                }
                else /// If the number of rows of the watermark image is more than that of the pixelblock.
                {
                    /// Set the row index to start blending in the watermark image.
                    wMRowIndex = (wMHeight - pBHeight);
                    waterStartRow = true;
                }

                /// If the number of cols of the pixelblock are more than the watermark image
                endCol = pBWidth;
                if (pBWidth >= wMWidth)
                {
                    /// Set the col index to start blending in the pixelblock.
                    /// Set the row index to start blending in the pixelblock.
                    switch (myWatermarkLocation)
                    {
                        case esriWatermarkLocation.esriWatermarkTopLeft:
                            {
                                pBColIndex = 0;
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkTopRight:
                            {
                                pBColIndex = pBWidth - wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkCenter:
                            {
                                pBColIndex = (pBWidth / 2) - (wMWidth / 2);
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomLeft:
                            {
                                pBColIndex = 0;
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomRight:
                            {
                                pBColIndex = pBWidth - wMWidth;
                                break;
                            }
                        default:
                            break;
                    }
                }
                else /// If the number of cols of the watermark image is more than that of the pixelblock.
                {
                    /// Set the col index to start blending in the watermark image.
                    wMColIndex = (wMWidth - pBWidth);
                    waterStartCol = true;
                }
                #endregion

                #region Prepare Watermark Image for reading
                // Get the pixels from the watermark image using the lockbits function.
                wMBitmapData = myWatermarkImage.LockBits(new Rectangle(0, 0, wMWidth, wMHeight),
                    ImageLockMode.ReadOnly, myWatermarkImage.PixelFormat);

                System.IntPtr wMScan0 = wMBitmapData.Scan0;
                int wMStride = wMBitmapData.Stride;
                #endregion

                // The unsafe keyword is used so that pointers can be used to access pixels
                // from the watermark image.
                unsafe
                {
                    int wMPaddingOffset = wMStride - (myWatermarkImage.Width * wMBandOffset);

                    // Start filling from the correct row, col in the pixelblock 
                    // using the indices calculated above
                    System.Array pixelValues;
                    if (pPixelBlock.Planes == 3)
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                        else
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region Not 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                int nooftimes = 0;
                                int noofskips = 0;
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        //Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                        {
                                            // Calculate the average value of the pixels of the watermark image
                                            double avgValue = (Convert.ToDouble(wMStartByte[0]) +
                                                               Convert.ToDouble(wMStartByte[1]) +
                                                               Convert.ToDouble(wMStartByte[2])) / 3;

                                            // and blend it with the pixelValue from the PixelBlock.
                                            pixelValue = ((1 - blendValue) * pixelValue) +
                                                         (blendValue * avgValue);
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        ++nooftimes;
                                        noofskips += wMBandOffset;
                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                        else
                        {
                            #region Not 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                int nooftimes = 0;
                                int noofskips = 0;
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Calculate the average value of the pixels of the watermark image
                                            double avgValue = (Convert.ToDouble(wMStartByte[0]) +
                                                               Convert.ToDouble(wMStartByte[1]) +
                                                               Convert.ToDouble(wMStartByte[2])) / 3;

                                            // and blend it with the pixelValue from the PixelBlock.
                                            pixelValue = ((1 - blendValue) * pixelValue) +
                                                         (blendValue * avgValue);
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        ++nooftimes;
                                        noofskips += wMBandOffset;
                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                }

                #region Cleanup
                myWatermarkImage.UnlockBits(wMBitmapData);
                myWatermarkImage.Dispose();
                myWatermarkImage = null;
                wMBitmapData = null;
                wMScan0 = (System.IntPtr)null;
                wMStride = 0;
                #endregion
            }
            catch (Exception exc)
            {
                #region Cleanup
                if (wMBitmapData != null)
                    myWatermarkImage.UnlockBits(wMBitmapData);
                wMBitmapData = null;
                if (myWatermarkImage != null)
                    myWatermarkImage.Dispose();
                myWatermarkImage = null;
                #endregion

                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method of Watermark Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms;
                int pbBigHt = pBHeight + rws;
                int l, t;
                l = (clms-1) / 2;
                t = (rws-1) / 2;
                //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                {

                    System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                    rstPixelType rsp = ipPixelBlock.get_PixelType(nBand);
                    //System.Array pixelValuesBig = (System.Array)(pbBig.get_PixelData(nBand));
                    for (int r = 0; r < pBHeight; r++)
                    {
                        for (int c = 0; c < pBWidth; c++)
                        {
                            object objVl = ipPixelBlock.GetVal(nBand,c, r);
                            if (objVl==null)
                            {
                                continue;
                            }
                            else
                            {
                                float outVl = System.Convert.ToSingle(getTransformedValue(pbBig, c+l, r+t,nBand));
                                object newVl = rasterUtil.getSafeValue(outVl, rsp);
                                //Console.WriteLine(outVl.ToString());
                                pixelValues.SetValue(newVl,c, r);
                            }
                        }

                    }
                    ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);

                }

            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms;
                int pbBigHt = pBHeight + rws;
                int l, t;
                l = clms / 2;
                t = rws / 2;
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc,null,myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                noDataValue = float.MinValue;//System.Convert.ToSingle(noDataValueArr.GetValue(0));
                for (int nBand = 0; nBand < ipPixelBlock.Planes; nBand++)
                {
                    rstPixelType pbt = ipPixelBlock.get_PixelType(nBand);
                    System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                    for (int r = 0; r < pBHeight; r++)
                    {
                        for (int c = 0; c < pBWidth; c++)
                        {
                            object inVlobj = ipPixelBlock.GetVal(nBand, c, r);
                            if (inVlobj==null)
                            {
                                continue;
                            }
                            else
                            {
                                updateGLCMDic(pbBig, c, r, nBand);
                                float outVl = System.Convert.ToSingle(getTransformedValue(countDic));
                                object newVl = rasterUtil.getSafeValue(outVl, pbt);
                                pixelValues.SetValue(newVl,c,r);
                            }
                        }

                    }
                    ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            //try
            //{
                //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms - 1;
                int pbBigHt = pBHeight + rws - 1;
                int l, t;
                l = clms / 2;
                t = rws / 2;
                //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                updatePixelRectangle(ipPixelBlock, pbBig);
            //}
            //catch (Exception e)
            //{
                //Console.WriteLine(e.ToString());
                //System.Windows.Forms.MessageBox.Show(e.ToString());
                //Console.WriteLine(pTlc.X.ToString() + ":" + pTlc.Y.ToString());

            //}
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Create a new pixel block to read the input data into.
                // This is done because the pPixelBlock represents the output
                // pixel block which is different from the input. 
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pBlockSize = new Pnt();
                pBlockSize.X = pBWidth;
                pBlockSize.Y = pBHeight;
                IPixelBlock inputPixelBlock = new PixelBlock();
                ((IPixelBlock4)inputPixelBlock).Create(myInpNumBands, pBWidth, pBHeight, myInpPixeltype);

                // Call Read method of the Raster Function Helper object to read the input pixels into
                // the inputPixelBlock.
                myFunctionHelper.Read(pTlc, null, pRaster, inputPixelBlock);

                System.Array inpPixelValues1;
                System.Array inpPixelValues2;
                System.Array outPixelValues;
                int index1 = Convert.ToInt16(myBandIndices[0]) - 1; ; // Get NIR band index specified by user.
                int index2 = Convert.ToInt16(myBandIndices[1]) - 1; ; // Get Red Band index specified by user.

                // Get the correct bands from the input.
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)inputPixelBlock;
                inpPixelValues1 = (System.Array)(ipPixelBlock.get_PixelData(index1));
                inpPixelValues2 = (System.Array)(ipPixelBlock.get_PixelData(index2));
                outPixelValues = (System.Array)(((IPixelBlock3)pPixelBlock).get_PixelData(0));
                int i = 0;
                int k = 0;
                double pixelValue = 0.0;
                double nirValue = 0.0;
                double irValue = 0.0;
                // Perform the NDVI computation and store the result in the output pixel block.
                for (i = 0; i < pBHeight; i++)
                {
                    for (k = 0; k < pBWidth; k++)
                    {
                        nirValue = Convert.ToDouble(inpPixelValues1.GetValue(k, i));
                        irValue = Convert.ToDouble(inpPixelValues2.GetValue(k, i));
                        // Check if input is not NoData.
                        if ((Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(index1, k, i)) == 1) &&
                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(index2, k, i)) == 1)
                        {
                            // NDVI[k] = (NIR[k]-Red[k])/(NIR[k]+Red[k]);
                            if ((nirValue + irValue) != 0) // Check for division by 0.
                            {
                                pixelValue = (nirValue - irValue) / (nirValue + irValue);
                                if (pixelValue < -1.0 || pixelValue > 1.0)
                                    pixelValue = 0.0;
                            }
                            else
                                pixelValue = 0.0;
                        }
                        outPixelValues.SetValue((float)(pixelValue), k, i);
                    }
                }
                // Set the output pixel values on the output pixel block.
                ((IPixelBlock3)pPixelBlock).set_PixelData(0, outPixelValues);
                // Copy over the NoData mask from the input and set it on the output.
                ((IPixelBlock3)pPixelBlock).set_NoDataMask(0, ((IPixelBlock3)inputPixelBlock).get_NoDataMask(0));
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method: " + exc.Message, exc);
                throw myExc;
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     //double vl = 0;
     //float pixelValue = 0f;
     try
     {
         //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         #region Load log object
         for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
         {
             //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
             System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
             rstPixelType pbT = pb3.get_PixelType(nBand);
             for (int r = 0; r < pPixelBlock.Height; r++)
             {
                 for (int c = 0; c < pPixelBlock.Width; c++)
                 {
                     object objVl = pb3.GetVal(nBand,c, r);
                     if (objVl == null)
                     {
                         continue;
                     }
                     else
                     {
                         //vl = System.Convert.ToSingle(objVl);
                         //pixelValue = (float)getFunctionValue(vl);
                         double objVl2 = getFunctionValue(System.Convert.ToDouble(objVl));
                         object newVl = rasterUtil.getSafeValue(objVl2, pbT);
                         dArr.SetValue(newVl, c, r);
                     }
                 }
             }
             pb3.set_PixelData(nBand, dArr);
         }
         #endregion
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;
                IRaster2 inRs2 = (IRaster2)inrs;
                IRaster2 outRs2 = (IRaster2)outrs;
                double mx,my;
                outRs2.PixelToMap((int)pTlc.X,(int)pTlc.Y,out mx, out my);
                int clm,rw;
                inRs2.MapToPixel(mx,my,out clm,out rw);
                IPnt pntLoc = new PntClass();
                pntLoc.SetCoords(clm,rw);
                IPnt pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
                IPixelBlock3 pBIn = (IPixelBlock3)inrs.CreatePixelBlock(pntSize);
                inrs.Read(pntLoc,(IPixelBlock)pBIn);
                for (int p = 0; p < pPixelBlock.Planes; p++)
                {
                    pPixelBlock3.set_PixelData(p, pBIn.get_PixelData(p));
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
         IPixelBlock vPb = myFunctionHelper2.Raster.CreatePixelBlock(pntSize);
         myFunctionHelper2.Read(pTlc, null, myFunctionHelper2.Raster, vPb);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         object intArr = calcMeanShift((IPixelBlock3)vPb,pb3);
         pb3.set_PixelData(0, intArr);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method Mean-shift Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb);
                IPixelBlock3 outPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array outArr = (System.Array)outPixelBlock.get_PixelData(0);
                System.Array[] inArr = new System.Array[inrs.RasterInfo.BandCount];
                IRasterBandCollection rsBc = (IRasterBandCollection)inrs;
                for (int b = 0; b < inrs.RasterInfo.BandCount; b++)
                {
                    IRasterBand rsB = rsBc.Item(b);
                    IRawPixels rPix = (IRawPixels)rsB;
                    IPixelBlock pb = rPix.CreatePixelBlock(pbSize);
                    rPix.Read(pTlc,pb);
                    inArr[b] = (System.Array)pb.get_SafeArray(b);
                }
                updateOutArr(outPixelBlock, inArr, outArr);
                outPixelBlock.set_PixelData(0, outArr);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] inArr = new System.Array[inrsBands.RasterInfo.BandCount];
                IRasterBandCollection rsBc = (IRasterBandCollection)inrsBands;
                for (int p = 0; p < inArr.Length; p++)
                {
                    IRasterBand rsB = rsBc.Item(p);
                    IRawPixels rP = (IRawPixels)rsB;
                    IPixelBlock pb = rP.CreatePixelBlock(pbSize);
                    IPixelBlock3 pb3 = (IPixelBlock3)pb;
                    rP.Read(pTlc,pb);
                    inArr[p] = (System.Array)pb3.get_PixelData(0);
                }
                System.Array outArr = (System.Array)pPixelBlock.get_SafeArray(0);
                rstPixelType rsPt = pPixelBlock.get_PixelType(0);
                for (int r = 0; r < ipPixelBlock.Height; r++)
                {
                    for (int c = 0; c < ipPixelBlock.Width; c++)
                    {
                        object outVlObj = ipPixelBlock.GetVal(0, c, r);
                        if (outVlObj != null)
                        {
                            float outVl;
                            if (getOutPutVl(inArr, c, r, out outVl))
                            {
                                object newVl = rasterUtil.getSafeValue(outVl, rsPt);//convertVl(outVl,rsPt);
                                outArr.SetValue(newVl, c, r);
                            }
                        }
                    }
                }
                ipPixelBlock.set_PixelData(0, outArr);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of localMean Function. " + exc.Message, exc);
                Console.Write(exc.ToString());
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array outArr = (System.Array)ipPixelBlock.get_PixelData(0);
                rstPixelType pty = ipPixelBlock.get_PixelType(0);
                double[] vArr = new double[outPb.Planes];
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        bool checkVl = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            object vlObj = outPb.GetVal(0,k,i);
                            if(vlObj==null)
                            {
                                checkVl = false;
                                break;
                            }
                            vArr[coefnBand] = System.Convert.ToDouble(vlObj);
                        }
                        if(checkVl)
                        {
                            double tVl = lda.computeNew(vArr);
                            object newVl = rasterUtil.getSafeValue(tVl, pty);
                            outArr.SetValue(System.Convert.ToSingle(tVl), k, i);
                        }

                    }
                }
                ipPixelBlock.set_PixelData(0, outArr);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of GLM Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;//inrsBandsCoef
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    System.Array outArr = (System.Array)ipPixelBlock.get_PixelData(nBand);
                    rstPixelType pty = ipPixelBlock.get_PixelType(nBand);
                    for (int i = pBRowIndex; i < pBHeight; i++)
                    {
                        for (int k = pBColIndex; k < pBWidth; k++)
                        {

                            float[] IntSlpArr = slopes[nBand];
                            double sumVls = IntSlpArr[0];
                            bool checkNoData = true;
                            for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                            {
                                double slp = System.Convert.ToDouble(IntSlpArr[coefnBand + 1]);
                                if (slp == 0) continue;
                                //double noDataValue = System.Convert.ToDouble(noDataValueArr.GetValue(coefnBand));
                                object objPvl = outPb.GetVal(coefnBand, k, i);
                                if (objPvl == null)
                                {
                                    checkNoData = false;
                                    break;
                                }
                                else
                                {
                                    double pixelValue = Convert.ToDouble(objPvl);
                                    sumVls += pixelValue * slp;
                                }
                            }
                            if (checkNoData)
                            {
                                object nVl = rasterUtil.getSafeValue(sumVls, pty);
                                outArr.SetValue(nVl, k, i);
                            }
                        }
                    }
                    ipPixelBlock.set_PixelData(nBand, outArr);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Tobit Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc, null,myFunctionHelperCoef.Raster,(IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] pArr = new System.Array[ipPixelBlock.Planes];
                for (int coefnBand = 0; coefnBand < ipPixelBlock.Planes; coefnBand++)
                {
                    System.Array pixelValues = (System.Array)(pPixelBlock.get_SafeArray(coefnBand));
                    pArr[coefnBand] = pixelValues;
                }
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        object pObj = outPb.GetVal(0, k, i);

                        if (pObj == null)
                        {
                            continue;
                        }
                        else
                        {
                            string pixelValue = pObj.ToString();
                            double[] c;
                            if (tDic.TryGetValue(pixelValue, out c))
                            {
                                for (int v = 0; v < pArr.Length; v++)
                                {
                                    rstPixelType pty = pPixelBlock.get_PixelType(v);
                                    float vl = System.Convert.ToSingle(c[v]);
                                    object newVl = rasterUtil.getSafeValue(vl, pty);
                                    pArr[v].SetValue(newVl, k, i);
                                }
                            }
                            else
                            {
                                for (int v = 0; v < pArr.Length; v++)
                                {
                                    pArr.SetValue(0, k, i);
                                }
                            }
                        }

                    }
                }
                for (int i = 0; i < pArr.Length; i++)
                {
                    ipPixelBlock.set_PixelData(i, pArr[i]);
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of TTest Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            double vl = 0;
            float pixelValue = 0f;
            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
                #region Load log object
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            vl = System.Convert.ToDouble(dArr.GetValue(c, r));
                            if (rasterUtil.isNullData(System.Convert.ToSingle(vl), noDataValue))
                            {
                                continue;
                            }
                            pixelValue = System.Convert.ToSingle(getFunctionValue(vl));
                            dArr.SetValue(pixelValue, c, r);
                        }
                    }
                    pb3.set_PixelData(nBand, dArr);
                    //unsafe
                    //{
                    //    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    //    int lng = dArr.Length;
                    //    fixed (float* dValue = (float[,])dArr)
                    //    {
                    //        for (int i = 0; i < lng; i++)
                    //        {
                    //            pixelValue = *(dValue + i);
                    //            if (rasterUtil.isNullData(pixelValue, noDataValue))
                    //            {
                    //                continue;
                    //            }
                    //            pixelValue = System.Convert.ToSingle(getFunctionValue(pixelValue));
                    //            *(dValue + i) = pixelValue;

                    //        }
                    //        pb3.set_PixelData(nBand, dArr);
                    //    }
                    //}

                }
                #endregion
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampeling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] cArr = new System.Array[ipPixelBlock.Planes];
                for (int outBand = 0; outBand < ipPixelBlock.Planes; outBand++)
                {
                    System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(outBand);
                    cArr[outBand] = pixelValues;
                }
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] expArr = new double[slopes.Length];
                        double sumExp = 0;
                        int catCnts = 0;
                        bool noDataCheck = true;
                        foreach (double[] IntSlpArr in slopes)
                        {
                            double sumVls = IntSlpArr[0];
                            for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                            {
                                object coefnVlObj = outPb.GetVal(coefnBand, k, i);
                                //Console.WriteLine("Slope X value = " + pixelValue.ToString());
                                if (coefnVlObj==null)
                                {
                                    noDataCheck = false;
                                    break;
                                }
                                double slp = IntSlpArr[coefnBand + 1];
                                //Console.WriteLine("x = " + pixelValue.ToString() + " slope = " + slp.ToString());
                                sumVls += System.Convert.ToDouble(coefnVlObj) * slp;
                            }
                            if (noDataCheck)
                            {
                                double expSum = Math.Exp(sumVls);
                                expArr[catCnts] = expSum;
                                sumExp += expSum;
                                catCnts += 1;
                                //Console.WriteLine("sumVls = " + sumVls.ToString());
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (noDataCheck)
                        {
                            sumExp += 1;
                            double sumProb = 0;
                            catCnts = 1;
                            foreach (double expVl in expArr)
                            {
                                rstPixelType pTy = ipPixelBlock.get_PixelType(catCnts);
                                double prob = expVl / sumExp;
                                //Console.WriteLine("Probability = " + prob.ToString());
                                sumProb += prob;
                                object newVl = rasterUtil.getSafeValue(prob, pTy);
                                cArr[catCnts].SetValue(newVl, k, i);
                                //Console.WriteLine("Probability = " + cArr[catCnts].GetValue(k,i).ToString());
                                catCnts += 1;

                            }
                            rstPixelType pTy2 = ipPixelBlock.get_PixelType(0);
                            double lProb = 1 - sumProb;
                            object newVl2 = rasterUtil.getSafeValue(lProb, pTy2);
                            cArr[0].SetValue(newVl2, k, i);//base category
                        }
                        else
                        {
                            for (int b = 0; b < ipPixelBlock.Planes; b++)
                            {
                                cArr[b].SetValue(0, k, i);
                            }

                        }
                    }
                }
                for(int i=0;i<ipPixelBlock.Planes;i++)
                {
                    ipPixelBlock.set_PixelData(i,cArr[i]);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Regression Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         #region Load log object
         int pBHeight = pPixelBlock.Height;
         int pBWidth = pPixelBlock.Width;
         Pnt pbSize = new PntClass();
         pbSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array outPutArr = (System.Array)ipPixelBlock.get_PixelData(0);
         IPixelBlock3 CoefPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         myFunctionHelperCoef.Read(pTlc, null, myFunctionHelperCoef.Raster, (IPixelBlock)CoefPb);
         for (int r = 0; r < ipPixelBlock.Height; r++)
         {
             for (int c = 0; c < ipPixelBlock.Width; c++)
             {
                 object vlObj = CoefPb.GetVal(0, c, r);
                 if (vlObj != null)
                 {
                     if ((float)vlObj > 0)
                     {
                         vlObj = CoefPb.GetVal(1, c, r);
                     }
                     else
                     {
                         vlObj = CoefPb.GetVal(2, c, r);
                     }
                     if (vlObj != null)
                     {
                         outPutArr.SetValue(vlObj, c, r);
                     }
                 }
             }
         }
         ipPixelBlock.set_PixelData(0,outPutArr);
         #endregion
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of con Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock, int clms, int rws, IRasterFunctionHelper orig, rasterUtil.windowType wd)
        {
            try
            {
                if (wd == rasterUtil.windowType.RECTANGLE)
                {
                    try
                    {
                       int pBHeight = pPixelBlock.Height;
                        int pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt pbBigSize = new PntClass();
                        IPnt pbBigLoc = new PntClass();
                        int l, t;
                        l = clms / 2;
                        t = rws / 2;
                        int pbBigWd = pBWidth + clms;// -1;
                        int pbBigHt = pBHeight + rws;// -1;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc, null,orig.Raster, (IPixelBlock)pbBig);

                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float[,] pixelValues = (float[,])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[,])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)//coordinates in terms of the small pixel block
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary<int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec,er,clms,rws,c,r,(float)rasterUtil.getNoDataValue(rstPixelType.PT_FLOAT)); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);

                                    pixelValues.SetValue(uniqueMax, c, r);
                                }
                            }
                            try
                            {
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base rectangle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
                else
                {

                    try
                    {
                        List<int[]> iter = new List<int[]>();
                        int[,] circleWindow = rasterUtil.createFocalWidow(clms, clms, wd,out iter);
                        System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                        int pBHeight = pPixelBlock.Height;
                        int pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt pbBigSize = new PntClass();
                        IPnt pbBigLoc = new PntClass();
                        int pbBigWd = pBWidth + clms;
                        int pbBigHt = pBHeight + rws;
                        int l, t;
                        l = clms / 2;
                        t = rws / 2;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc,null,orig.Raster, (IPixelBlock)pbBig);
                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                            float[,] pixelValues = (float[,])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[,])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary<int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec, er,clms,rws,c,r, noDataValue, circleWindow); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);

                                    try
                                    {
                                        pixelValues.SetValue(uniqueMax, c, r);
                                    }
                                    catch
                                    {
                                        pixelValues.SetValue(noDataValue, c, r);
                                    }
                                }
                            }
                            ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base circle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base helper Function. " + exc.Message, exc);
                throw myExc;
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         pFilt.Filter(pPixelBlock);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
     }
 }
 public IFunctionRasterDataset PixelBlockToRaster(IPixelBlock ValuePb,IPnt TopLeft,object inRasterObject)
 {
     IFunctionRasterDataset rRst = createIdentityRaster(inRasterObject);
     string tempAr = funcDir + "\\" + FuncCnt + ".afr";
     IFunctionRasterDataset frDset = new FunctionRasterDatasetClass();
     IFunctionRasterDatasetName frDsetName = new FunctionRasterDatasetNameClass();
     frDsetName.FullName = tempAr;
     frDset.FullName = (IName)frDsetName;
     IRasterFunction rsFunc = new FunctionRasters.PixelBlockToRasterFunctionDataset();
     FunctionRasters.PixelBlockToRasterFunctionArguments args = new FunctionRasters.PixelBlockToRasterFunctionArguments(this);
     args.ValuePixelBlock = ValuePb;
     args.ValueRaster = rRst;
     args.TopLeft = TopLeft;
     frDset.Init(rsFunc, args);
     return frDset;
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The watermark image is then blended to the bottom right corner of the pixel block. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            BitmapData wMBitmapData = null;
            double pixelValue = 0.0;
            int wmRow = 0;
            int wmCol = 0;
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);

                int wMBandOffset = 0;

                #region Reference Raster Properties
                // Get the pixel type of the reference raster to see if
                // it is compatible (8 bit).
                IRasterProps referenceProps = (IRasterProps)pRaster;
                if (referenceProps.PixelType != rstPixelType.PT_UCHAR &&
                    referenceProps.PixelType != rstPixelType.PT_CHAR)
                {
                    throw new System.Exception(
                        "Function can only be applied to 8bit data.");
                }

                #endregion

                #region Load watermark image object
                // Create new image object for the watermark image.
                myWatermarkImage = new Bitmap(myWatermarkImagePath);
                // Read number of bands of the watermark image.
                if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                    wMBandOffset = 4;
                else
                {
                    if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
                        wMBandOffset = 3;
                    else
                    {
                        throw new System.Exception(
                            "Invalid bitmap. Please provide one with 8bits per band in ARGB or RGB format.");
                    }
                }
                #endregion

                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                int wMHeight = myWatermarkImage.Height;
                int wMWidth = myWatermarkImage.Width;
                int x_gap = xgap;
                int y_gap = ygap;

                #region Prepare Watermark Image for reading
                // Get the pixels from the watermark image using the lockbits function.
                wMBitmapData = myWatermarkImage.LockBits(new Rectangle(0, 0, wMWidth, wMHeight),
                    ImageLockMode.ReadOnly, myWatermarkImage.PixelFormat);

                System.IntPtr wMScan0 = wMBitmapData.Scan0;
                int wMStride = wMBitmapData.Stride;
                #endregion

                // The unsafe keyword is used so that pointers can be used to access pixels
                // from the watermark image.
                unsafe
                {
                    int wMPaddingOffset = wMStride - (wMWidth * wMBandOffset);

                    // Start filling from the correct row, col in the pixelblock
                    // using the indices calculated above
                    System.Array pixelValues;
                    if (pPixelBlock.Planes == 3)
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                byte* wMStartByte = (byte*)(void*)wMScan0;
                                wmRow = 0;
                                for (int i = 0; i < pBHeight; i++)
                                {
                                    wmCol = 0;
                                    byte* wMColStartByte = wMStartByte;
                                    for (int k = 0; k < pBWidth; k++)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                            pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);
                                        }

                                        if (wmCol == wMWidth - 1)
                                        {
                                            wmCol = 0;
                                            wMStartByte = wMColStartByte;
                                            k += x_gap;
                                        }
                                        else
                                        {
                                            ++wmCol;
                                            wMStartByte += wMBandOffset;
                                        }
                                    }
                                    wMStartByte = wMColStartByte + wMWidth * wMBandOffset;
                                    if (wmRow == wMHeight - 1)
                                    {
                                        wmRow = 0;
                                        wMStartByte = (byte*)(void*)wMScan0;
                                        i += y_gap;
                                    }
                                    else
                                    {
                                        ++wmRow;
                                        wMStartByte += wMPaddingOffset;

                                    }

                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                }

                #region Cleanup
                myWatermarkImage.UnlockBits(wMBitmapData);
                myWatermarkImage.Dispose();
                myWatermarkImage = null;
                wMBitmapData = null;
                wMScan0 = (System.IntPtr)null;
                wMStride = 0;
                #endregion
            }
            catch (Exception exc)
            {
                #region Cleanup
                if (wMBitmapData != null)
                    myWatermarkImage.UnlockBits(wMBitmapData);
                wMBitmapData = null;
                if (myWatermarkImage != null)
                    myWatermarkImage.Dispose();
                myWatermarkImage = null;
                #endregion

                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method of Watermark Function. " + exc.Message, exc);
                throw myExc;
            }
        }