/// <summary>
        /// 求图幅与区域交点
        /// </summary>
        /// <param name="edge">边代号</param>
        /// <param name="p1">起点</param>
        /// <param name="p2">终点</param>
        /// <returns></returns>
        public BPoint FindIntersection(int edge, BPoint p1, BPoint p2)
        {
            double B = 0, L = 0;
            double minx, miny, maxx, maxy;

            minx = mapSheet.WSPoint1.L;
            maxx = mapSheet.ENPoint1.L;
            miny = mapSheet.WSPoint1.B;
            maxy = mapSheet.ENPoint1.B;
            if (edge == 1)
            {
                L = minx;
                B = p2.B + (p2.B - p1.B) * (minx - p2.L) / (p2.L - p1.L);
            }
            else if (edge == 3)
            {
                L = maxx;
                B = p2.B + (p2.B - p1.B) * (maxx - p2.L) / (p2.L - p1.L);
            }
            else if (edge == 2)
            {
                B = miny;
                L = p2.L + (miny - p2.B) * (p2.L - p1.L) / (p2.B - p1.B);
            }
            else if (edge == 4)
            {
                B = maxy;
                L = p2.L + (maxy - p2.B) * (p2.L - p1.L) / (p2.B - p1.B);
            }
            return(new BPoint(B, L));
        }
Exemple #2
0
        /// <summary>
        /// 计算角点
        /// </summary>
        /// <param name="latDiffer"></param>
        /// <param name="lonDiffer"></param>
        public void CalculateSheetPoints(double latDiffer, double lonDiffer)
        {
            char[] alpha = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V' };
            string row = sheetNum.Substring(0, 1);
            int    a = 0, b = 0, c = 0, d = 0;

            for (int i = 0; i < 22; i++)
            {
                if (row.Equals(alpha[i].ToString()))
                {
                    a = i + 1;
                }
            }
            b = int.Parse(sheetNum.Substring(1, 2));
            double latitude  = (a - 1) * 4;
            double longitude = (b - 31) * 6;

            if (sheetNum.Length > 3)
            {
                c         = int.Parse(sheetNum.Substring(4, 3));
                d         = int.Parse(sheetNum.Substring(7, 3));
                latitude  = (a - 1) * 4 + (4 / latDiffer - c) * latDiffer;
                longitude = (b - 31) * 6 + (d - 1) * lonDiffer;
            }
            //计算西南角的经纬度坐标
            //经纬度,单位:度
            //转为弧度
            latitude  = latitude * Math.PI / 180;
            longitude = longitude * Math.PI / 180;
            latDiffer = latDiffer * Math.PI / 180;
            lonDiffer = lonDiffer * Math.PI / 180;
            WSPoint   = new BPoint(latitude, longitude);
            ENPoint   = new BPoint(latitude + latDiffer, lonDiffer + longitude);
        }
        /// <summary>
        /// 判断点是否在图幅内
        /// </summary>
        /// <param name="edge">边代号</param>
        /// <param name="pt">某点</param>
        /// <returns></returns>
        public bool InSide(int edge, BPoint pt)
        {
            double latdiffer = 0, londiffer = 0;

            Tool.SetLatAndLonDif(MainForm.MeaScale, ref latdiffer, ref londiffer);
            mapSheet.CalculateSheetPoints(latdiffer, londiffer);
            double minx, miny, maxx, maxy;

            minx = mapSheet.WSPoint1.L;
            maxx = mapSheet.ENPoint1.L;
            miny = mapSheet.WSPoint1.B;
            maxy = mapSheet.ENPoint1.B;
            if (edge == 1 && pt.L < minx || edge == 3 && pt.L > maxx || edge == 2 && pt.B < miny || edge == 4 && pt.B > maxy)
            {
                return(false);
            }
            return(true);
        }