Ejemplo n.º 1
0
        /// <summary>
        /// 内插值法求点的“地面高”
        /// </summary>
        /// <param name="pPnt"></param>
        /// <returns>点的高程值</returns>
        private double Calculate_Z2(IPoint pPnt)
        {
            double pZ = 0;
            //================================================
            double dRad                  = double.Parse("15".Trim()) / 2.0; //搜索半径一半
            double dBufferRad            = 0.0;
            ITopologicalOperator pTopo   = pPnt as ITopologicalOperator;
            IGeometry            pBuffer = pTopo.Buffer(dRad);

            IPointCollection pPC = new MultipointClass();

            pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dRad));
            pPC.AddPointCollection(pntColl(pBuffer));
            //================================================
            int pTag = 1;

            //如果点数小于2,则增大搜索半径,重新搜索
            while (pPC.PointCount < 2)
            {
                if (pTag > 4)//若重新搜索4次还没有点,则退出
                {
                    break;
                }
                pTag++;
                dBufferRad = dRad * pTag;
                pBuffer    = pTopo.Buffer(dBufferRad);

                pPC.RemovePoints(0, pPC.PointCount);
                pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dBufferRad));
                pPC.AddPointCollection(pntColl(pBuffer));
            }
            //================================================
            if (pPC.PointCount > 1)
            {
                double pTolZ   = 0;
                double pLength = 0;
                double iP      = 0;
                double pToliP  = 0;//权系数

                for (int i = 0; i < pPC.PointCount; i++)
                {
                    IPoint pPt = pPC.get_Point(i);

                    if (pPt.Z >= 0 || pPt.Z < 0)
                    {
                        pLength = Get_Len_2piont(pPnt, pPt);
                        if (pLength > 0)
                        {
                            iP     = 1 / Math.Pow(pLength, 2);
                            pToliP = pToliP + iP;
                            pTolZ  = pTolZ + iP * pPt.Z;
                        }
                    }//if (pPt.Z != double.NaN)
                }

                if (pToliP != 0)
                {
                    pZ = pTolZ / pToliP;
                }    //pToliP = 0使用初始化值0作为pZ结果
                else //大于两个点均与查询点重合
                {
                    pZ = 0;
                }
            }
            else//点数小于两个
            {
                //if (frmSetValue.UseConst)
                //{
                //    pZ = frmSetValue.ConstHight;
                //}
                //else
                //{
                //    frmSetValue pFrmSetValue = new frmSetValue(pPnt.X, pPnt.Y);
                //    if (pFrmSetValue.ShowDialog() == DialogResult.OK)
                //    {
                //        pZ = pFrmSetValue.ReturnValue;
                //        bolEdit = true;
                //    }
                //}
            }
            //================================================

            return(pZ);
        }