Esempio n. 1
0
        public static Shapefile NamedPointsFromGPX(GPXFile gpxFile, out List <int> shpIndexes)
        {
            shpIndexes = new List <int>();
            Shapefile sf;

            if (gpxFile.NamedWaypointsInLocalTime.Count > 0)
            {
                if (GPXMappingManager.WaypointsShapefile == null || GPXMappingManager.WaypointsShapefile.NumFields == 0)
                {
                    sf = new Shapefile();

                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                    {
                        sf.GeoProjection = globalMapping.GeoProjection;
                        sf.Key           = "gpxfile_waypoint";
                        sf.EditAddField("Name", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("TimeStamp", FieldType.DATE_FIELD, 1, 1);
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        GPXMappingManager.WaypointsShapefile = sf;
                    }
                }
                else
                {
                    sf = GPXMappingManager.WaypointsShapefile;
                }

                foreach (var wlt in gpxFile.NamedWaypointsInLocalTime)
                {
                    var shp = new Shape();
                    if (shp.Create(ShpfileType.SHP_POINT))
                    {
                        if (shp.AddPoint(wlt.Longitude, wlt.Latitude) >= 0)
                        {
                            var shpIndex = sf.EditAddShape(shp);
                            if (shpIndex >= 0)
                            {
                                sf.EditCellValue(sf.FieldIndexByName["Name"], shpIndex, wlt.Name);
                                sf.EditCellValue(sf.FieldIndexByName["TimeStamp"], shpIndex, wlt.Time);
                                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, gpxFile.GPS.DeviceName);
                                sf.EditCellValue(sf.FieldIndexByName["Filename"], shpIndex, gpxFile.FileName);
                                shpIndexes.Add(shpIndex);
                            }
                        }
                    }
                }

                sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle;
                sf.DefaultDrawingOptions.PointSize  = 12;
                sf.DefaultDrawingOptions.FillColor  = _mapWinGISUtils.ColorByName(tkMapColor.Red);
                return(sf);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public static int MapTrackGPX(GPXFile gpxfile, out List <int> handles)
 {
     handles = new List <int>();
     if (gpxfile.Tracks.Count > 0)
     {
         var sf = ShapefileFactory.TrackFromGPX(gpxfile, out handles);
         MapLayersHandler.AddLayer(sf, "GPX track", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
     }
     return(MapLayersHandler.CurrentMapLayer.Handle);
 }
Esempio n. 3
0
        public static void AppendGPX(GPXFile gpxFile, string fileNameGPX)
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.Load(fileNameGPX);

            // load v.1.0 elements
            DecodeGPX10(gpxFile, oDoc);
            // load v.1.1 elements
            DecodeGPX11(gpxFile, oDoc);
        }
Esempio n. 4
0
        public GpxInformation LoadFile(string fileName)
        {
            _gpxData  = new GpxInformation();
            _fileName = fileName;
            var gpx = new GPXFile(_fileName);

            LoadRoutes(gpx);
            LoadWayPoints(gpx);
            LoadTracks(gpx);
            return(_gpxData);
        }
        public static int MapGPX(GPXFile gpxFile, out int shpIndex, out List <int> handles, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (gpxFile != null)
                {
                    Shapefile sf = null;
                    if (gpxFile.TrackCount > 0)
                    {
                        //sf = ShapefileFactory.TrackFromGPX(gpxFile,out shpIndex);
                        sf = ShapefileFactory.TracksFromGPXFiles(gpxFile, out handles);
                        //var result = ShapefileFactory.CreateTripAndHaulsFromGPX(gpxFile);
                        //sf = result.Shapefile;
                        //handles.Add(result.Handle);
                        //Console.WriteLine($"shapefile with {sf.Shape[0].numPoints} created. Handle is {result.Handle}");
                        shpfileName = "GPX tracks";
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        sf          = ShapefileFactory.NamedPointsFromGPX(gpxFile, out handles);
                        shpfileName = "GPX waypoints";
                    }
                    //MapWindowForm.Title =$"Number of layers:{MapControl.NumLayers}";
                    MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);

                    if (gpxFile.TrackCount > 0)
                    {
                        GPXTracksLayer = MapLayersHandler.CurrentMapLayer;
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        GPXWaypointsLayer = MapLayersHandler.CurrentMapLayer;
                    }

                    return(MapLayersHandler.CurrentMapLayer.Handle);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                var ly = MapLayersHandler.get_MapLayer(gpxFile.FileName);
                MapLayersHandler.RemoveLayer(ly.Handle);
                return(-1);
            }
        }
 public static FishingTripAndGearRetrievalTracks MapTrackGPX(GPXFile gpxfile)
 {
     if (gpxfile.Tracks.Count > 0)
     {
         var result = ShapefileFactory.CreateTripAndHaulsFromGPX(gpxfile);
         if (result != null)
         {
             MapLayersHandler.AddLayer(result.TripShapefile, "GPX track", uniqueLayer: true, layerKey: result.TripShapefile.Key, rejectIfExisting: true);
         }
         return(result);
     }
     return(null);
 }
Esempio n. 7
0
        public static Shapefile TrackFromGPX(GPXFile gpxFile, out List <int> handles)
        {
            handles = new List <int>();
            var       shpIndex = -1;
            Shapefile sf;

            if (gpxFile.TrackWaypoinsInLocalTime.Count > 0)
            {
                if (GPXMappingManager.TrackShapefile == null || GPXMappingManager.TrackShapefile.NumFields == 0)
                {
                    sf = new Shapefile();
                    if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYLINE))
                    {
                        sf.EditAddField("GPS", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Filename", FieldType.STRING_FIELD, 1, 1);
                        sf.EditAddField("Length", FieldType.DOUBLE_FIELD, 1, 1);
                        sf.EditAddField("DateStart", FieldType.DATE_FIELD, 1, 1);
                        sf.EditAddField("DateEnd", FieldType.DATE_FIELD, 1, 1);
                        sf.Key           = "gpxfile_track";
                        sf.GeoProjection = GPXManager.entities.mapping.globalMapping.GeoProjection;
                        GPXMappingManager.TrackShapefile = sf;
                    }
                }
                else
                {
                    sf = GPXMappingManager.TrackShapefile;
                }

                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POLYLINE))
                {
                    foreach (var wlt in gpxFile.TrackWaypoinsInLocalTime)
                    {
                        shp.AddPoint(wlt.Longitude, wlt.Latitude);
                    }
                }
                shpIndex = sf.EditAddShape(shp);
                handles.Add(shpIndex);
                sf.EditCellValue(sf.FieldIndexByName["GPS"], shpIndex, gpxFile.GPS.DeviceName);
                sf.EditCellValue(sf.FieldIndexByName["FileName"], shpIndex, gpxFile.FileName);
                sf.EditCellValue(sf.FieldIndexByName["Length"], shpIndex, gpxFile.TrackLength);
                sf.EditCellValue(sf.FieldIndexByName["DateStart"], shpIndex, gpxFile.DateRangeStart);
                sf.EditCellValue(sf.FieldIndexByName["DateEnd"], shpIndex, gpxFile.DateRangeEnd);

                return(sf);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 8
