示例#1
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());
     }
 }
示例#2
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());
            }
        }
示例#3
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]);
            }
        }
示例#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          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;
     }
 }
示例#5
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();
        }
示例#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.

                //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());
            }
        }
        /// <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());
            }
        }
示例#8
0
        public void DEMToTIN(IRaster iRaster, string tinFileName)
        {
            try
            {
                //***************生成TIN模型*********************************************
                IGeoDataset           pGeoData   = iRaster as IGeoDataset;
                IEnvelope             pExtent    = pGeoData.Extent;
                IRasterBandCollection pRasBC     = iRaster as IRasterBandCollection;
                IRasterBand           pRasBand   = pRasBC.Item(0);
                IRawPixels            pRawPixels = pRasBand as IRawPixels;
                IRasterProps          pProps     = pRawPixels as IRasterProps;
                int    iWid       = pProps.Width;
                int    iHei       = pProps.Height;
                double w          = iWid / 1000.0f;
                double h          = iHei / 1000.0f;
                IPnt   pBlockSize = new DblPntClass();
                bool   IterationFlag;

                if (w < 1 && h < 1) //横纵都小于1000个像素
                {
                    pBlockSize.X  = iWid;
                    pBlockSize.Y  = iHei;
                    IterationFlag = false;
                }
                else
                {
                    pBlockSize.X  = 1001.0f;
                    pBlockSize.Y  = 1001.0f;
                    IterationFlag = true;
                }
                double cellsize = 0.0f;             //栅格大小

                IPnt pPnt1 = pProps.MeanCellSize(); //栅格平均大小
                cellsize = pPnt1.X;
                ITinEdit pTinEdit = new TinClass() as ITinEdit;
                pTinEdit.InitNew(pExtent);
                ISpatialReference pSpatial = pGeoData.SpatialReference;
                pExtent.SpatialReference = pSpatial;
                IPnt pOrigin           = new DblPntClass();
                IPnt pPixelBlockOrigin = new DblPntClass();
                //栅格左上角像素中心坐标
                double bX = pBlockSize.X;
                double bY = pBlockSize.Y;
                pBlockSize.SetCoords(bX, bY);
                IPixelBlock   pPixelBlock   = pRawPixels.CreatePixelBlock(pBlockSize);
                object        nodata        = pProps.NoDataValue; //无值标记
                ITinAdvanced2 pTinNodeCount = pTinEdit as ITinAdvanced2;
                int           nodeCount     = pTinNodeCount.NodeCount;
                object        vtMissing     = Type.Missing;
                object        vPixels       = null; //格子
                double        m_zTolerance  = 0;
                if (!IterationFlag)                 //当为一个处理单元格子时;(w < 1 && h < 1) //横纵都小于1000个像素
                {
                    pPixelBlockOrigin.SetCoords(0.0f, 0.0f);
                    pRawPixels.Read(pPixelBlockOrigin, pPixelBlock);
                    vPixels = pPixelBlock.get_SafeArray(0);
                    double xMin = pExtent.XMin;
                    double yMax = pExtent.YMax;
                    pOrigin.X = xMin + cellsize / 2;
                    pOrigin.Y = yMax - cellsize / 2;
                    bX        = pOrigin.X;
                    bY        = pOrigin.Y;
                    pTinEdit.AddFromPixelBlock(bX, bY, cellsize, cellsize, nodata, vPixels, m_zTolerance, ref vtMissing, out vtMissing);
                }
                else //当有多个处理单元格时,依次循环处理每个单元格
                {
                    int i = 0, j = 0, count = 0;
                    int FirstGoNodeCount = 0;

                    //while (nodeCount != FirstGoNodeCount)
                    //{
                    count++;
                    nodeCount = pTinNodeCount.NodeCount;
                    int bwidth = 0; int bheight = 0;
                    //依次循环处理
                    for (i = 0; i < (int)h + 1; i++)
                    {
                        if (i < (int)h)
                        {
                            bheight = 1000;
                        }
                        else
                        {
                            bheight = iHei - 1000 * i;
                        }
                        for (j = 0; j < (int)w + 1; j++)
                        {
                            if (j < (int)w)
                            {
                                bwidth = 1000;
                            }
                            else
                            {
                                bwidth = iWid - 1000 * j;
                            }
                            pBlockSize.SetCoords(bwidth, bheight);
                            pPixelBlock = pRawPixels.CreatePixelBlock(pBlockSize);


                            double bX1, bY1, xMin1, yMax1;
                            bX1 = pBlockSize.X;
                            bY1 = pBlockSize.Y;
                            pPixelBlockOrigin.SetCoords(j * 1000, i * 1000);

                            pRawPixels.Read(pPixelBlockOrigin, pPixelBlock);
                            vPixels = pPixelBlock.get_SafeArray(0);
                            xMin1   = pExtent.XMin;
                            yMax1   = pExtent.YMax;
                            //bX1 = pBlockSize.X;
                            //bY1 = pBlockSize.Y;
                            pOrigin.X = xMin1 + j * 1000 * cellsize + cellsize / 2.0f;
                            pOrigin.Y = yMax1 - i * 1000 * cellsize - cellsize / 2.0f;
                            bX1       = pOrigin.X;
                            bY1       = pOrigin.Y;
                            pTinEdit.AddFromPixelBlock(bX1, bY1, cellsize, cellsize, nodata, vPixels, m_zTolerance, ref vtMissing, out vtMissing);
                            FirstGoNodeCount = pTinNodeCount.NodeCount;
                        }
                    }
                    //}
                }
                //保存TIN文件
                pTinEdit.SaveAs(tinFileName, ref vtMissing);
                pTinEdit.StopEditing(true);
                m_pTin = pTinEdit as ITin;
                MessageBox.Show("转换成功!");
            }
            catch (SystemException e)
            {
                MessageBox.Show(e.Message);
            }
        }
        /// <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;
            }
        }
