private void newGpxFile(string Name, string Path)
        {
            FileStream readFile  = File.Open(Path, FileMode.Open);
            FileStream writeFile = File.OpenWrite("../../Files/" + Name);

            GpxReader reader = new GpxReader(readFile);
            GpxWriter writer = new GpxWriter(writeFile);

            while (reader.Read())
            {
                switch (reader.ObjectType)
                {
                case GpxObjectType.Metadata:
                    writer.WriteMetadata(reader.Metadata);
                    break;

                case GpxObjectType.WayPoint:
                    writer.WriteWayPoint(reader.WayPoint);
                    break;

                case GpxObjectType.Route:
                    writer.WriteRoute(reader.Route);
                    break;

                case GpxObjectType.Track:
                    writer.WriteTrack(reader.Track);
                    break;
                }
            }
            readFile.Close();
            writeFile.Close();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var      input       = new FileStream(@"C:\perso\Night ride\Night ride 2nd part.gpx", FileMode.Open);
            var      output      = new FileStream(@"C:\perso\Night ride\Night ride 2nd part_with_timespamp.gpx", FileMode.Create);
            DateTime startTime   = DateTime.Parse("2020-07-06T23:35:28");
            DateTime endTime     = DateTime.Parse("2020-07-07T00:35:28");
            double   totalPoints = 1379;
            int      p           = 0;

            using (GpxReader reader = new GpxReader(input))
            {
                using (GpxWriter writer = new GpxWriter(output))
                {
                    while (reader.Read())
                    {
                        switch (reader.ObjectType)
                        {
                        case GpxObjectType.Metadata:
                            writer.WriteMetadata(reader.Metadata);
                            break;

                        case GpxObjectType.WayPoint:
                            writer.WriteWayPoint(reader.WayPoint);
                            break;

                        case GpxObjectType.Route:
                            writer.WriteRoute(reader.Route);
                            break;

                        case GpxObjectType.Track:
                            var track = reader.Track;
                            foreach (var seg in track.Segments)
                            {
                                foreach (var point in seg.TrackPoints)
                                {
                                    point.Time = startTime.AddSeconds(p * (endTime - startTime).TotalSeconds / totalPoints);
                                    Console.WriteLine($"time = {point.Time}");
                                    p++;
                                }
                            }
                            writer.WriteTrack(track);
                            break;
                        }
                    }
                }
            }
        }
예제 #3
0
    public static IList <Coordinates> GetGPXPoints()
    {
        IList <Coordinates> lst = new List <Coordinates>();

        //Reading the GOX
        Debug.Log(("Reading GPX"));


        StreamReader input = new StreamReader(@"C:\Users\Chris\Documents\UnityProjects\CreateObject\Assets\gpxfiles\Heffers.gpx", Encoding.Default);
        // StreamReader input = new StreamReader(@"C:\Users\Chris\Documents\UnityProjects\CreateObject\Assets\chop.gpx", Encoding.Default);
        // StreamReader input = new StreamReader(@"C:\Users\Chris\Documents\UnityProjects\CreateObject\Assets\Perth worlds qualifier.gpx", Encoding.Default);

        MemoryStream m = new MemoryStream();

        using (GpxReader reader = new GpxReader(input.BaseStream))
        {
            using (GpxWriter writer = new GpxWriter(m))
            {
                while (reader.Read())
                {
                    switch (reader.ObjectType)
                    {
                    case GpxObjectType.Metadata:
                        Debug.Log(("Metadata"));
                        writer.WriteMetadata(reader.Metadata);
                        break;

                    case GpxObjectType.WayPoint:
                        Debug.Log(("Point"));
                        writer.WriteWayPoint(reader.WayPoint);
                        break;

                    case GpxObjectType.Route:
                        Debug.Log(("Route"));
                        writer.WriteRoute(reader.Route);
                        break;

                    case GpxObjectType.Track:
                        Debug.Log(("Track"));
                        writer.WriteTrack(reader.Track);


                        //Set a local origin
                        //GPSEncoder.SetLocalOrigin(new Vector2((float)originCoords.latitude, (float)originCoords.longitude));

                        //Coordinates origin = new  Coordinates(1.289639, -3532648, 1);


                        IList <GpxTrackSegment> segments = reader.Track.Segments;
                        IList <GpxTrackPoint>   tp       = segments[0].TrackPoints;
                        foreach (GpxTrackPoint item in tp)
                        {
                            Debug.Log(("lat" + item.Latitude));
                            Debug.Log(("lng" + item.Longitude));
                            Debug.Log(("e" + item.Elevation));

                            //Coordinates c = new Coordinates(item.Latitude, item.Longitude, item.Elevation.Value);
                            //Vector3 v = c.convertCoordinateToVector();
                            Coordinates currentLocation;
                            currentLocation = new Coordinates(item.Latitude, item.Longitude, item.Elevation.Value);



                            lst.Add(currentLocation);

                            //   UnityEngine.GameObject o = (GameObject)Instantiate(prefab, new Vector3(v.x, v.y, v.z), Quaternion.identity);
                            //UnityEngine.GameObject o = (GameObject)Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
                            // o.transform.parent = sourceGO.transform;
                        }


                        break;
                    }
                }
            }
        }


        return(lst);
    }