public GpxParser(string fileName, TrackPath path)
 {
     try {
         StreamReader sr = new StreamReader(fileName);
         string file = sr.ReadToEnd();
         sr.Close();
         _doc = new XmlDocument();
         _doc.LoadXml(file);
         XmlNode node = _doc.ChildNodes[0];
         foreach (XmlNode n in _doc.ChildNodes) {
             if (n.Name == "gpx") { node = n; break; }
         }
         foreach (XmlNode n in node) {
             if (n.Name == "trk") { node = n; break; }
         }
         foreach (XmlNode n in node) {
             if (n.Name == "trkseg") { node = n; break; }
         }
         foreach (XmlNode n in node.ChildNodes) {
             if (n.Name == "trkpt") {
                 Location loc = new Location(double.Parse(n.Attributes[0].Value)
                 , double.Parse(n.Attributes[1].Value));
                 loc.Elevation = double.Parse(n.FirstChild.InnerText);
                 path.Locations.Add(loc);
             }
         }
         _status = "Read " + path.Locations.Count + " Locations";
     } catch (Exception e) {
         //_status = e.Message;
         _status = "Parsing error, cannot read input file.";
         path.Locations.Clear();
     }
 }
 /// <summary>
 /// constructor for pathfinder strategy
 /// </summary>
 public PathfinderStrategy()
 {
     _turns = new List<Turn>();
     _turnImages = new List<Image>();
     _pois = new List<PointOfInterest>();
     _path = new TrackPath();
     _web = new WebInterface();
     _cache = new CacheStrategy();
     _rideMapFid = new FiducialStrategy();
     _turnMapFid = new FiducialStrategy();
     _rideMpaPainter = new MapPainter(_rideMapFid);
     _turnMapPainter = new MapPainter(_turnMapFid);
 }
Exemple #3
0
 /// <summary>
 /// constructor for pathfinder strategy
 /// </summary>
 public PathfinderStrategy()
 {
     _turns          = new List <Turn>();
     _turnImages     = new List <Image>();
     _pois           = new List <PointOfInterest>();
     _path           = new TrackPath();
     _web            = new WebInterface();
     _cache          = new CacheStrategy();
     _rideMapFid     = new FiducialStrategy();
     _turnMapFid     = new FiducialStrategy();
     _rideMpaPainter = new MapPainter(_rideMapFid);
     _turnMapPainter = new MapPainter(_turnMapFid);
 }
Exemple #4
0
 /// <summary>
 /// Draw locations, begin and end points onto the turn inspector
 /// </summary>
 /// <param name="image">image of the turn map</param>
 /// <param name="path">current turn</param>
 /// <returns>image with points drawn on the map</returns>
 private void drawOnTurnMap(ref Image image, TrackPath path)
 {
     _turnMapFid.processImage((Bitmap)image);
     //if the fiducial strategy class has located the balloons
     //register the image to the UTM locations (UL, LR) _pd is our instance of PathDrawer
     if (_turnMapFid.MapLocated)
     {
         _turnMapFid.setCorrespondence(path.UpperLeft, path.LowerRight);
         _turnMapPainter.drawLocations(ref image, path.GeocodeLocations.ToArray());
         Location begin = path.GeocodeLocations[0];
         Location end   = path.GeocodeLocations[path.GeocodeLocations.Count - 1];
         _turnMapPainter.drawBeginAndEndPoints(ref image, begin, end);
     }
 }
Exemple #5
0
        /// <summary>
        /// returns the map image at index _currentTurn
        /// </summary>
        public Image getTurnMap(int height, int width)
        {
            Image     image    = null;
            TrackPath turnPath = new TrackPath();

            turnPath.Round   = false;
            turnPath.Weight  = 10;
            turnPath.MapType = _path.MapType;
            string mapSize = width.ToString() + "x" + height.ToString() + "&";

            if (_turns != null && _turns.Count > _currentTurn)
            {
                for (int i = _turns[_currentTurn].Locs[0].GpxLocation.Index;
                     i <= _turns[_currentTurn].Locs[2].GpxLocation.Index; i++)
                {
                    turnPath.Locations.Add(_path.Locations[i]);
                }
            }
            turnPath.GeocodeLocations = turnPath.Locations;
            // download web image
            if (turnPath != null && turnPath.Locations.Count > 0)
            {
                //incedentally, getting the path string sorts the locations
                string turnPathUrl = turnPath.getPathUrlString();
                if (_turnImages[_currentTurn] == null)
                {
                    image = _web.downloadImage(_baseMapUrl + mapSize
                                               + turnPathUrl + "&sensor=false");
                    if (image == null)
                    {
                        _status = _web.Status;
                    }
                    else
                    {
                        image = new Bitmap(image);
                        _turnImages[_currentTurn] = image;
                    }
                }
                else
                {
                    image = _turnImages[_currentTurn];
                }
                if (image != null)
                {
                    drawOnTurnMap(ref image, turnPath);
                }
            }
            return(image);
        }
