Пример #1
0
        //double[] cVerticesArray=null;
        //int angle = (int)(item.AvgProgress * 360);
        //int count = 0;
        //cVerticesArray = CoordinateConverter.GPSPie(cx, cy, z, 15, angle, out count);
        //polyline = sgworld.Creator.CreatePolygonFromArray(cVerticesArray, sgworld.Creator.CreateColor(255, 215, 0, 255), sgworld.Creator.CreateColor(255, 215, 0, 255),


        /// <summary>
        ///
        /// </summary>
        /// <param name="x">中心点经度</param>
        /// <param name="y">中心点纬度</param>
        /// <param name="h">中心点高度</param>
        /// <param name="l">矩形宽度</param>
        /// <param name="w">矩形高度</param>
        /// <returns>矩形点集</returns>
        public static double[] GPSRectangle(double x, double y, double h, double l, double w, double dir)
        {
            //n = 4;
            double cosa = Math.Cos(dir * Math.PI / 180);
            double sina = Math.Sin(dir * Math.PI / 180);

            double[] ps = new double[] { -l / 2, w / 2, h, l / 2, w / 2, h, l / 2, -w / 2, h, -l / 2, -w / 2, h };
            double[] p = new double[12];
            double   ux, uy;

            //int zone;

            // 计算中心点 utm坐标
            CoordinateConverter.LatLonToUTMXY(y, x, out ux, out uy);

            // 计算四个顶点utm坐标
            for (int i = 0; i < 12; i += 3)
            {
                p[i]     = cosa * ps[i] + sina * ps[i + 1] + ux;
                p[i + 1] = -sina * ps[i] + cosa * ps[i + 1] + uy;
                p[i + 2] = h;
            }

            // 顶点坐标转换为经纬度坐标
            for (int i = 0; i < 12; i += 3)
            {
                CoordinateConverter.UTMXYToLatLon(p[i], p[i + 1], out ps[i + 1], out ps[i], false);
            }

            return(ps);
        }
