Beispiel #1
0
        public override void getOutPutVl(IPixelBlock3 pb, System.Array[] inArr, float vl, int c, int r)
        {
            float[] orgArr  = new float[bndCnt];
            float[] sortArr = new float[bndCnt];
            orgArr[0]  = vl;
            sortArr[0] = vl;
            for (int p = 1; p < bndCnt; p++)
            {
                float vl2 = System.Convert.ToSingle(inArr[p].GetValue(c, r));
                orgArr[p]  = vl2;
                sortArr[p] = vl2;
            }
            System.Array.Sort(sortArr);
            for (int p = 0; p < bndCnt; p++)
            {
                rstPixelType ptyp      = pb.get_PixelType(p);
                float        orgVl     = orgArr[p];
                int          indexSort = System.Array.LastIndexOf(sortArr, orgVl);
                float        prc       = indexSort / bndCntf;
                object       newVl     = rasterUtil.getSafeValue(prc, ptyp);
                inArr[p].SetValue(newVl, c, r);
            }

            //int[] cntLst = new int[100];
            //float[] probLst = new float[100];
            //float[] orgLst = new float[bndCnt];
            //int[] indexvl = new int[bndCnt];
            //float min = float.MaxValue;
            //float max = float.MinValue;
            //float TCnt = 0;
            //for (int i = 0; i < coefPb.Planes; i++)
            //{
            //    object objVl = coefPb.GetVal(i, c, r);
            //    if (objVl != null)
            //    {
            //        float vl = (float)objVl;
            //        orgLst[i] = vl;
            //        if (vl > max) max = vl;
            //        if (vl < min) min = vl;
            //        TCnt+=1;
            //    }
            //}
            //float rng = max - min;
            //for (int i = 0; i < orgLst.Length; i++)
            //{
            //    int indexVl = (int)(99*(orgLst[i] - min) / rng);
            //    indexvl[i] = indexVl;
            //    cntLst[indexVl] = cntLst[indexVl] + 1;
            //}
            //int sumCnt = 0;
            //for (int i = 0; i < cntLst.Length; i++)
            //{
            //    sumCnt = sumCnt + cntLst[i];
            //    probLst[i] = sumCnt/TCnt;
            //}
            //for (int i = 0; i < orgLst.Length; i++)
            //{
            //    updateArr[i].SetValue(probLst[indexvl[i]], c, r);
            //}
        }
Beispiel #2
0
        private object splitArray(int[] vls, IPixelBlock3 pb3)
        {
            int width  = pb3.Width;
            int height = pb3.Height;
            int cnt    = 0;

            System.Array outArr = (System.Array)pb3.get_PixelData(0);
            rstPixelType rsp    = pb3.get_PixelType(0);

            foreach (int i in vls)
            {
                double div = System.Convert.ToDouble(cnt) / width;
                int    r   = (int)div;
                int    c   = cnt - (r * width);
                try
                {
                    object newvl = rasterUtil.getSafeValue(i, rsp);
                    outArr.SetValue(i, c, r);
                }
                catch
                {
                    object newvl = rasterUtil.getSafeValue(900, rsp);
                    outArr.SetValue(900, c, r);
                }
                cnt++;
            }
            return(outArr);
        }
Beispiel #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
     {
         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());
     }
 }
Beispiel #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
     {
         //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());
     }
 }
Beispiel #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
     {
         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());
     }
 }
Beispiel #6
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());
     }
 }
Beispiel #7
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);
             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;
     }
 }
Beispiel #8
0
        private void updateOutArr(IPixelBlock3 outPb, System.Array[] inArr, System.Array outArr)
        {
            int bands = inArr.Length;

            string[]       sArr  = new string[bands];
            System.Array[] vlArr = new System.Array[bands];
            rstPixelType   pTy   = outPb.get_PixelType(0);

            for (int r = 0; r < outPb.Height; r++)
            {
                for (int c = 0; c < outPb.Width; c++)
                {
                    bool ch = true;
                    for (int p = 0; p < bands; p++)
                    {
                        object inObj = inArr[p].GetValue(c, r);
                        if (inObj == null)
                        {
                            ch = false;
                            break;
                        }
                        else
                        {
                            sArr[p] = inObj.ToString();
                        }
                    }
                    if (ch)
                    {
                        int    vl   = uniqueCounter;
                        string sVls = String.Join(",", sArr);
                        if (!uniqueDic.TryGetValue(sVls, out vl))
                        {
                            uniqueCounter += 1;
                            vl             = uniqueCounter;
                            uniqueDic.Add(sVls, vl);
                        }
                        object newVl = rasterUtil.getSafeValue(vl, pTy);
                        outArr.SetValue(newVl, c, r);
                    }
                }
            }
        }
Beispiel #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 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());
     }
 }
 private void updateOutArr(IPixelBlock3 outPb, System.Array[] inArr, System.Array outArr)
 {
     int bands = inArr.Length;
     string[] sArr = new string[bands];
     System.Array[] vlArr = new System.Array[bands];
     rstPixelType pTy = outPb.get_PixelType(0);
     for (int r = 0; r < outPb.Height; r++)
     {
         for (int c = 0; c < outPb.Width; c++)
         {
             bool ch = true;
             for (int p = 0; p < bands; p++)
             {
                 object inObj = inArr[p].GetValue(c, r);
                 if (inObj == null)
                 {
                     ch = false;
                     break;
                 }
                 else
                 {
                     sArr[p] = inObj.ToString();
                 }
             }
             if (ch)
             {
                 int vl = uniqueCounter;
                 string sVls = String.Join(",", sArr);
                 if (!uniqueDic.TryGetValue(sVls, out vl))
                 {
                     uniqueCounter += 1;
                     vl = uniqueCounter;
                     uniqueDic.Add(sVls, vl);
                 }
                 object newVl = rasterUtil.getSafeValue(vl, pTy);
                 outArr.SetValue(newVl, c, r);
             }
         }
     }
 }