示例#10
0
        //分析的主要实现函数
        private IRasterLayer Analyze(IRasterLayer pRasterLayer)
        {
            IRaster      pRaster     = pRasterLayer.Raster;
            IRasterProps rasterProps = (IRasterProps)pRaster;

            //设置栅格数据起始点
            IPnt pBlockSize = new Pnt();

            pBlockSize.SetCoords(rasterProps.Width, rasterProps.Height);

            //选取整个范围
            IPixelBlock pPixelBlock = pRaster.CreatePixelBlock(pBlockSize);

            //左上点坐标
            IPnt tlp = new Pnt();

            tlp.SetCoords(0, 0);

            //读入栅格
            IRasterBandCollection pRasterBands = pRaster as IRasterBandCollection;
            IRasterBand           pRasterBand  = pRasterBands.Item(0);
            IRawPixels            pRawRixels   = pRasterBands.Item(0) as IRawPixels;

            pRawRixels.Read(tlp, pPixelBlock);

            //将PixBlock的值组成数组
            Array pSafeArray = pPixelBlock.get_SafeArray(0) as Array;

            //Array转数组
            double[,] myDoubleArr = new double[pSafeArray.GetLength(0), pSafeArray.GetLength(1)];
            for (int i = 0; i < myDoubleArr.GetLength(0); i++)
            {
                for (int j = 0; j < myDoubleArr.GetLength(1); j++)
                {
                    myDoubleArr[i, j] = Convert.ToDouble(pSafeArray.GetValue(i, j));
                }
            }

            for (int i = 0; i < myDoubleArr.GetLength(0); i++)
            {
                for (int j = 0; j < myDoubleArr.GetLength(1); j++)
                {
                    if (myDoubleArr[i, j] == 255)
                    {
                        myDoubleArr[i, j] = 0;
                    }
                }
            }
            double[,] ZeroArray = GetArray(myDoubleArr, Convert.ToInt32(textBox4.Text));
            double[,] OArray    = SumArray(ZeroArray, Convert.ToInt32(textBox4.Text));
            double[,] LastArray = ReturnLastArray(OArray, Convert.ToInt32(textBox4.Text));
            pPixelBlock.set_SafeArray(0, LastArray);

            //StreamWriter sw = File.AppendText(@"E:\GIS底层实验\WorkSpace\result\arrry.txt");
            //for (int y = 0; y < rasterProps.Height; y++)
            //{
            //    for (int x = 0; x < rasterProps.Width; x++)
            //    {
            //        //int value = Convert.ToInt32(pSafeArray.GetValue(x, y));
            //        Byte value = Convert.ToByte(pSafeArray.GetValue(x, y));
            //        string TxtCon = ("X:" + Convert.ToString(x) + "," + "Y:" + Convert.ToString(y) + "," + "Value" + pSafeArray.GetValue(x, y) + "\n");
            //        sw.Write(TxtCon);
            //    }
            //}
            //sw.Flush();
            //sw.Close();

            // 编辑raster,将更新的值写入raster中
            IRasterEdit rasterEdit = pRaster as IRasterEdit;

            rasterEdit.Write(tlp, pPixelBlock);
            rasterEdit.Refresh();
            return(pRasterLayer);
        }