Пример #2
0
        /// <summary>
        /// 计算两GPS点距离,返回以米为单位
        /// </summary>
        /// <param name="longitude1"></param>
        /// <param name="latitude1"></param>
        /// <param name="longitude2"></param>
        /// <param name="latitude2"></param>
        /// <returns></returns>
        public static double getUTMDistance(double longitude1, double latitude1, double longitude2, double latitude2)
        {
            double len = 0;
            double xx1, yy1, xx2, yy2;

            //int z1, z2;
            //CoordinateConverter.UTMXYToLatLon(517670.66484, 4032205.24460, out xx, out yy, 50, false);
            CoordinateConverter.LatLonToUTMXY(latitude1, longitude1, out xx1, out yy1);
            CoordinateConverter.LatLonToUTMXY(latitude2, longitude2, out xx2, out yy2);
            len = Math.Sqrt((xx1 - xx2) * (xx1 - xx2) + (yy1 - yy2) * (yy1 - yy2));
            return(len);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x">中心点经度</param>
        /// <param name="y">中心点纬度</param>
        /// <param name="h">中心点高度</param>
        /// <param name="r">半径,以米为单位</param>
        /// <param name="angle">角度,圆周360度</param>
        /// <param name="count">点的个数</param>
        /// <returns>圆周点集(经纬度,高度)</returns>
        public static double[] GPSPie(double x, double y, double h, double r, int angle, out int count)
        {
            int step = 5;

            count = angle / step + 1 + (angle % step > 0 ? 1 : 0);
            if (count == 1)
            {
                count = 0;
                return(null);
            }
            //double[] ps = new double[] { -l / 2, w / 2, h, l / 2, w / 2, h, l / 2, -w / 2, h, -l / 2, -w / 2, h };
            double[] p = new double[count * 3];
            double[] pd = new double[count * 3];
            double   a = 0;
            double   astep = Math.PI / 180 * step;
            double   ux, uy;
            int      i = 0;

            CoordinateConverter.LatLonToUTMXY(y, x, out ux, out uy);

            // 计算圆弧点utm坐标
            for (i = 0; i < 3 * (count - 1); a += astep, i += 3)
            {
                p[i]      = r * Math.Cos(a) + ux;
                p[i + 1]  = r * Math.Sin(a) + uy;
                pd[i + 2] = h;
            }
            //if (i == count){
            //    i --;
            p[i]      = r * Math.Cos(angle * Math.PI / 180) + ux;
            p[i + 1]  = r * Math.Sin(angle * Math.PI / 180) + uy;
            pd[i + 2] = h;
            //}

            for (i = 0; i < count * 3; i += 3)
            {
                CoordinateConverter.UTMXYToLatLon(p[i], p[i + 1], out pd[i + 1], out pd[i], false);
            }

            return(pd);
        }
Пример #4
0
        // 117.11726427,36.67414252


        public static void MarsToEarth(double[] marsLong, double[] marsLat, double[] earthLong, double[] earthLat,
                                       double[] newMarsLong, double[] newMarsLat, out double[] newEarthLong, out double[] newEarthLat)
        {
            int ptNum = marsLong.Length;

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


            int pN = newMarsLong.Length;

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

            newEarthLong = new double[pN];
            newEarthLat  = new double[pN];
            //double[] YYRes = new double[pN * 2];

            for (int i = 0; i < ptNum; i++)
            {
                CoordinateConverter.LatLonToUTMXY(marsLat[i], marsLong[i], out X[2 * i + 0, 0], out X[2 * i + 1, 0]);
                CoordinateConverter.LatLonToUTMXY(earthLat[i], earthLong[i], out Y[2 * i + 0, 0], out Y[2 * i + 1, 0]);
                CoordinateConverter.LatLonToUTMXY(newMarsLat[i], newMarsLong[i], out XX[2 * i + 0], out XX[2 * i + 1]);
            }

            CoordTrans4Param ct = new CoordTrans4Param();

            ct.CalculateTrans4Param(X, Y);
            for (int 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]);
                CoordinateConverter.UTMXYToLatLon(YY[i * 2 + 0], YY[i * 2 + 1], out newEarthLat[i], out newEarthLong[i]);
                //Console.WriteLine("准确的 x {0}, y {1}, 计算的 x {2} , y {3} ", YYRead[i * 2 + 0], YYRead[i * 2 + 1], YY84[i * 2 + 0], YY84[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);
            }
            //return YYRes;
        }
