Beispiel #1
0
 public double getUTMDistance(double x, double y)
 {
     return(CoordinateConverter.getUTMDistance(mX, mY, x, y));
 }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            double x1, y1, x2, y2;

            x1 = 119;
            x2 = 120;
            y1 = y2 = 35;
            Console.WriteLine("x:" + CoordinateConverter.getUTMDistance(x1, y1, x2, y2));
            Console.WriteLine("y:" + CoordinateConverter.getUTMDistance(x1, y1, x1, y2 + 1));
            string fileName = @"D:\sevenParamsTest.xlsx";
            //if (chainList.Count > 0)
            //    chainList.Clear();
            //LoadDataTableFromExcel(fileName, "Sheet1");
            int ptNum = 10;

            double[,] X   = MatrixTool.Init(3 * ptNum, 1);
            double[,] Y   = MatrixTool.Init(3 * ptNum, 1);
            double[,] Y84 = MatrixTool.Init(3 * ptNum, 1);


            int pN = 10;

            double[] XX     = new double[pN * 3];
            double[] YYRead = new double[pN * 3];
            double[] YY     =  new double[pN * 3];
            double[] YY84   = new double[pN * 3];

            int i = 0;
            int j = 0;
            int k = 0;

            foreach (DataRow dr in ds.Tables["Sheet1"].Rows)
            {
                if (i % 20 == 0 && j < ptNum)
                {
                    X[j * 3 + 1, 0]   = Convert.ToDouble(dr["North"]);
                    X[j * 3 + 0, 0]   = Convert.ToDouble(dr["East"]);
                    X[j * 3 + 2, 0]   = Convert.ToDouble(dr["Altitude"]);
                    Y84[j * 3 + 0, 0] = Convert.ToDouble(dr["Longitude"]);
                    Y84[j * 3 + 1, 0] = Convert.ToDouble(dr["Latitude"]);
                    Y84[j * 3 + 2, 0] = Convert.ToDouble(dr["Altitude"]);
                    j++;
                }
                if (i % 20 == 10 && k < ptNum)
                {
                    XX[k * 3 + 1]     = Convert.ToDouble(dr["North"]);
                    XX[k * 3 + 0]     = Convert.ToDouble(dr["East"]);
                    XX[k * 3 + 2]     = Convert.ToDouble(dr["Altitude"]);
                    YYRead[k * 3 + 0] = Convert.ToDouble(dr["Longitude"]);
                    YYRead[k * 3 + 1] = Convert.ToDouble(dr["Latitude"]);
                    YYRead[k * 3 + 2] = Convert.ToDouble(dr["Altitude"]);
                    k++;
                }
                i++;
                if (j == ptNum && k == ptNum)
                {
                    break;
                }
            }

            for (i = 0; i < ptNum; i++)
            {
                CoordinateConverter.LatLonToUTMXY(Y84[3 * i + 1, 0], Y84[3 * i + 0, 0], out Y[3 * i + 0, 0], out Y[3 * i + 1, 0]);
            }

            CoordTrans7Param ct = new CoordTrans7Param();

            ct.CalculateTrans7Param(X, Y);
            for (i = 0; i < pN; i++)
            {
                ct.TransCoord(XX[i * 3 + 0], XX[i * 3 + 1], XX[i * 3 + 2], out YY[i * 3 + 0], out YY[i * 3 + 1], out YY[i * 3 + 2]);
                CoordinateConverter.UTMXYToLatLon(YY[i * 3 + 0], YY[i * 3 + 1], out YY84[i * 3 + 1], out YY84[i * 3 + 0]);
                Console.WriteLine("准确的 x {0}, y {1}, z{2}, 计算的 x {3} , y {4} , z {5}", YYRead[i * 3 + 0], YYRead[i * 3 + 1], YYRead[i * 3 + 2], YY84[i * 3 + 0], YY84[i * 3 + 1], YY[i * 3 + 2]);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 求点与多条线段的最短距离,如果投影在多条线段内,返回t,否则f
        /// </summary>
        /// <param name="x">点</param>
        /// <param name="y">点</param>
        /// <param name="xa">多线段</param>
        /// <param name="ya"></param>
        /// <param name="ma"></param>
        /// <param name="fromid">多线段起点下标</param>
        /// <param name="toid">终点下标</param>
        /// <param name="m">最近点</param>
        /// <param name="dis">距离</param>
        /// <returns></returns>
        private static bool getDistance(double x, double y, double[] xa, double[] ya, double[] ma, int fromid, int toid, out double m, out double dis)
        {
            bool found = false;

            m = dis = 0;
            double lx = xa[fromid];
            double ly = ya[fromid];
            double rx = xa[toid];
            double ry = ya[toid];

            if ((x - lx) * (rx - lx) + (y - ly) * (ry - ly) < 0)
            {
                m   = ma[fromid];
                dis = CoordinateConverter.getUTMDistance(x, y, lx, ly);
            }
            else if ((x - rx) * (lx - rx) + (y - ry) * (ly - ry) < 0)
            {
                m   = ma[toid];
                dis = CoordinateConverter.getUTMDistance(x, y, rx, ry);
            }
            else
            {
                found = true;
                int minid = fromid;
                dis = CoordinateConverter.getUTMDistance(x, y, lx, ly);
                for (int i = fromid + 1; i <= toid; i++)
                {
                    double di = CoordinateConverter.getUTMDistance(x, y, xa[i], ya[i]);
                    if (di < dis)
                    {
                        dis   = di;
                        minid = i;
                    }
                }
                int lid = minid - 1;
                if (lid < fromid)
                {
                    lid = fromid;
                }
                int rid = minid + 1;
                if (rid > toid)
                {
                    rid = toid;
                }
                double d1 = CoordinateConverter.getUTMDistance(x, y, xa[lid], ya[lid]);
                double d2 = CoordinateConverter.getUTMDistance(x, y, xa[rid], ya[rid]);

                double ddd = d1 / (d1 + d2);
                //if (d1 > d2)
                //{
                //    ddd = disInterpolate(x, y, xa[lid], ya[lid], xa[rid], ya[rid]);
                //}
                //else
                //{
                //    ddd = 1 - disInterpolate(x,y,xa[rid],ya[rid],xa[lid],ya[lid]);
                //}
                m = ma[lid] + (ma[rid] - ma[lid]) * ddd;
                double xm = xa[lid] + (xa[rid] - xa[lid]) * ddd;
                double ym = ya[lid] + (ya[rid] - ya[lid]) * ddd;
                dis = CoordinateConverter.getUTMDistance(x, y, xm, ym);
            }
            return(found);
        }
Beispiel #4
0
        private void button2_Click1(object sender, EventArgs e)
        {
            double x1, y1, x2, y2;

            x1 = 119;
            x2 = 120;
            y1 = y2 = 35;
            Console.WriteLine("x:" + CoordinateConverter.getUTMDistance(x1, y1, x2, y2));
            Console.WriteLine("y:" + CoordinateConverter.getUTMDistance(x1, y1, x1, y2 + 1));
            string fileName = @"D:\sevenParamsTest.xlsx";
            //if (chainList.Count > 0)
            //    chainList.Clear();
            //LoadDataTableFromExcel(fileName, "Sheet1");
            int ptNum = 5;

            double[,] X = MatrixTool.Init(2 * ptNum, 1);
            double[,] Y = MatrixTool.Init(2 * ptNum, 1);


            int pN = 10;

            double[] XX     = new double[pN * 2];
            double[] YYRead = new double[pN * 2];
            double[] YY     = new double[pN * 2];

            int i = 0;
            int j = 0;
            int k = 0;

            foreach (DataRow dr in ds.Tables["Sheet1"].Rows)
            {
                if (i % 40 == 0 && j < ptNum)
                {
                    X[j * 2 + 0, 0] = Convert.ToDouble(dr["North"]);
                    X[j * 2 + 1, 0] = Convert.ToDouble(dr["East"]);

                    Y[j * 2 + 0, 0] = Convert.ToDouble(dr["Longitude"]);
                    Y[j * 2 + 1, 0] = Convert.ToDouble(dr["Latitude"]);

                    j++;
                }
                if (i % 20 == 10 && k < pN)
                {
                    XX[k * 2 + 0] = Convert.ToDouble(dr["North"]);
                    XX[k * 2 + 1] = Convert.ToDouble(dr["East"]);

                    YYRead[k * 2 + 0] = Convert.ToDouble(dr["Longitude"]);
                    YYRead[k * 2 + 1] = Convert.ToDouble(dr["Latitude"]);

                    k++;
                }
                i++;
                if (j == ptNum && k == pN)
                {
                    break;
                }
            }
            double cx1, cy1, cx2, cy2;

            cx1 = cy1 = cx2 = cy2 = 0;
            double sx = 91310;
            double sy = 111000;

            for (i = 0; i < pN; i++)
            {
                cx1 += XX[2 * i];
                cy1 += XX[2 * i + 1];
                cx2 += YYRead[2 * i];
                cy2 += YYRead[2 * i + 1];
            }
            cx1 /= pN;
            cy1 /= pN;
            cx2 /= pN;
            cy2 /= pN;

            for (i = 0; i < ptNum; i++)
            {
                X[2 * i, 0]     = X[2 * i, 0] - cx1;
                X[2 * i + 1, 0] = X[2 * i + 1, 0] - cy1;
                Y[2 * i, 0]     = (Y[2 * i, 0] - cx2) * sx;
                Y[2 * i + 1, 0] = (Y[2 * i + 1, 0] - cy2) * sy;
            }

            for (i = 0; i < pN; i++)
            {
                XX[2 * i]     = XX[2 * i] - cx1;
                XX[2 * i + 1] = XX[2 * i + 1] - cy1;
            }

            CoordTrans4Param ct = new CoordTrans4Param();

            ct.CalculateTrans4Param(X, Y);
            for (i = 0; i < pN; i++)
            {
                ct.TransCoord(XX[i * 2 + 0], XX[i * 2 + 1], out YY[i * 2 + 0], out YY[i * 2 + 1]);
                Console.WriteLine("准确的 x {0}, y {1}, 计算的 x {2} , y {3} ", YYRead[i * 2 + 0], YYRead[i * 2 + 1], YY[i * 2 + 0] / sx + cx2, YY[i * 2 + 1] / sy + cy2);
            }
        }