Esempio n. 1
0
        private void TestFunc2(string filePath)
        {
            List <TrackPointItem> trkPtList = new List <TrackPointItem>();

            DateTime target = DateTime.Parse("2010/04/25 12:21:09");

            using (System.Xml.XmlReader xr = System.Xml.XmlReader.Create(new System.IO.StreamReader(filePath)))
            {
                while (xr.Read())
                {
                    switch (xr.NodeType)
                    {
                    case System.Xml.XmlNodeType.Element:
                        System.Diagnostics.Debug.Print(xr.Name);
                        if (0 == string.Compare(xr.Name, "trkpt", true))
                        {
                            string sxml = xr.ReadOuterXml();

                            string lon = xr.GetAttribute("lon");
                            string lat = xr.GetAttribute("lat");

                            TrackPointItem item = GetLocData(sxml);

                            trkPtList.Add(item);

                            if (0 == item.CompareTo(target))
                            {
                                UInt32[] re = item.LonArray();

                                UInt32[] el = item.EleArray();

                                UInt32[] sp = item.SpeedArray();

                                string s = string.Format("http://maps.google.com/maps?q={0},{1}", item.Lat, item.Lon);
                                System.Diagnostics.Process.Start(s);

                                System.Diagnostics.Debug.Print("");
                            }
                        }
                        break;

                    case System.Xml.XmlNodeType.Text:
                        System.Diagnostics.Debug.Print(xr.Value);
                        break;

                    default:
                        System.Diagnostics.Debug.Print(xr.NodeType.ToString());
                        break;
                    }
                }
            }

            trkPtList.Sort();

            return;
        }
Esempio n. 2
0
        private TrackPointItem GetLocData(string trkptXml)
        {
            string lon    = string.Empty;
            string lat    = string.Empty;
            string sEle   = string.Empty;
            string sTime  = string.Empty;
            string sSpeed = string.Empty;

            using (System.Xml.XmlReader xr = System.Xml.XmlReader.Create(new System.IO.StringReader(trkptXml)))
            {
                while (xr.Read())
                {
                    switch (xr.NodeType)
                    {
                    case System.Xml.XmlNodeType.Element:
                        if (0 == string.Compare(xr.Name, "ele", true))
                        {
                            sEle = xr.ReadString();
                        }
                        else if (0 == string.Compare(xr.Name, "time", true))
                        {
                            sTime = xr.ReadString();
                        }
                        else if (0 == string.Compare(xr.Name, "speed", true))
                        {
                            sSpeed = xr.ReadString();
                        }
                        else if (0 == string.Compare(xr.Name, "trkpt", true))
                        {
                            lon = xr.GetAttribute("lon");
                            lat = xr.GetAttribute("lat");
                        }
                        break;
                    }
                }
            }

            TrackPointItem trkPt = new TrackPointItem(lon, lat, DateTime.Parse(sTime));

            trkPt.Speed = sSpeed;
            trkPt.Ele   = sEle;

            return(trkPt);
        }
Esempio n. 3
0
        private List <TrackPointItem> LoadGpxFile(string filePath)
        {
            List <TrackPointItem> trkPtList = new List <TrackPointItem>();

            using (System.Xml.XmlReader xr = System.Xml.XmlReader.Create(new System.IO.StreamReader(filePath)))
            {
                while (xr.Read())
                {
                    switch (xr.NodeType)
                    {
                    case System.Xml.XmlNodeType.Element:
                        //System.Diagnostics.Debug.Print(xr.Name);
                        if (0 == string.Compare(xr.Name, "trkpt", true))
                        {
                            string sxml = xr.ReadOuterXml();

                            string lon = xr.GetAttribute("lon");
                            string lat = xr.GetAttribute("lat");

                            TrackPointItem item = GetLocData(sxml);

                            trkPtList.Add(item);
                        }
                        break;

/*
 *                      case System.Xml.XmlNodeType.Text:
 *                          System.Diagnostics.Debug.Print(xr.Value);
 *                          break;
 *
 *                      default:
 *                          System.Diagnostics.Debug.Print(xr.NodeType.ToString());
 *                          break;*/
                    }
                }
            }

            return(trkPtList);
        }
Esempio n. 4
0
        /// <summary>
        /// GPXファイルの読み込み
        /// </summary>
        /// <param name="filePath">GPXファイルのパス</param>
        /// <returns>PGXから読み込んだ座標情報リスト</returns>
        private static List <TrackPointItem> LoadGpxFile(string filePath)
        {
            List <TrackPointItem> trkPtList = new List <TrackPointItem>();

            using (System.Xml.XmlReader xr = System.Xml.XmlReader.Create(new System.IO.StreamReader(filePath)))
            {
                while (xr.Read())
                {
                    switch (xr.NodeType)
                    {
                    case System.Xml.XmlNodeType.Element:
                        if (0 == string.Compare(xr.Name, "trkpt", true))
                        {
                            if (!xr.IsEmptyElement)
                            {
                                string lon = xr.GetAttribute("lon");
                                string lat = xr.GetAttribute("lat");

                                string sEle   = string.Empty;
                                string sTime  = string.Empty;
                                string sSpeed = string.Empty;

                                while (xr.Read())
                                {
                                    switch (xr.NodeType)
                                    {
                                    case System.Xml.XmlNodeType.Element:
                                        if (0 == string.Compare(xr.Name, "ele", true))
                                        {
                                            sEle = xr.ReadString();
                                        }
                                        else if (0 == string.Compare(xr.Name, "time", true))
                                        {
                                            sTime = xr.ReadString();
                                        }
                                        else if (0 == string.Compare(xr.Name, "speed", true))
                                        {
                                            sSpeed = xr.ReadString();
                                        }
                                        else
                                        {
                                            if (!xr.IsEmptyElement)
                                            {
                                                while (xr.Read())
                                                {
                                                    if (xr.NodeType == System.Xml.XmlNodeType.EndElement)
                                                    {
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        continue;

                                    case System.Xml.XmlNodeType.EndElement:
                                        break;

                                    default:
                                        continue;
                                    }
                                    break;
                                }

                                DateTime dt;
                                if (DateTime.TryParse(sTime, out dt))
                                {
                                    TrackPointItem item = new TrackPointItem(lon, lat, dt);
                                    item.Speed = sSpeed;
                                    item.Ele   = sEle;
                                    trkPtList.Add(item);
                                }
                            }
                        }
                        break;
                    }
                }
            }

            return(trkPtList);
        }