Пример #5
0
        //// 给定里程,计算经纬度朝向坐标
        //public CRWPosition getPosbyMeter(double m)
        //{
        //    CRWPosition pos = new CRWPosition();
        //    int index = 0;
        //    //x = y = z = 0; dir = 0;
        //    if (m < start)
        //    {
        //        pos.longitude = longitude[0];
        //        pos.latitude = latitude[0];
        //        pos.altitude = altitude[0];
        //        if (heading != null)
        //            pos.heading = heading[0];
        //        return pos;
        //    }
        //    if (m >= end)
        //    {
        //        pos.longitude = longitude[mPointNum - 1];
        //        pos.latitude = latitude[mPointNum - 1];
        //        pos.altitude = altitude[mPointNum - 1];
        //        if (heading != null)
        //            pos.heading = heading[mPointNum - 1];
        //        return pos;
        //    }
        //    int nm = (int)m;
        //    if (nm % 10 == 9)
        //    {
        //        index = nm / 10 + 1;
        //        pos.longitude = longitude[index];
        //        pos.latitude = latitude[index];
        //        pos.altitude = altitude[index];
        //        if (heading != null)
        //            pos.heading = heading[index];
        //    }
        //    else
        //    {
        //        index = nm / 10;
        //        if (nm % 10 == 0)
        //        {
        //            pos.longitude = longitude[index];
        //            pos.latitude = latitude[index];
        //            pos.altitude = altitude[index];
        //            if (heading != null)
        //                pos.heading = heading[index];
        //        }
        //        else
        //        {
        //            double t = (m - nm) / 10;
        //            pos.longitude = longitude[index] * (1 - t) + longitude[index + 1] * t;
        //            pos.latitude = latitude[index] * (1 - t) + latitude[index + 1] * t;
        //            pos.altitude = altitude[index] * (1 - t) + altitude[index + 1] * t;
        //            if (heading != null)
        //                pos.heading = heading[index] * (1 - t) + heading[index + 1] * t;
        //        }
        //    }
        //    return pos;
        //}

        /// <summary>
        /// 给定经纬度,输出里程与距离
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="mileage"></param>
        /// <param name="distance"></param>
        public void getMeterbyPos(double x, double y, out double mileage, out double distance)
        {
            int    errorNum = 0;
            double ux, uy;

            CoordinateConverter.LatLonToUTMXY(y, x, out ux, out uy);
            distance = 0;
            mileage  = 0;
            try
            {
                mileage = 0;

                int    count   = mPointNum;
                double mindist = (utmX[0] - ux) * (utmX[0] - ux) +
                                 (utmY[0] - uy) * (utmY[0] - uy);
                double dist = 10;
                int    step = (int)Math.Sqrt(count) + 1;
                //int i;
                int index = 0;
                for (int i = step; i < count; i += step)
                {
                    dist = (utmX[i] - ux) * (utmX[i] - ux) + (utmY[i] - uy) * (utmY[i] - uy);
                    if (dist < mindist)
                    {
                        mindist = dist;
                        index   = i;
                    }
                    errorNum = i;
                }

                int index2 = index;
                int j      = index - step;
                if (j < 0)
                {
                    j = 0;
                }
                for (; j < index + step && j < count; j++)
                {
                    dist = (utmX[j] - ux) * (utmX[j] - ux) + (utmY[j] - uy) * (utmY[j] - uy);
                    if (dist < mindist)
                    {
                        mindist = dist;
                        index2  = j;
                    }
                    errorNum = -j;
                }
                if (index2 > 0 && index2 < count - 1)
                {
                    double d1, d2;
                    d1      = Math.Sqrt(Math.Pow(utmX[index2 - 1] - ux, 2) + Math.Pow(utmY[index2 - 1] - uy, 2));
                    d2      = Math.Sqrt(Math.Pow(utmX[index2 + 1] - ux, 2) + Math.Pow(utmY[index2 + 1] - uy, 2));
                    mileage = meter[index2 - 1] + (meter[index2 + 1] - meter[index2 - 1]) * d1 / (d1 + d2);
                }
                else if (index2 == 0)
                {
                    double d1, d2;
                    d1      = Math.Sqrt(Math.Pow(utmX[0] - ux, 2) + Math.Pow(utmY[0] - uy, 2));
                    d2      = Math.Sqrt(Math.Pow(utmX[1] - ux, 2) + Math.Pow(utmY[1] - uy, 2));
                    mileage = (meter[1] - meter[0]) * d1 / (d1 + d2);
                }
                else
                {
                    double d1, d2;
                    d1      = Math.Sqrt(Math.Pow(utmX[count - 2] - ux, 2) + Math.Pow(utmY[count - 2] - uy, 2));
                    d2      = Math.Sqrt(Math.Pow(utmX[count - 1] - ux, 2) + Math.Pow(utmY[count - 1] - uy, 2));
                    mileage = meter[count - 2] + (meter[count - 1] - meter[count - 2]) * d1 / (d1 + d2);
                }
                double mx, my, mz, md;
                getPosbyLocalMeter(mileage, out mx, out my, out mz, out md);
                if (mIsReverse)
                {
                    mileage = mStart - mileage;
                }
                else
                {
                    mileage = mStart + mileage;
                }
                distance = CoordinateConverter.getUTMDistance(mx, my, x, y);
                //return mileage;
            }
            catch (Exception e)
            {
                Console.WriteLine("error num" + errorNum);
                //return -1;
            }
        }