コード例 #1
0
ファイル: CalculateTopBase.cs プロジェクト: batuZ/Samples
        /// <summary>
        /// 计算最高点值
        /// </summary>
        /// <param name="envelope">计算范围</param>
        /// <returns>最高点高程</returns>
        /// <remarks>计算方式为在区域内按步长值依次选取采样点,求最大值</remarks>
        protected double GetTopValue(IPolygon calcPolygon)
        {
            IPolygon  polygon  = calcPolygon.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolygon;
            IEnvelope envelope = polygon.Envelope;

            // 采样点数量 可根据精度修改
            const double pickCount = 10000;

            // 高程计算模式
            gviGetElevationType mode = gviGetElevationType.gviGetElevationFromDatabase;

            // 最高点高程值和位置
            double topValue = double.MinValue;
            double topPointX = double.MinValue, topPointY = double.MinValue;

            double step        = Math.Sqrt(envelope.Width * envelope.Height / pickCount);
            double xStart      = envelope.MinX;
            double yStart      = envelope.MinY;
            bool   hasTopPoint = false;

            while (xStart <= envelope.MaxX)
            {
                yStart = envelope.MinY;
                while (yStart <= envelope.MaxY)
                {
                    double           elevatation = _AxRenderControl.Terrain.GetElevation(xStart, yStart, mode);
                    IGeometryFactory factory     = new GeometryFactory();
                    IPoint           point       = factory.CreatePoint(gviVertexAttribute.gviVertexAttributeNone);
                    IVector3         vector      = new Vector3();
                    vector.Set(xStart, yStart, 0);
                    point.Position = vector;
                    bool pointOnSurface = (polygon.IsPointOnSurface(point));
                    if (topValue < elevatation && pointOnSurface)
                    {
                        topValue    = elevatation;
                        topPointX   = xStart;
                        topPointY   = yStart;
                        hasTopPoint = true;
                    }

                    yStart += step;
                }
                xStart += step;
            }

            //MessageBox.Show(string.Format("最高点高度:{0}。坐标为X:{1} Y:{2} Z:{3}:", topValue, topPointX, topPointY, topValue));

            if (hasTopPoint)
            {
                DrawTableLabel(topPointX, topPointY, topValue);

                DrawTopPoint(topPointX, topPointY, topValue);
            }

            return(topValue);
        }
コード例 #2
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (PickResult.Type == gviObjectType.gviObjectTerrain)
            {
                gviGetElevationType mode = gviGetElevationType.gviGetElevationFromMemory;
                switch (this.toolStripGetElevationType.Text)
                {
                case "GetElevationFromMemory":
                    mode = gviGetElevationType.gviGetElevationFromMemory;
                    break;

                case "GetElevationFromDatabase":
                    mode = gviGetElevationType.gviGetElevationFromDatabase;
                    break;
                }
                double elevatation = this.axRenderControl1.Terrain.GetElevation(IntersectPoint.X, IntersectPoint.Y, mode);
                MessageBox.Show("当前位置高程为:" + elevatation.ToString());
            }
        }