Beispiel #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)
        {
            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());
            }
        }
Beispiel #12
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);
         //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());
     }
 }
Beispiel #13
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);
                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>
        /// 写入栅格数据。
        /// </summary>
        public static void WriteRaster(IRasterLayer rasterLayer, float[,] datas)
        {
            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 pixelBlock = ((IRaster)raster).CreatePixelBlock(blockSize);

            rasterLayer.Raster.Read(fromPnt, pixelBlock);

            IPixelBlock3 pixelBlock3 = (IPixelBlock3)pixelBlock;
            object       temp        = pixelBlock3.get_PixelDataByRef(0);

            if ((pixelBlock3.get_PixelType(0) == rstPixelType.PT_CLONG) || (pixelBlock3.get_PixelType(0) == rstPixelType.PT_ULONG))
            {
                System.Int32[,] pixelData = (System.Int32[, ])temp;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (datas[i, j] == -9999f)
                        {
                            pixelData[j, i] = 0;
                        }
                        else
                        {
                            if (pixelData[j, i] != Convert.ToInt32(datas[i, j]))
                            {
                                pixelData[j, i] = Convert.ToInt32(datas[i, j]);
                            }
                        }
                    }
                }
                pixelBlock3.set_PixelData(0, pixelData);
            }
            else if ((pixelBlock3.get_PixelType(0) == rstPixelType.PT_SHORT) || (pixelBlock3.get_PixelType(0) == rstPixelType.PT_USHORT))
            {
                System.Int16[,] pixelData = (System.Int16[, ])temp;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (datas[i, j] == -9999f)
                        {
                            pixelData[j, i] = 0;
                        }
                        else
                        {
                            if (pixelData[j, i] != Convert.ToInt16(datas[i, j]))
                            {
                                pixelData[j, i] = Convert.ToInt16(datas[i, j]);
                            }
                        }
                    }
                }
                pixelBlock3.set_PixelData(0, pixelData);
            }
            else if ((pixelBlock3.get_PixelType(0) == rstPixelType.PT_CHAR) || (pixelBlock3.get_PixelType(0) == rstPixelType.PT_UCHAR))
            {
                System.Byte[,] pixelData = (System.Byte[, ])temp;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (datas[i, j] == -9999f)
                        {
                            //pixelData[j, i] = 0;
                            ;
                        }
                        else
                        {
                            if (pixelData[j, i] != Convert.ToByte(datas[i, j]))
                            {
                                pixelData[j, i] = Convert.ToByte(datas[i, j]);
                            }
                        }
                    }
                }
                pixelBlock3.set_PixelData(0, pixelData);
            }
            else if (pixelBlock3.get_PixelType(0) == rstPixelType.PT_FLOAT)
            {
                System.Single[,] pixelData = (System.Single[, ])temp;
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (datas[i, j] == -9999f)
                        {
                            //pixelData[j, i] =0;
                            ;
                        }
                        else
                        {
                            if (pixelData[j, i] != Convert.ToSingle(datas[i, j]))
                            {
                                pixelData[j, i] = Convert.ToSingle(datas[i, j]);
                            }
                        }
                    }
                }
                pixelBlock3.set_PixelData(0, pixelData);
            }

            ((IRasterEdit)rasterLayer.Raster).Write(fromPnt, (IPixelBlock)pixelBlock3);
            ((IRasterEdit)rasterLayer.Raster).Refresh();
        }
 private object splitArray(int[] vls, IPixelBlock3 pb3)
 {
     int width = pb3.Width;
     int height = pb3.Height;
     int cnt = 0;
     System.Array outArr = (System.Array)pb3.get_PixelData(0);
     rstPixelType rsp = pb3.get_PixelType(0);
     foreach (int i in vls)
     {
         double div = System.Convert.ToDouble(cnt) / width;
         int r = (int)div;
         int c = cnt - (r * width);
         try
         {
             object newvl = rasterUtil.getSafeValue(i, rsp);
             outArr.SetValue(i, c, r);
         }
         catch
         {
             object newvl = rasterUtil.getSafeValue(900, rsp);
             outArr.SetValue(900, c, r);
         }
         cnt++;
     }
     return outArr;
 }
Beispiel #16
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)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++)
                                {
                                    double vl    = c[v];
                                    object newVl = rasterUtil.getSafeValue(vl, ipPixelBlock.get_PixelType(v));
                                    pArr[v].SetValue(newVl, k, i);
                                }
                            }
                            else
                            {
                                for (int v = 0; v < pArr.Length; v++)
                                {
                                    pArr.SetValue(ndVl, 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());
            }
        }
Beispiel #17
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)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());
            }
        }
Beispiel #18
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;
         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++)
                 {
                     bool checkNoData = true;
                     int  ov          = 1;
                     for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                     {
                         double min    = mins[coefnBand];
                         double max    = maxs[coefnBand];
                         object objPvl = outPb.GetVal(coefnBand, k, i);
                         if (objPvl == null)
                         {
                             checkNoData = false;
                             ov          = 0;
                             break;
                         }
                         else
                         {
                             double pixelValue = Convert.ToDouble(objPvl);
                             if (pixelValue < min || pixelValue > max)
                             {
                                 ov = 0;
                                 break;
                             }
                         }
                     }
                     if (checkNoData)
                     {
                         object nVl = rasterUtil.getSafeValue(ov, 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 Domain Function. " + exc.Message, exc);
         Console.WriteLine(exc.ToString());
     }
 }