示例#11
0
        public static IRasterDataset TinToRaster(ITinAdvanced itinAdvanced_0,
                                                 esriRasterizationType esriRasterizationType_0, string string_0, string string_1, rstPixelType rstPixelType_0,
                                                 double double_0, IEnvelope ienvelope_0, bool bool_0)
        {
            IPoint lowerLeft = ienvelope_0.LowerLeft;

            lowerLeft.X -= double_0 * 0.5;
            lowerLeft.Y -= double_0 * 0.5;
            int                num              = (int)Math.Round((double)((ienvelope_0.Width / double_0) + 1.0));
            int                num2             = (int)Math.Round((double)((ienvelope_0.Height / double_0) + 1.0));
            IGeoDataset        dataset          = itinAdvanced_0 as IGeoDataset;
            ISpatialReference2 spatialReference = dataset.SpatialReference as ISpatialReference2;
            IRasterDataset     dataset2         = CreateRasterSurf(string_0, string_1, "GRID", lowerLeft, num, num2, double_0,
                                                                   double_0, rstPixelType_0, spatialReference, true);
            IRasterBandCollection bands    = dataset2 as IRasterBandCollection;
            IRawPixels            pixels   = bands.Item(0) as IRawPixels;
            ITinSurface           pSurface = itinAdvanced_0 as ITinSurface;

            pSurface.RasterInterpolationMethod = esriSurfaceInterpolationType.esriNaturalNeighborInterpolation;
            IRasterProps props       = pixels as IRasterProps;
            object       noDataValue = props.NoDataValue;
            IPnt         tlc         = new DblPnt();
            int          num3        = 2048;
            int          num4        = 2048;

            if (num < 2048)
            {
                num3 = num;
            }
            if (num2 < num4)
            {
                num4 = num2;
            }
            IPnt size = new DblPnt
            {
                X = num3,
                Y = num4
            };
            IPixelBlock pxls   = pixels.CreatePixelBlock(size);
            object      block  = pxls.get_SafeArray(0);
            IPoint      point2 = new Point();

            for (int i = 0; i < num2; i += num4)
            {
                for (int j = 0; j < num; j += num3)
                {
                    if ((num - j) < num3)
                    {
                        size.X = num - j;
                        pxls   = pixels.CreatePixelBlock(size);
                        block  = pxls.get_SafeArray(0);
                    }
                    point2.X = (lowerLeft.X + (j * double_0)) + (double_0 * 0.5);
                    point2.Y = (lowerLeft.Y + ((num2 - i) * double_0)) - (double_0 * 0.5);
                    IGeoDatabaseBridge2 bridge = new GeoDatabaseHelper() as IGeoDatabaseBridge2;
                    bridge.QueryPixelBlock(pSurface, point2.X, point2.Y, double_0, double_0, esriRasterizationType_0,
                                           noDataValue, ref block);
                    tlc.X = j;
                    tlc.Y = i;
                    pxls.set_SafeArray(0, block);
                    pixels.Write(tlc, pxls);
                }
                bool flag = false;
                if (size.X != num3)
                {
                    size.X = num3;
                    flag   = true;
                }
                if ((num2 - i) < num4)
                {
                    size.Y = num2 - i;
                }
                if (flag)
                {
                    block = pixels.CreatePixelBlock(size).get_SafeArray(0);
                }
            }
            return(dataset2);
        }