0
 private void LoadWayPoints(GPXFile gpx)
 {
     foreach (var waypoint in gpx.GetWaypoints())
     {
         var wPoint = new WayPoint();
         wPoint.Name   = waypoint.name;
         wPoint.Source = _fileName;
         wPoint.Points = new List <wptType>()
         {
             waypoint
         };
         _gpxData.WayPoints.Add(wPoint);
     }
 }
Esempio n. 9
0
        private void OnMapShapeSelected(MapInterActionHandler s, LayerEventArg e)
        {
            if (CurrentLayer != null && CurrentLayer.LayerType == "ShapefileClass" && LayerSelector != null)
            {
                SelectedShapeIndexes = e.SelectedIndexes.ToList();
                if (SelectedShapeIndexes.Count > 0)
                {
                    var sf            = (Shapefile)CurrentLayer.LayerObject;
                    int fileNameField = sf.FieldIndexByName["Filename"];
                    int gpsField      = sf.FieldIndexByName["GPS"];

                    switch (LayerSelector.GetType().Name)
                    {
                    case "DataGrid":
                        var    dataGrid     = (System.Windows.Controls.DataGrid)LayerSelector;
                        string fileName     = sf.CellValue[fileNameField, SelectedShapeIndexes[0]];
                        string gps          = sf.CellValue[gpsField, SelectedShapeIndexes[0]];
                        string itemGPS      = "";
                        string itemFilename = "";
                        foreach (var item in dataGrid.Items)
                        {
                            switch (dataGrid.Name)
                            {
                            case "dataGridTrips":
                                Trip trip = (Trip)item;
                                itemGPS      = trip.GPS.DeviceName;
                                itemFilename = trip.Track.FileName;
                                break;

                            case "dataGridGPXFiles":
                                GPXFile gpxFile = (GPXFile)item;
                                itemGPS      = gpxFile.GPS.DeviceName;
                                itemFilename = gpxFile.FileName;
                                break;
                            }
                            if (itemGPS == gps && itemFilename == fileName)
                            {
                                dataGrid.SelectedItem = item;
                                dataGrid.ScrollIntoView(item);
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 10
0
        public static Shapefile GPXTrackVertices(GPXFile gpxfile, out List <int> shpIndexes)
        {
            shpIndexes = new List <int>();
            Shapefile sf;

            if (gpxfile.GPXFileType == GPXFileType.Track && gpxfile.TrackWaypoinsInLocalTime.Count > 0)
            {
                sf = new Shapefile();
                if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT))
                {
                    sf.EditAddField("Name", FieldType.INTEGER_FIELD, 1, 1);
                    sf.EditAddField("Time", FieldType.DATE_FIELD, 1, 1);
                    sf.Key           = "gpx_track_vertices";
                    sf.GeoProjection = globalMapping.GeoProjection;
                    GPXMappingManager.TrackVerticesShapefile = sf;
                }
            }
            else
            {
                sf = GPXMappingManager.TrackVerticesShapefile;
            }

            foreach (var wlt in gpxfile.TrackWaypoinsInLocalTime)
            {
                var shp = new Shape();
                if (shp.Create(ShpfileType.SHP_POINT))
                {
                    if (shp.AddPoint(wlt.Longitude, wlt.Latitude) >= 0)
                    {
                        var shpIndex = sf.EditAddShape(shp);
                        if (shpIndex >= 0)
                        {
                            sf.EditCellValue(sf.FieldIndexByName["Name"], shpIndex, shpIndex + 1);
                            sf.EditCellValue(sf.FieldIndexByName["Time"], shpIndex, wlt.Time);
                            shpIndexes.Add(shpIndex);
                        }
                    }
                }
            }
            sf.DefaultDrawingOptions.PointShape      = tkPointShapeType.ptShapeRegular;
            sf.DefaultDrawingOptions.PointSize       = 10;
            sf.DefaultDrawingOptions.PointSidesCount = 4;
            sf.DefaultDrawingOptions.FillColor       = _mapWinGISUtils.ColorByName(tkMapColor.Orange);
            sf.DefaultDrawingOptions.LineColor       = _mapWinGISUtils.ColorByName(tkMapColor.Black);
            sf.DefaultDrawingOptions.LineWidth       = 1.5f;
            return(sf);
        }
        private void LoadTracks(GPXFile gpx)
        {
            var trackIndex = 1;

            foreach (var track in gpx.GetTracks())
            {
                var gpxTrack = new Track();
                if (string.IsNullOrEmpty(track.name) && string.IsNullOrEmpty(gpx.Name))
                {
                    track.name = $"t{trackIndex.ToString()}";
                    trackIndex++;
                }
                gpxTrack.Name     = string.IsNullOrEmpty(track.name) ? gpx.Name : track.name;
                gpxTrack.Segments = track.trkseg;
                _gpxData.Tracks.Add(gpxTrack);
            }
        }
Esempio n. 12
0
        private void LoadRoutes(GPXFile gpx)
        {
            var routeIndex = 1;

            foreach (var route in gpx.GetRoutes())
            {
                var gpxRoute = new Route();
                if (string.IsNullOrEmpty(route.name))
                {
                    route.name = string.Format("r{0}", routeIndex.ToString());
                    routeIndex++;
                }
                gpxRoute.Name   = route.name;
                gpxRoute.Points = route.RouteWayPoints;
                _gpxData.Routes.Add(gpxRoute);
            }
        }
Esempio n. 13
0
        internal void Save(IEnumerable <wptType> waypoints, string fileName = null)
        {
            var gpxFile = new GPXFile();
            var gpx     = new gpxType();
            var rte     = new rteType();

            rte.name  = Title.Trim();
            rte.rtept = ToRoute().Points.ToArray();
            gpx.rte   = new List <rteType>()
            {
                rte
            }.ToArray();
            gpx.wpt = waypoints.ToArray();
            var fileNameToSave = string.IsNullOrEmpty(fileName) ? FileName : fileName;

            gpxFile.Save(fileNameToSave, gpx);
            IsInEditMode = false;
        }
Esempio n. 14
0
        /// <summary>
        /// rebuild gpxFile from Map Layers
        /// </summary>
        /// <param name="oLayerGPXPolylines"></param>
        /// <param name="oLayerGPXSymbols"></param>
        /// <returns></returns>
        public static GPXFile makeGPXfromMapLayers(LayerVectors oLayerGPXPolylines, LayerVectors oLayerGPXSymbols)
        {
            GPXFile gpxFile = new GPXFile();

            GPXTrk trk = new GPXTrk();
            gpxFile.trks.Add(trk);

            for (int i = 0; i < oLayerGPXPolylines.FeaturesCount; i++)
            {
                GPXTrkSeg seg = new GPXTrkSeg();

                Feature f = oLayerGPXPolylines.FeatureGet(i);
                if (f is PolylineFeature)
                {
                    PolylineFeature oPolyline = (PolylineFeature)f;

                    for (int ipart = 0; ipart < oPolyline.m_oParts.Count; ipart++)
                    {
                        Part part = oPolyline.m_oParts[ipart];
                        for (int ipoint = 0; ipoint < part.Points.Count; ipoint++)
                        {
                            DPoint layerPoint = part.Points[ipoint];
                            SymbolFeature symbol = (SymbolFeature)layerPoint.Tag;

                            double lon = layerPoint.X;
                            double lat = layerPoint.Y;
                            double ele = (double)symbol.getField("ele");
                            DateTime time = (DateTime)symbol.getField("time");

                            GpxWpt wpt = new GpxWpt(lon, lat, ele, time, -99);
                            wpt.selected = layerPoint.Selected;

                            seg.wpts.Add(wpt);
                        }
                    }
                }
                if (seg.wpts.Count > 0)
                {
                    trk.trkSeg.Add(seg);
                }
            }
            return gpxFile;
        }
Esempio n. 15
0
        public void Track_Compare_FromGeoFile_Conversion()
        {
            // ARRANGE
            Int32   transformedCount = 0;
            GeoFile geoFile          = gpxTrackFile.ToGeoFile();
            Int32   origionalCount   = geoFile.Routes[0].Points.Count;
            GPXFile gpxFile          = new GPXFile();

            // ACT
            Boolean success = gpxFile.FromGeoFile(geoFile);

            transformedCount = gpxFile.Routes[0].RoutePoints.Count; // Count of transformed track

            // ASSERT
            success.Should().BeTrue();
            gpxFile.Routes.Should().NotBeEmpty();
            gpxFile.Routes[0].RoutePoints.Should().NotBeEmpty();
            origionalCount.Should().Be(transformedCount);
        }
Esempio n. 16
0
        private void SaveSplitRoute(BikeTouringGISLayer obj)
        {
            var baseDirectory = Path.GetDirectoryName(obj.FileName);
            int i             = 1;

            foreach (var splitRoute in obj.SplitRoutes)
            {
                var filename = string.Format(@"{0}\{1}_{2}.gpx", baseDirectory, obj.SplitPrefix, i);
                var gpxFile  = new GPXFile();
                var gpx      = new gpxType();
                var rte      = new rteType();
                rte.name  = $"{i}_{obj.SplitPrefix}";
                rte.rtept = splitRoute.Points.ToArray();
                gpx.rte   = new List <rteType>()
                {
                    rte
                }.ToArray();
                gpxFile.Save(filename, gpx);
                i++;
            }
        }
Esempio n. 17
0
 public void Bind(GPXFile gpxFile)
 {
     this.gpxFile = gpxFile;
     InitScroll();
 }
Esempio n. 18
0
        /// <summary>
        /// create features on layer based on gpxFile object
        /// </summary>
        /// <param name="gpxFile"></param>
        /// <param name="oLayerGPXPolylines"></param>
        /// <param name="oLayerGPXSymbols"></param>
        public static void makeMapLayersFromGPX(GPXFile gpxFile, LayerVectors oLayerGPXPolylines, LayerVectors oLayerGPXSymbols)
        {
            oLayerGPXSymbols.FeaturesClear();
            oLayerGPXPolylines.FeaturesClear();

            // fill layers with data
            if (gpxFile != null)
            {
                for (int iTrk = 0; iTrk < gpxFile.trks.Count; iTrk++)
                {
                    GPXTrk trk = gpxFile.trks[iTrk];

                    for (int iSeg = 0; iSeg < trk.trkSeg.Count; iSeg++)
                    {
                        GPXTrkSeg seg = trk.trkSeg[iSeg];
                        List<DPoint> oPoints1 = new List<DPoint>();

                        for (int iWpt = 0; iWpt < seg.wpts.Count; iWpt++)
                        {
                            GpxWpt wpt = seg.wpts[iWpt];

                            DPoint oPoint = new DPoint(wpt.lon, wpt.lat);
                            oPoint.Selected = wpt.selected;

                            oPoints1.Add(oPoint);

                            // add gpx point
                            Feature oSymbol = FeatureFactory.CreateSymbol(wpt.lon, wpt.lat, (uint)0xFF00FF00);
                            oSymbol.Tag = oPoint;
                            oLayerGPXSymbols.FeaturesAdd(oSymbol);

                            // link point to symbol and symbol to point
                            oPoint.Tag = oSymbol;

                            // fill data
                            oSymbol.setField("lat", wpt.lat);
                            oSymbol.setField("lon", wpt.lon);
                            oSymbol.setField("ele", wpt.ele);
                            oSymbol.setField("time", wpt.time);
                        }
                        if (oPoints1.Count > 0)
                        {
                            PolylineFeature oPolyline1 = FeatureFactory.CreatePolyline(oPoints1, new Style(Color.Green));
                            oLayerGPXPolylines.FeaturesAdd(oPolyline1);
                        }
                    }
                }
            }
        }
Esempio n. 19
0
        private static void DecodeGPX11(GPXFile gpxFile, XmlDocument oDoc)
        {
            XmlNamespaceManager manager = new XmlNamespaceManager(oDoc.NameTable);
            manager.AddNamespace("oo", "http://www.topografix.com/GPX/1/1");

            XmlNodeList oTracks = oDoc.SelectNodes("oo:gpx/oo:trk", manager);
            foreach (XmlNode xmltrk in oTracks)
            {
                GPXTrk gpxtrk = new GPXTrk();
                gpxtrk.parent = gpxFile;
                gpxFile.trks.Add(gpxtrk);

                XmlNode nameNode = xmltrk.SelectSingleNode("oo:name", manager);
                if (nameNode != null) gpxtrk.name = nameNode.InnerText;
                XmlNode cmtNode = xmltrk.SelectSingleNode("oo:cmt", manager);
                if (cmtNode != null) gpxtrk.cmt = cmtNode.InnerText;
                XmlNode descNode = xmltrk.SelectSingleNode("oo:desc", manager);
                if (descNode != null) gpxtrk.desc = descNode.InnerText;

                XmlNodeList oTrkSeg = xmltrk.SelectNodes("oo:trkseg", manager);
                foreach (XmlNode xmlseg in oTrkSeg)
                {
                    GPXTrkSeg gpxseg = new GPXTrkSeg();
                    gpxseg.parent = gpxtrk;
                    gpxtrk.trkSeg.Add(gpxseg);
                    XmlNodeList oTrackPoints = xmlseg.SelectNodes("oo:trkpt", manager);

                    foreach (XmlNode oTrkPt in oTrackPoints)
                    {
                        string sLat = oTrkPt.Attributes.GetNamedItem("lat").Value;
                        string sLon = oTrkPt.Attributes.GetNamedItem("lon").Value;

                        string sTime = "";
                        XmlNode nodeTime = oTrkPt.SelectSingleNode("oo:time", manager);
                        if (nodeTime != null)
                        {
                            sTime = nodeTime.InnerText;
                        }

                        XmlNode oN = oTrkPt.SelectSingleNode("oo:ele", manager);
                        string sEle = "-9999";
                        if (oN != null)
                        {
                            sEle = oN.InnerText;
                        }
                        string sSpeed = "0";
                        oN = oTrkPt.SelectSingleNode("oo:speed", manager);
                        if (oN != null)
                        {
                            sSpeed = oN.InnerText;
                        }

                        double dLat = Convert.ToDouble(sLat, CultureInfo.InvariantCulture);
                        double dLon = Convert.ToDouble(sLon, CultureInfo.InvariantCulture);

                        DateTime dDTime;
                        DateTime dDTime_utc;
                        if (sTime != "")
                        {
                            //DateTime t1 = DateTime.Parse("2009-07-05T09:06:07Z", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                            //DateTime t2 = DateTime.Parse("2009-07-05T09:06:07", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);

                            dDTime = DateTime.Parse(sTime, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                            dDTime_utc = dDTime.ToUniversalTime();
                        }
                        else
                        {
                            dDTime = DateTime.MinValue;
                            dDTime_utc = DateTime.MinValue;
                        }

                        double dEle = Convert.ToDouble(sEle, CultureInfo.InvariantCulture);
                        double dSpeed = Convert.ToDouble(sSpeed, CultureInfo.InvariantCulture);

                        GpxWpt wpt = new GpxWpt(dLon, dLat, dEle, dDTime_utc, dSpeed);
                        wpt.parent = gpxseg;
                        gpxseg.wpts.Add(wpt);
                    }
                }
            }
            return;
        }
Esempio n. 20
0
        internal static string TimeSpan(GPXFile gpxFile)
        {
            DateTime minTime = DateTime.MinValue;
            DateTime maxTime = DateTime.MinValue;

            string message = "";
            foreach (GPXTrk trk in gpxFile.trks)
            {
                foreach (GPXTrkSeg seg in trk.trkSeg)
                {
                    foreach (GpxWpt wpt in seg.wpts)
                    {
                        if (wpt.time != DateTime.MinValue)
                        {
                            if (minTime == DateTime.MinValue) minTime = wpt.time;
                            if (maxTime == DateTime.MinValue) maxTime = wpt.time;
                            if (wpt.time < minTime) minTime = wpt.time;
                            if (wpt.time > maxTime) maxTime = wpt.time;
                        }
                    }
                }
            }

            if (minTime != DateTime.MinValue && maxTime != DateTime.MinValue)
            {
                TimeSpan ts = maxTime - minTime;
                message = ts.ToString();
            }
            else
            {
                message = "no available";
            }
            return message;
        }
Esempio n. 21
0
        public static void SaveGPXv11(GPXFile gpxFile, string fileNameGPX)
        {
            XmlDocument oDoc = new XmlDocument();

            const string namespaceUri = "http://www.topografix.com/GPX/1/1";

            XmlNode nodeRoot = oDoc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            oDoc.AppendChild(nodeRoot);

            XmlNode nodeGpx = oDoc.CreateElement("", "gpx", namespaceUri);
            oDoc.AppendChild(nodeGpx);

            XmlAttribute att = oDoc.CreateAttribute("version");
            att.Value = "1.1";
            nodeGpx.Attributes.Append(att);

            att = oDoc.CreateAttribute("xmlns:xsi");
            att.Value = "http://www.w3.org/2001/XMLSchema-instance";
            nodeGpx.Attributes.Append(att);

            att = oDoc.CreateAttribute("xsi:schemaLocation");
            att.Value = "http://www.topografix.com/GPX/1/1/gpx.xsd";
            nodeGpx.Attributes.Append(att);

            XmlNode nodeTrk = oDoc.CreateElement("", "trk", namespaceUri);
            nodeGpx.AppendChild(nodeTrk);

            for (int iTrk = 0; iTrk < gpxFile.trks.Count; iTrk++)
            {
                GPXTrk trk = gpxFile.trks[iTrk];

                for (int iSeg = 0; iSeg < trk.trkSeg.Count; iSeg++)
                {
                    GPXTrkSeg seg = trk.trkSeg[iSeg];

                    XmlNode nodeTrkseg = oDoc.CreateElement("", "trkseg", namespaceUri);

                    if (seg.wpts.Count > 0)
                    {
                        nodeTrk.AppendChild(nodeTrkseg);

                        for (int iWpt = 0; iWpt < seg.wpts.Count; iWpt++)
                        {
                            GpxWpt wp = seg.wpts[iWpt];

                            XmlNode nodeTrkpt = oDoc.CreateElement("", "trkpt", namespaceUri);

                            XmlAttribute attTrkpt;
                            attTrkpt = oDoc.CreateAttribute("lat");
                            attTrkpt.Value = Convert.ToString(wp.lat, CultureInfo.InvariantCulture);
                            nodeTrkpt.Attributes.Append(attTrkpt);
                            attTrkpt = oDoc.CreateAttribute("lon");
                            attTrkpt.Value = Convert.ToString(wp.lon, CultureInfo.InvariantCulture);
                            nodeTrkpt.Attributes.Append(attTrkpt);

                            if (wp.ele > -500)
                            {
                                XmlNode nodeEle = oDoc.CreateElement("", "ele", namespaceUri);
                                nodeEle.InnerText = Convert.ToString(wp.ele, CultureInfo.InvariantCulture);
                                nodeTrkpt.AppendChild(nodeEle);
                            }

                            if (wp.time != null)
                            {
                                if (wp.time > DateTime.MinValue)
                                {
                                    XmlNode nodeTime = oDoc.CreateElement("", "time", namespaceUri);
                                    nodeTime.InnerText = XmlConvert.ToString(wp.time, "yyyy-MM-ddTHH:mm:ss");
                                    nodeTrkpt.AppendChild(nodeTime);
                                }
                            }

                            nodeTrkseg.AppendChild(nodeTrkpt);
                        }
                    }
                }
            }

            oDoc.Save(fileNameGPX);

            // validate resulting file
            //...
            GPXValidator validator = new GPXValidator();
            string error = validator.validate(fileNameGPX);
            if (error != "") MessageBox.Show(error);
        }
Esempio n. 22
0
 public void Bind(GPXFile gpxFile)
 {
     this.gpxFile = gpxFile;
 }
Esempio n. 23
0
 public GPXTests()
 {
     gpxTrackFile = base.GetXMLData <GPXFile>("GPXFiles/GPXRouteOnly.gpx");
 }
Esempio n. 24
0
 public SplitTests()
 {
     gpxTrackFile = base.GetXMLData <GPXFile>("GPXFiles/HalfMarathon.gpx");
 }
Esempio n. 25
0
        private void fillTreeWithGPX(GPXFile gpxFile, TreeView treeView1)
        {
            treeView1.Visible = false; // hack to prevent flickering
            treeView1.Nodes.Clear();
            if (gpxFile == null) return;

            foreach (GPXTrk trk in gpxFile.trks)
            {
                TreeNode nodeTrk = new TreeNode("Track: " + trk.name);
                treeView1.Nodes.Add(nodeTrk);
                nodeTrk.Tag = trk;
                nodeTrk.Checked = trk.selected;

                foreach (GPXTrkSeg trkseg in trk.trkSeg)
                {
                    string name = "Segment with " + trkseg.wpts.Count + " points.";
                    TreeNode nodeSeg = new TreeNode(name);
                    nodeSeg.Tag = trkseg;
                    nodeSeg.Checked = trkseg.selected;

                    nodeTrk.Nodes.Add(nodeSeg);
                }
                nodeTrk.Expand();
            }
            treeView1.Visible = true;
        }
Esempio n. 26
0
 public CompareTests()
 {
     tcxTrackFile = base.GetXMLData <TCXFile>("TCXFiles/HalfMarathon.tcx");
     gpxTrackFile = base.GetXMLData <GPXFile>("GPXFiles/HalfMarathon.gpx");
 }
Esempio n. 27
0
        private void openMoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String fileName = @"d:\rav\Private\rv130_gps_tracks\Data_slady_gps_Logger\sandiego2\2010-04-17_sd.gpx";
            openFileDialog1.FileName = fileName;
            openFileDialog1.Filter = "GPX track files (*.gpx)|*.gpx|All files (*.*)|*.*";
            openFileDialog1.Multiselect = true;
            DialogResult res = openFileDialog1.ShowDialog();
            if (res == DialogResult.Cancel)
                return;

            // load GPX file
            GPXFile gpxFile = new GPXFile();
            foreach (string file in openFileDialog1.FileNames)
            {
                try
                {
                    gpxPresenter.LoadAndAppend(file);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to load gpx file. " + ex.Message);
                }
            }

            if (openFileDialog1.FileNames.GetLength(0) > 0)
                fileName = openFileDialog1.FileNames[0];

            setCurrentGPX(fileName);
        }
Esempio n. 28
0
        internal static double CalcLength(GPXFile gpxFile)
        {
            double len = 0;
            foreach (GPXTrk trk in gpxFile.trks)
            {
                foreach (GPXTrkSeg seg in trk.trkSeg)
                {
                    if (seg.wpts.Count > 1)
                    {
                        for (int i = 1; i < seg.wpts.Count; i++)
                        {
                            GpxWpt wpt1 = seg.wpts[i - 1];
                            GpxWpt wpt2 = seg.wpts[i];

                            len = len + distance(wpt1.lon, wpt1.lat, wpt2.lon, wpt2.lat);
                        }
                    }
                }
            }
            return len;
        }