Exemple #6
0
 public GpxParser(string fileName, TrackPath path)
 {
     try {
         StreamReader sr   = new StreamReader(fileName);
         string       file = sr.ReadToEnd();
         sr.Close();
         _doc = new XmlDocument();
         _doc.LoadXml(file);
         XmlNode node = _doc.ChildNodes[0];
         foreach (XmlNode n in _doc.ChildNodes)
         {
             if (n.Name == "gpx")
             {
                 node = n; break;
             }
         }
         foreach (XmlNode n in node)
         {
             if (n.Name == "trk")
             {
                 node = n; break;
             }
         }
         foreach (XmlNode n in node)
         {
             if (n.Name == "trkseg")
             {
                 node = n; break;
             }
         }
         foreach (XmlNode n in node.ChildNodes)
         {
             if (n.Name == "trkpt")
             {
                 Location loc = new Location(double.Parse(n.Attributes[0].Value)
                                             , double.Parse(n.Attributes[1].Value));
                 loc.Elevation = double.Parse(n.FirstChild.InnerText);
                 path.Locations.Add(loc);
             }
         }
         _status = "Read " + path.Locations.Count + " Locations";
     } catch (Exception e) {
         //_status = e.Message;
         _status = "Parsing error, cannot read input file.";
         path.Locations.Clear();
     }
 }