示例#12
0
        private void middleRowColumn(IPnt loc)
        {
            double x         = loc.X;
            double y         = loc.Y;
            string outLocStr = x.ToString() + ":" + y.ToString();
            IPnt   readLoc   = new PntClass();

            readLoc.SetCoords(x - 1, y - 1);
            IRasterEdit regRsE      = (IRasterEdit)OutRaster;
            IPnt        writePbSize = new PntClass();

            writePbSize.SetCoords(pbwidth, pbheight);
            IPnt readPbSize = new PntClass();

            readPbSize.SetCoords(pbwidth + 2, pbheight + 2);
            IPixelBlock pb  = inRs.CreatePixelBlock(readPbSize);
            IPixelBlock pb2 = OutRaster.CreatePixelBlock(writePbSize);

            System.Array[] inOutArr;
            System.Array   inArr  = null;
            System.Array   outArr = null;
            if (outArrDic.TryGetValue(outLocStr, out inOutArr))
            {
                inArr  = inOutArr[0];
                outArr = inOutArr[1];
            }
            else
            {
                OutRaster.Read(loc, pb2);
                inRs.Read(readLoc, pb);
                OutRaster.Read(loc, pb2);
                inArr  = (System.Array)pb.get_SafeArray(0);
                outArr = (System.Array)pb2.get_SafeArray(0);
                outArrDic[outLocStr] = new System.Array[] { inArr, outArr };
            }
            int height = pb2.Height;
            int width  = pb2.Width;

            for (int c = 0; c < width; c++)
            {
                int ic = c + 1;
                for (int r = 0; r < height; r++)
                {
                    List <string> cr = new List <string>();
                    cr.Add(c.ToString() + ":" + r.ToString());
                    int ir   = r + 1;
                    int inVl = System.Convert.ToInt32(inArr.GetValue(ic, ir));
                    //Console.WriteLine("Invalue = " + inVl.ToString());
                    if ((inVl == noDataVl) || (inVl == (noDataVl - 1)))
                    {
                        Console.WriteLine("Invalue = " + inVl.ToString());
                        continue;
                    }
                    else
                    {
                        int outVl32 = System.Convert.ToInt32(outArr.GetValue(c, r));
                        if (outVl32 == noDataVl2)
                        {
                            rCnt  = 0;
                            rPerm = 0;
                            outArr.SetValue(counter, c, r);
                            List <int>[] nextArray = { new List <int>(), new List <int>(), new List <int>(), new List <int>() };//determines if the next pixel block must be queried {left,top,right,bottom}
                            while (cr.Count > 0)
                            {
                                rCnt++;
                                rPerm += findRegion(inVl, counter, noDataVl2, inArr, outArr, cr, nextArray);
                            }
                            for (int i = 0; i < nextArray.Length; i++)
                            {
                                List <int> pbNextLst = nextArray[i];
                                if (pbNextLst.Count > 0)
                                {
                                    int[]  startClms = new int[pbNextLst.Count];
                                    int[]  startRws  = new int[pbNextLst.Count];
                                    IPnt   newLoc    = new PntClass();
                                    double nClP      = loc.X;
                                    double nRwP      = loc.Y;
                                    switch (i)
                                    {
                                    case 0:
                                        nClP     = nClP - pbwidth;
                                        startRws = pbNextLst.ToArray();
                                        int stcl = pbwidth - 1;
                                        for (int k = 0; k < startRws.Length; k++)
                                        {
                                            startClms[k] = stcl;
                                        }
                                        break;

                                    case 1:
                                        nRwP      = nRwP - pbheight;
                                        startClms = pbNextLst.ToArray();    //rws=pbHeight-1
                                        int strw = pbheight - 1;
                                        for (int k = 0; k < startClms.Length; k++)
                                        {
                                            startRws[k] = strw;
                                        }
                                        break;

                                    case 2:
                                        nClP     = nClP + pbwidth;
                                        startRws = pbNextLst.ToArray();    //clms=0;
                                        break;

                                    default:
                                        nRwP      = nRwP + pbheight;
                                        startClms = pbNextLst.ToArray();    //rws = 0;
                                        break;
                                    }
                                    if ((nClP >= 0 && nRwP >= 0 & nClP <= rsProps2.Width && nRwP <= rsProps2.Height))
                                    {
                                        newLoc.SetCoords(nClP, nRwP);
                                        middleRowColumn(newLoc, startRws, startClms);
                                    }
                                }
                            }
                            IRow row = vatTable.CreateRow();
                            row.set_Value(valueIndex, counter);
                            row.set_Value(countIndex, rCnt);
                            row.set_Value(permIndex, rPerm);
                            row.Store();
                            counter++;
                        }
                        else
                        {
                        }
                    }
                }
            }
            pb2.set_SafeArray(0, (System.Array)outArr);
            regRsE.Write(loc, pb2);
            outArrDic.Remove(outLocStr);
        }
