예제 #1
0
        //public const double ε = 1;

        public static Point GetPoint(this EarthPoint ep)
        {
            return(new Point()
            {
                X = c * ep.LongitudeRad,
                Y = c * Math.Log(0.5 * ep.LatitudeRad + Math.PI / 4)
            });
        }
예제 #2
0
        static void Main(string[] args)
        {
            var p1 = new EarthPoint(77.1539, -139.398);
            var p2 = new EarthPoint(-77.1804, -139.55);

            var r = p1.DistanceTo(p2);

            String GpxPath = args[0];
            String TxtPath = args[1];

            var gpx = XDocument.Load(GpxPath).Root;
            var EarthPoints =
                gpx.Element("trk").Element("trkseg")
                    .Elements("trkpt")
                    .Select(XPoint =>
                        new EarthPoint((Double)XPoint.Attribute("lat"), (Double)XPoint.Attribute("lon")))
                    .ToList();

            using (TextWriter tw = new StreamWriter(TxtPath))
            {
                EarthPoint prewPoint = null;
                double x = 0;
                foreach (var p in EarthPoints)
                {
                    if (prewPoint != null)
                        x += p.DistanceTo(prewPoint);
                    prewPoint = p;

                    var s = string.Format(System.Globalization.CultureInfo.InvariantCulture.NumberFormat,
                                          "{{ {0:F6}, {1:F6}, {2:F0} }},", p.Latitude, p.Longitude, x);
                    tw.WriteLine(s);
                    Console.WriteLine(s);
                }
            }

            Console.ReadLine();
        }
예제 #3
0
        private static IEnumerable<PositionedGObject> PositeObjects(GSection sec, GPost post)
        {
            GPost p2 = sec.Posts
                        .Where(pp =>   (int)post.Direction * (post.Ordinate - pp.Ordinate) > 0)
                        .OrderBy(pp => (int)post.Direction * (post.Ordinate - pp.Ordinate)).FirstOrDefault();

            if (p2 == null) yield break;

            double l = post.Point.DistanceTo(p2.Point);
            foreach (var o in post.Tracks.First().Objects)
            {
                double ratio = (o.Ordinate - post.Ordinate) / l;
                var o_point =
                    new EarthPoint(
                        (1 - ratio) * post.Point.Latitude  + ratio * p2.Point.Latitude,
                        (1 - ratio) * post.Point.Longitude + ratio * p2.Point.Longitude);
                yield return new PositionedGObject() { Object = o, Point = o_point };
            }
        }
예제 #4
0
 public static Double EstimateDistances(this EarthPoint p1, EarthPoint p2)
 {
     return Math.Pow(Math.Sin((p2.LatitudeRad - p1.LatitudeRad) / 2), 2)
         + Math.Cos(p1.LatitudeRad) * Math.Cos(p2.LatitudeRad) * Math.Pow(Math.Sin((p2.LongitudeRad - p1.LongitudeRad) / 2), 2);
 }
예제 #5
0
 /// <summary>
 /// Возвращает расстояние между точками по теореме гаверсинусов
 /// </summary>
 /// <param name="p1">Первая точка</param>
 /// <param name="p2">Вторая точка</param>
 /// <returns>Расстояние между точками в метрах</returns>
 public static Double DistanceTo(this EarthPoint p1, EarthPoint p2)
 {
     return 2 * c * Math.Asin(Math.Sqrt(EstimateDistances(p1, p2)));
 }
예제 #6
0
 public static Double EstimateDistances(this EarthPoint p1, EarthPoint p2)
 {
     return(Math.Pow(Math.Sin((p2.LatitudeRad - p1.LatitudeRad) / 2), 2)
            + Math.Cos(p1.LatitudeRad) * Math.Cos(p2.LatitudeRad) * Math.Pow(Math.Sin((p2.LongitudeRad - p1.LongitudeRad) / 2), 2));
 }
예제 #7
0
 /// <summary>
 /// Возвращает расстояние между точками по теореме гаверсинусов
 /// </summary>
 /// <param name="p1">Первая точка</param>
 /// <param name="p2">Вторая точка</param>
 /// <returns>Расстояние между точками в метрах</returns>
 public static Double DistanceTo(this EarthPoint p1, EarthPoint p2)
 {
     return(2 * c * Math.Asin(Math.Sqrt(EstimateDistances(p1, p2))));
 }