Exemple #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="image"></param>
 /// <param name="path"></param>
 /// <returns>return image of the points drawn on ride map</returns>
 private void drawnOnRideMap(ref Image image, TrackPath path)
 {
     if (_rideMapFid.MapLocated)
     {
         _rideMpaPainter.drawLocations(ref image, path.GeocodeLocations.ToArray());
         if (_turns != null && _turns.Count > 0)
         {
             _rideMpaPainter.drawTurn(ref image, _turns[_currentTurn]);
         }
         Location begin = path.GeocodeLocations[0];
         Location end   = path.GeocodeLocations[path.GeocodeLocations.Count - 1];
         _rideMpaPainter.drawBeginAndEndPoints(ref image, begin, end);
         if (_pois != null)
         {
             _rideMpaPainter.drawPointsOfInterest(ref image, _pois.ToArray());
         }
     }
 }
 /// <summary>
 /// gets a string that represents the list of directions
 /// currently formatted using google maps directions as a model
 /// </summary>
 public static string getDirections(string units, List<Address> locations, List<Turn> turns, TrackPath path)
 {
     //case for meters, kilometers, and miles
     if (locations == null) return "";
     StringBuilder _directionsString = null;
     if (locations.Count > 0 && turns != null && turns.Count > 0) {
         _directionsString = new StringBuilder(("1) Start at " + locations[0].AddressString
             + "\r\ngo " + getDistanceInUnits(turns[0].Distance, units)
             + "\r\nmake a  " + turns[0].TurnDirection
             + " at " + turns[0].Locs[2].StreetName + "\r\ntotal: "
             + getDistanceInUnits(turns[0].Locs[1].GpxLocation.Distance, units)
             + "\r\n\r\n"));
         for (int i = 1; i < turns.Count - 1; i++)
             _directionsString.Append((i + 1) + ") Turn " + turns[i].TurnDirection
                 + " at " + turns[i].Locs[2].StreetName + "\r\ngo "
                 + getDistanceInUnits(turns[i].Distance, units) + " total: "
                 + getDistanceInUnits(turns[i].Locs[1].GpxLocation.Distance, units)
                 + "\r\n\r\n");
         int last = turns.Count - 1;
         if (turns.Count > 1)
             _directionsString.Append((last + 1) + ") Turn " + turns[last].TurnDirection
                 + " at " + turns[last].Locs[2].StreetName + "\r\ngo "
                 + getDistanceInUnits(turns[last].Distance, units) + ", total: "
                 + getDistanceInUnits(turns[last].Locs[1].GpxLocation.Distance, units)
                 + "\r\n\r\n");
         _directionsString.Append("End at " + locations[locations.Count - 1].AddressString
             + "\r\ntotal distance: " + getDistanceInUnits(path.TotalDistance, units));
     } else if (locations.Count > 0) {
         _directionsString = new StringBuilder("1) Start at " + locations[0].AddressString
             + "\r\n\r\nEnd at " + locations[locations.Count - 1].AddressString
             + "\r\ntotal distance: " + getDistanceInUnits(path.TotalDistance, units));
     } else {
         if (path.TotalDistance > 0)
             _directionsString = new StringBuilder("No internet connection.\r\ntotal distance "
                 + getDistanceInUnits(path.TotalDistance, units));
         else _directionsString = new StringBuilder("No locations, check your input .gpx file");
     }
     string temp = _directionsString.ToString().Replace("Turn null", "Go straight");
     return temp;
 }
        public KmlParser(string fileName, TrackPath path)
        {
            string s = "";

            string[] lines;
            string[] coords;
            string[] splitstrings = { "\r\n", "\n", "\r" };
            try {
                StreamReader sr = new StreamReader(fileName);
                s = sr.ReadToEnd();
                sr.Close();
                s = s.Substring(s.IndexOf("<coordinates>")
                                , s.IndexOf("</coordinates>") - s.IndexOf("<coordinates>"));
                s     = s.Replace("<coordinates>", "");
                s     = s.Replace("</coordinates>", "");
                s     = s.Replace(" ", "");
                s     = s.Trim();
                lines = s.Split(splitstrings, StringSplitOptions.None);

                // after string processing, have one long string like this:
                // -124.058970,43.979150,0.000000\n
                // -123.177780,44.048160,0.000000\n
                // ...

                // so split into lines, then split each line by ','

                foreach (string line in lines)
                {
                    coords = line.Split(',');
                    Location loc = new Location(double.Parse(coords[1]), double.Parse(coords[0]));
                    loc.Elevation = double.Parse(coords[2]);
                    path.Locations.Add(loc);
                }
                _status = "Read " + path.Locations.Count + " locations";
            } catch (Exception e) {
                //_status = e.Message;
                _status = "Parsing error, cannot read input file.";
                path.Locations.Clear();
            }
        }
        public KmlParser(string fileName, TrackPath path)
        {
            string s = "";
            string[] lines;
            string[] coords;
            string[] splitstrings = { "\r\n", "\n", "\r" };
            try {
                StreamReader sr = new StreamReader(fileName);
                s = sr.ReadToEnd();
                sr.Close();
                s = s.Substring(s.IndexOf("<coordinates>")
                    , s.IndexOf("</coordinates>") - s.IndexOf("<coordinates>"));
                s = s.Replace("<coordinates>", "");
                s = s.Replace("</coordinates>", "");
                s = s.Replace(" ", "");
                s = s.Trim();
                lines = s.Split(splitstrings, StringSplitOptions.None);

                // after string processing, have one long string like this:
                // -124.058970,43.979150,0.000000\n
                // -123.177780,44.048160,0.000000\n
                // ...

                // so split into lines, then split each line by ','

                foreach (string line in lines) {
                    coords = line.Split(',');
                    Location loc = new Location(double.Parse(coords[1]), double.Parse(coords[0]));
                    loc.Elevation = double.Parse(coords[2]);
                    path.Locations.Add(loc);
                }
                _status = "Read " + path.Locations.Count + " locations";
            } catch (Exception e) {
                //_status = e.Message;
                _status = "Parsing error, cannot read input file.";
                path.Locations.Clear();
            }
        }
        /// <summary>
        /// gets a string that represents the list of directions
        /// currently formatted using google maps directions as a model
        /// </summary>
        public static string getDirections(string units, List <Address> locations, List <Turn> turns, TrackPath path)
        {
            //case for meters, kilometers, and miles
            if (locations == null)
            {
                return("");
            }
            StringBuilder _directionsString = null;

            if (locations.Count > 0 && turns != null && turns.Count > 0)
            {
                _directionsString = new StringBuilder(("1) Start at " + locations[0].AddressString
                                                       + "\r\ngo " + getDistanceInUnits(turns[0].Distance, units)
                                                       + "\r\nmake a  " + turns[0].TurnDirection
                                                       + " at " + turns[0].Locs[2].StreetName + "\r\ntotal: "
                                                       + getDistanceInUnits(turns[0].Locs[1].GpxLocation.Distance, units)
                                                       + "\r\n\r\n"));
                for (int i = 1; i < turns.Count - 1; i++)
                {
                    _directionsString.Append((i + 1) + ") Turn " + turns[i].TurnDirection
                                             + " at " + turns[i].Locs[2].StreetName + "\r\ngo "
                                             + getDistanceInUnits(turns[i].Distance, units) + " total: "
                                             + getDistanceInUnits(turns[i].Locs[1].GpxLocation.Distance, units)
                                             + "\r\n\r\n");
                }
                int last = turns.Count - 1;
                if (turns.Count > 1)
                {
                    _directionsString.Append((last + 1) + ") Turn " + turns[last].TurnDirection
                                             + " at " + turns[last].Locs[2].StreetName + "\r\ngo "
                                             + getDistanceInUnits(turns[last].Distance, units) + ", total: "
                                             + getDistanceInUnits(turns[last].Locs[1].GpxLocation.Distance, units)
                                             + "\r\n\r\n");
                }
                _directionsString.Append("End at " + locations[locations.Count - 1].AddressString
                                         + "\r\ntotal distance: " + getDistanceInUnits(path.TotalDistance, units));
            }
            else if (locations.Count > 0)
            {
                _directionsString = new StringBuilder("1) Start at " + locations[0].AddressString
                                                      + "\r\n\r\nEnd at " + locations[locations.Count - 1].AddressString
                                                      + "\r\ntotal distance: " + getDistanceInUnits(path.TotalDistance, units));
            }
            else
            {
                if (path.TotalDistance > 0)
                {
                    _directionsString = new StringBuilder("No internet connection.\r\ntotal distance "
                                                          + getDistanceInUnits(path.TotalDistance, units));
                }
                else
                {
                    _directionsString = new StringBuilder("No locations, check your input .gpx file");
                }
            }
            string temp = _directionsString.ToString().Replace("Turn null", "Go straight");

            return(temp);
        }
 /// <summary>
 /// Draw locations, begin and end points onto the turn inspector
 /// </summary>
 /// <param name="image">image of the turn map</param>
 /// <param name="path">current turn</param>
 /// <returns>image with points drawn on the map</returns>
 private void drawOnTurnMap(ref Image image, TrackPath path)
 {
     _turnMapFid.processImage((Bitmap)image);
     //if the fiducial strategy class has located the balloons
     //register the image to the UTM locations (UL, LR) _pd is our instance of PathDrawer
     if (_turnMapFid.MapLocated) {
         _turnMapFid.setCorrespondence(path.UpperLeft, path.LowerRight);
         _turnMapPainter.drawLocations(ref image, path.GeocodeLocations.ToArray());
         Location begin = path.GeocodeLocations[0];
         Location end = path.GeocodeLocations[path.GeocodeLocations.Count - 1];
         _turnMapPainter.drawBeginAndEndPoints(ref image, begin, end);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="image"></param>
 /// <param name="path"></param>
 /// <returns>return image of the points drawn on ride map</returns>
 private void drawnOnRideMap(ref Image image, TrackPath path)
 {
     if (_rideMapFid.MapLocated) {
         _rideMpaPainter.drawLocations(ref image, path.GeocodeLocations.ToArray());
         if (_turns != null && _turns.Count > 0) {
             _rideMpaPainter.drawTurn(ref image, _turns[_currentTurn]);
         }
         Location begin = path.GeocodeLocations[0];
         Location end = path.GeocodeLocations[path.GeocodeLocations.Count - 1];
         _rideMpaPainter.drawBeginAndEndPoints(ref image, begin, end);
         if (_pois != null)
             _rideMpaPainter.drawPointsOfInterest(ref image, _pois.ToArray());
     }
 }
 /// <summary>
 /// returns the map image at index _currentTurn
 /// </summary>
 public Image getTurnMap(int height, int width)
 {
     Image image = null;
     TrackPath turnPath = new TrackPath();
     turnPath.Round = false;
     turnPath.Weight = 10;
     turnPath.MapType = _path.MapType;
     string mapSize = width.ToString() + "x" + height.ToString() + "&";
     if (_turns != null && _turns.Count > _currentTurn) {
         for (int i = _turns[_currentTurn].Locs[0].GpxLocation.Index;
             i <= _turns[_currentTurn].Locs[2].GpxLocation.Index; i++)
             turnPath.Locations.Add(_path.Locations[i]);
     }
     turnPath.GeocodeLocations = turnPath.Locations;
     // download web image
     if (turnPath != null && turnPath.Locations.Count > 0) {
         //incedentally, getting the path string sorts the locations
         string turnPathUrl = turnPath.getPathUrlString();
         if (_turnImages[_currentTurn] == null) {
             image = _web.downloadImage(_baseMapUrl + mapSize
                 + turnPathUrl + "&sensor=false");
             if (image == null) _status = _web.Status;
             else {
                 image = new Bitmap(image);
                 _turnImages[_currentTurn] = image;
             }
         } else {
             image = _turnImages[_currentTurn];
         }
         if (image != null)
             drawOnTurnMap(ref image, turnPath);
     }
     return image;
 }