Пример #1
0
        private static void ParseTrack(GPXLib gpx, JsonValue elem, int trackNum)
        {
            Trkseg segment = new Trkseg();

            foreach (JsonValue node in elem["nodes"])
            {
                Wpt wpt = new Wpt
                {
                    Lat           = node["x"],
                    Lon           = node["y"],
                    Ele           = node["z"],
                    EleSpecified  = node.ContainsKey("z") && node["z"] != 0,
                    Sat           = Convert.ToString((int)node["sat_qty"]),
                    Time          = Date.DateTimeFromUnixTimestampSeconds(node["t"]),
                    TimeSpecified = node.ContainsKey("t")
                };

                segment.TrkptList.Add(wpt);
                TrackMinMax(wpt.Lat, wpt.Lon);
            }

            Trk track = new Trk(String.Format("Track {0}", trackNum))
            {
                Number = trackNum.ToString()
            };

            track.TrksegList.Add(segment);

            gpx.TrkList.Add(track);
        }
Пример #2
0
        private static void WritePointsAsGpx(string outputPath, List <Position> sortedPoints)
        {
            var points = sortedPoints.Select(p => new Wpt((decimal)p.Latitude, (decimal)p.Longitude)
            {
                Time = p.Time.UtcDateTime, TimeSpecified = true
            }).ToList();

            if (!points.Any())
            {
                using (var se = new StreamWriter(System.Console.OpenStandardError()))
                {
                    se.WriteLine("Couldn't find any pictures with GPS coordinates");
                    return;
                }
            }
            var      gpx           = new GPXLib();
            int      trackIndex    = 0;
            DateTime lastPointTime = points[trackIndex].Time;

            foreach (var point in points)
            {
                if (point.Time.Subtract(lastPointTime).TotalHours > 5)
                {
                    trackIndex++;
                }
                lastPointTime = point.Time;
                gpx.AddTrackPoint($"maintrack{trackIndex}", 0, point);
            }

            gpx.SaveToFile(Path.Combine(outputPath, "track.gpx"));
            File.WriteAllText(Path.Combine(outputPath, "track.json"), JsonConvert.SerializeObject(sortedPoints));
        }
Пример #3
0
        private static void ParseTimezone(GPXLib gpx, JsonValue elem)
        {
            string       displayName  = "Local Time Zone";
            string       standardName = "Local Time";
            TimeSpan     offset       = TimeSpan.FromSeconds(elem["time_shift"]);
            TimeZoneInfo local        = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName);

            Date.TimeZone = local;
            //TODO save this timezone somewhere in gpx file
        }
Пример #4
0
        private static void ParseWaypoint(GPXLib gpx, JsonValue elem, int waypointNum)
        {
            Wpt waypoint = new Wpt
            {
                Name          = String.Format("Waypoint {0}", waypointNum),
                Lat           = elem["x"],
                Lon           = elem["y"],
                Ele           = elem["z"],
                EleSpecified  = elem.ContainsKey("z") && elem["z"] != 0,
                Sat           = Convert.ToString((int)elem["sat_qty"]),
                Time          = Date.DateTimeFromUnixTimestampSeconds(elem["t"]),
                TimeSpecified = elem.ContainsKey("t")
            };

            gpx.WptList.Add(waypoint);
            TrackMinMax(waypoint.Lat, waypoint.Lon);
        }
Пример #5
0
        private void TestingGpxLib()
        {
            var gpxLib = new GPXLib();

            gpxLib.LoadFromFile(Filename);
            Console.WriteLine("Loaded File");

            Console.WriteLine("===== Route Data =====");

            foreach (var route in gpxLib.RteList)
            {
                // ges all route data
                Console.WriteLine($"Route information for {route.Name}");
            }

            Console.WriteLine("===== Waypoint Data =====");
            foreach (var waypoint in gpxLib.WptList)
            {
                Console.WriteLine($"WAypoint information for {waypoint.Name}");
            }

            // Sample file only has Trackinformation
            Console.WriteLine("===== Track Data =====");
            foreach (var track in gpxLib.TrkList)
            {
                Console.WriteLine($"Track information for {track.Name}");

                foreach (var segment in track.TrksegList)
                {
                    Console.WriteLine($"Track information for segment.");
                    foreach (var point in segment.TrkptList)
                    {
                        // elevation will default to 0 is not provided
                        Console.WriteLine($"\t{point.Lat}\t{point.Lon}\t{point.Ele}");
                    }
                }
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            if (args.Length > 0 && File.Exists(args[0]))
            {
                var path = args[0];
                using (StreamReader sr = new StreamReader(path))
                {
                    var json = JsonValue.Parse(sr.ReadToEnd());

                    GPXLib gpx = new GPXLib();

                    var meta        = json["meta"];
                    var data        = json["data"];
                    var trackNum    = 0;
                    var waypointNum = 0;
                    foreach (JsonValue elem in data)
                    {
                        string type = elem["type"];
                        switch (type)
                        {
                        case "TZ":
                            ParseTimezone(gpx, elem);
                            break;

                        case "TRACK":
                            ParseTrack(gpx, elem, ++trackNum);
                            break;

                        case "NO_SIGNAL":
                            ParseNoSignal(gpx, elem);
                            break;

                        case "WAYPOINT":
                            ParseWaypoint(gpx, elem, ++waypointNum);
                            break;

                        case "STOP":
                            ParseStop(gpx, elem);
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                    }


                    gpx.Metadata.Name = "Starline GPX Track";

                    var startDate = Date.DateTimeFromUnixTimestampSeconds(Date.minSeconds);
                    var endDate   = Date.DateTimeFromUnixTimestampSeconds(Date.maxSeconds);
                    gpx.Metadata.Desc = String.Format("Track from {0} to {1}", startDate, endDate);

                    gpx.Creator = "starlineonline2gpx converter";

                    gpx.Metadata.Bounds.Maxlat = Maxlat;
                    gpx.Metadata.Bounds.Minlat = Minlat;
                    gpx.Metadata.Bounds.Maxlon = Maxlon;
                    gpx.Metadata.Bounds.Minlon = Minlon;
                    gpx.Metadata.Time          = startDate;
                    gpx.Metadata.TimeSpecified = true;

                    var author = new Person();
                    author.Link.Href    = @"https://github.com/DJm00n/starlineonline2gpx";
                    author.Email.Id     = @"dimitriy.ryazantcev";
                    author.Email.Domain = "gmail.com";
                    author.Name         = @"Dimitriy Ryazantcev";

                    gpx.Metadata.Author = author;


                    gpx.SaveToFile(Path.ChangeExtension(path, "gpx"));
                }
            }
        }
Пример #7
0
 private static void ParseStop(GPXLib gpx, JsonValue elem)
 {
     //throw new NotImplementedException();
 }