示例#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
            {
                // Call Read method of the Raster Function Helper object.
                //IRasterProps rsP = (IRasterProps)pRaster;
                //rsP.PixelType = convPType;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                for (int p = 0; p < pPixelBlock.Planes; p++)
                {
                    System.Array outArr = (System.Array)pPixelBlock.get_SafeArray(p);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            object vlObj = pPixelBlock.GetVal(p, c, r);
                            if (vlObj != null)
                            {
                                object newVl = convertVl(vlObj);
                                outArr.SetValue(newVl, c, r);
                            }
                            else
                            {
                                outArr.SetValue(null, c, r);
                            }
                        }
                    }
                    pPixelBlock.set_SafeArray(p, outArr);
                }
                //int pBHeight = pPixelBlock.Height;
                //int pBWidth = pPixelBlock.Width;
                //IPnt pbSize = new PntClass();
                //pbSize.SetCoords(pBWidth, pBHeight);
                //IRasterBandCollection rsBc = (IRasterBandCollection)inrs;
                //for (int p = 0; p < pPixelBlock.Planes; p++)
                //{
                //    IRasterBand rsB = rsBc.Item(p);
                //    IRawPixels rP = (IRawPixels)rsB;
                //    IPixelBlock pb = rP.CreatePixelBlock(pbSize);
                //    rP.Read(pTlc, pb);
                //    System.Array outArr = (System.Array)((IPixelBlock3)pPixelBlock).get_PixelData(p);
                //    for (int r = 0; r < pBHeight; r++)
                //    {
                //        for (int c = 0; c < pBWidth; c++)
                //        {
                //            object outVlObj = pb.GetVal(0, c, r);
                //            if (outVlObj != null)
                //            {
                //                object adVl = convertVl(outVlObj);
                //                outArr.SetValue(adVl, c, r);
                //            }
                //            else
                //            {
                //                //Console.WriteLine("outVlObj = null for r,c " + r.ToString() + ", " + c.ToString());
                //            }



                //        }
                //    }
                //    ((IPixelBlock3)pPixelBlock).set_PixelData(p, 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;
            }
        }