Esempio n. 1
0
        private static List<Waypoint> ReadGpx(string filename)
        {
            if(!File.Exists(filename)) return null;

            List<Waypoint> points = new List<Waypoint>();

            XmlTextReader xtr = new XmlTextReader(filename);

            string subNodeName;

            Waypoint wp;

            try
            {
                //Loop through all elements
                while (xtr.Read())
                {
                    if (xtr.NodeType != XmlNodeType.Element && xtr.NodeType != XmlNodeType.EndElement &&
                        xtr.NodeType != XmlNodeType.Text)
                        continue;

                    //We're looking for waypoints
                    if (xtr.Name != "wpt") continue;

                    wp = new Waypoint();
                    if (xtr.HasAttributes) // Found latitude and longitude
                    {
                        string tempVal = xtr.GetAttribute("lat");
                        wp.Latitude = Convert.ToDouble(string.IsNullOrEmpty(tempVal) ? "0" : tempVal, CultureInfo.InvariantCulture.NumberFormat);

                        tempVal = xtr.GetAttribute("lon");
                        wp.Longitude = Convert.ToDouble(string.IsNullOrEmpty(tempVal) ? "0" : tempVal, CultureInfo.InvariantCulture.NumberFormat);
                    }

                    //Move to next node
                    xtr.Read();

                    //Loop through sub items
                    do
                    {
                        subNodeName = xtr.Name;
                        switch (subNodeName)
                        {
                            case "ele":
                                wp.Elevation = Convert.ToDouble(xtr.ReadString(), CultureInfo.InvariantCulture.NumberFormat);
                                xtr.Read();
                                break;
                            case "time":
                                wp.Time = xtr.ReadString();
                                xtr.Read();
                                break;
                            case "name":
                                wp.Name = xtr.ReadString();
                                xtr.Read();
                                break;
                            case "cmt":
                                wp.Cmt = xtr.ReadString();
                                xtr.Read();
                                break;
                                //Description is not read from GPX. It is remade by the LogViewer.
                            case "desc":
                                xtr.Read();
                                xtr.Read();
                                break;
                            case "fix":
                                wp.Fix = xtr.ReadString();
                                xtr.Read();
                                break;
                            case "sat":
                                wp.SatCount = Convert.ToInt32(xtr.ReadString(), CultureInfo.InvariantCulture.NumberFormat);
                                xtr.Read();
                                break;
                            case "vdop":
                                wp.Vdop = Convert.ToDouble(xtr.ReadString(), CultureInfo.InvariantCulture.NumberFormat);
                                xtr.Read();
                                break;
                            case "hdop":
                                wp.Hdop = Convert.ToDouble(xtr.ReadString(), CultureInfo.InvariantCulture.NumberFormat);
                                xtr.Read();
                                break;
                            case "pdop":
                                wp.Pdop = Convert.ToDouble(xtr.ReadString(), CultureInfo.InvariantCulture.NumberFormat);
                                xtr.Read();
                                break;
                            case "":
                                //Blank tags should be ignored
                                break;
                            case "wpt":
                                //Closing tag of this element.
                                break;
                            case "extensions":
                                //The extensions element specifies information about our access point at this spot.
                                xtr.Read();
                                string subSubNodeName;

                                do
                                {
                                    subSubNodeName = xtr.Name;
                                    switch (subSubNodeName)
                                    {
                                        case "MAC":
                                            wp.Extensions.MacAddress = xtr.ReadString();
                                            xtr.Read();
                                            break;
                                        case "SSID":
                                            wp.Extensions.Ssid = xtr.ReadString();
                                            xtr.Read();
                                            break;
                                        case "RSSI":
                                            wp.Extensions.Rssi = Convert.ToInt32(xtr.ReadString());
                                            xtr.Read();
                                            break;
                                        case "ChannelID":
                                            wp.Extensions.Channel = Convert.ToUInt32(xtr.ReadString());
                                            xtr.Read();
                                            break;
                                        case "security":
                                            wp.Extensions.Security = xtr.ReadString();
                                            xtr.Read();
                                            break;
                                        case "signalQuality":
                                            wp.Extensions.SignalQuality = Convert.ToUInt32(xtr.ReadString());
                                            xtr.Read();
                                            break;
                                        case "networkType":
                                            wp.Extensions.NetworkType = xtr.ReadString();
                                            xtr.Read();
                                            break;
                                        case "rates":
                                            wp.Extensions.Rates = xtr.ReadString();
                                            xtr.Read();
                                            break;
                                            //Blank tags should be ignored.
                                        case "":
                                            break;
                                            //Closing tag should be skipped over also.
                                        case "extensions":
                                            break;
                                        default:
                                            xtr.Read();
                                            xtr.Read();
                                            break;
                                    }

                                    xtr.Read();
                                } while (subSubNodeName != "extensions");

                                break;
                                //Any other elements of GPX not implemented here but possibilty present in the log.
                                //e.g. magvar, geoidheight, src, link, sym, type, ageofdgpsdata, dgpsid
                            default:
                                xtr.Read();
                                xtr.Read();
                                break;
                        }
                        xtr.Read();

                    } while (subNodeName != "wpt");

                    //Add the Waypoint to the list
                    points.Add(wp);
                }
            }
            catch(XmlException)
            {

            }

            //doc.

            xtr.Close();

            return points;
        }
Esempio n. 2
0
        public static Waypoint[] FilterData(Waypoint[] points, WaypointFilterArgs args)
        {
            if(args == null) return points;

            var gp = points.GroupBy(wp => wp.Extensions.MacAddress);

            //string currentMac;

            foreach (IGrouping<string, Waypoint> waypoint in gp)
            {
                //Console.WriteLine(waypoint.Key);
                //currentMac = waypoint.Key;
                foreach (Waypoint wp in waypoint)
                {
                    //If the point is already ignored, skip it
                    if(wp.Ignore) continue;
                    //Ignore the point of the GPS seemed to have been locked up
                    if (args.GpsLockedUp)
                    {
                        if (wp != null)
                        {
                            Waypoint[] ps = waypoint.Where(wpt => wpt != wp && !wp.Ignore && wpt.Time.Equals(wp.Time)).ToArray();
                            if (ps.Count() > 0)
                            {
                                //I'm just using this to set ignore on all bad points
                                ps.All(tr => tr.Ignore = true);
                            }
                        }
                    }

                    //GPS fix filter
                    if(args.GpsFixLost)
                    {
                        if(wp.Fix != "2d" || wp.Fix != "3d" || wp.Fix != "dgps")
                        {
                            wp.Ignore = true;
                        }
                    }

                    //Minimum number of satellites
                    if(args.MinimumSatsVisible > -1)
                    {
                        if(wp.SatCount < args.MinimumSatsVisible)
                            wp.Ignore = true;
                    }

                    //Maximum speed filter
                    //Perhaps they're guilty about exceeding the speed limit, or perhaps the signal strength measurement losses accuracy?
                    if(args.MaximumSpeedKmh > -1)
                    {
                        //If the speed isn't avalible, ignore this point?
                        if(string.IsNullOrEmpty(wp.Cmt)) wp.Ignore = true;
                        else
                        {
                            try
                            {
                                double speed = double.Parse(wp.Cmt, CultureInfo.InvariantCulture.NumberFormat);
                                if (speed > args.MaximumSpeedKmh) wp.Ignore = true;
                            }
                            catch(Exception)
                            {
                                //If something went wrong, ignore the point.
                                wp.Ignore = true;
                            }
                        }
                    }

                    //Ignore high signal strengths
                    if(args.MaxSignal > -101)
                    {
                        if(wp.Extensions.Rssi > args.MaxSignal)
                            wp.Ignore = true;
                    }
                }
            }

            //return points;
            return points.Where(wp => !wp.Ignore).ToArray();
        }
Esempio n. 3
0
        public static Waypoint ConvertNetworkDataToWaypoint(NetworkData data, GpsData gpsData)
        {
            Waypoint outpoint = new Waypoint();

            outpoint.Latitude = gpsData.Latitude;
            outpoint.Longitude = gpsData.Longitude;

            outpoint.Elevation = gpsData.Altitude;
            if (gpsData.SatelliteTime.Year > 1)
            {
                outpoint.Time = string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                              new object[]
                                                  {
                                                      gpsData.SatelliteTime.Year,
                                                      gpsData.SatelliteTime.Month.ToString("D2"),
                                                      gpsData.SatelliteTime.Day.ToString("D2"),
                                                      gpsData.SatelliteTime.Hour.ToString("D2"),
                                                      gpsData.SatelliteTime.Minute.ToString("D2"),
                                                      gpsData.SatelliteTime.Second,
                                                      gpsData.SatelliteTime.Millisecond
                                                  });
            }
            else
            {
                DateTime now = DateTime.Now.ToUniversalTime();
                outpoint.Time = string.Format("{0}-{1}-{2}T{3}:{4}:{5}.{6}Z",
                                              new object[]
                                                  {
                                                      now.Year,
                                                      now.Month.ToString("D2"),
                                                      now.Day.ToString("D2"),
                                                      now.Hour.ToString("D2"),
                                                      now.Minute.ToString("D2"),
                                                      now.Second,
                                                      now.Millisecond
                                                  });
            };

            outpoint.GeoidHeight = gpsData.GeoidSeperation;
            //The SSID must be cleaned
            outpoint.Name = XmlHelper.CleanString(data.Ssid) + " [" + data.MyMacAddress + "]";

            outpoint.Cmt = gpsData.Speed.ToString(CultureInfo.InvariantCulture.NumberFormat);

            //outpoint.Description = string.Format(
            //    "{0}\r\n[{1}]\r\nRSSI: {2} dB\r\nQuality: {3}%\r\nChannel {4}\r\nSpeed (kph): {5}\r\n{6}",
            //    new object[]
            //        {
            //            XmlHelper.CleanString(data.Ssid), data.MyMacAddress.ToString(), data.Rssi, data.SignalQuality,
            //            data.Channel, gpsData.Speed,
            //            gpsData.SatelliteTime.ToString()
            //        });

            outpoint.Fix = gpsData.FixType;
            outpoint.SatCount = gpsData.SatellitesUsed;
            outpoint.Hdop = gpsData.Hdop;
            outpoint.Vdop = gpsData.Vdop;
            outpoint.Pdop = gpsData.Pdop;

            outpoint.Extensions.MacAddress = data.MyMacAddress.ToString();
            outpoint.Extensions.Ssid = XmlHelper.CleanString(data.Ssid);
            outpoint.Extensions.Rssi = data.Rssi;
            outpoint.Extensions.Channel = data.Channel;
            outpoint.Extensions.Security = data.Security;
            outpoint.Extensions.SignalQuality = data.SignalQuality;
            outpoint.Extensions.NetworkType = data.NetworkType;
            outpoint.Extensions.Rates = data.SupportedRates;

            return outpoint;
        }
Esempio n. 4
0
        public static XmlElement CreatePlacemark(XmlDocument document, Waypoint wp, bool visible, bool showLabel, bool paddleMarker, bool ssidLabel)
        {
            //Create the main placemark element
            XmlElement xeMain = document.CreateElement("Placemark");

            string color = KmlWriter.EncryptionColor(wp.Extensions.Security);

            //Visibility is default true
            xeMain.AppendChild(CreateElementWithText(document, "visibility", visible ? "1" : "0"));

            //placemark style
            XmlElement xeStyle = document.CreateElement("Style");
            xeStyle.SetAttribute("id", "sn_shaded_dot");

            XmlElement xeIconStyle = document.CreateElement("IconStyle");
            XmlElement xeIcon = document.CreateElement("Icon");
            xeIcon.AppendChild(CreateElementWithText(document, "href",
                                                     paddleMarker
                                                         ? "http://maps.google.com/mapfiles/kml/paddle/wht-blank.png"
                                                         : "http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png"));
            //Add icon element to iconstyle element
            xeIconStyle.AppendChild(xeIcon);

            xeIconStyle.AppendChild(CreateElementWithText(document, "color", color));
            xeIconStyle.AppendChild(CreateElementWithText(document, "scale", KmlWriter.IconScale(wp.Extensions.Rssi).ToString(CultureInfo.InvariantCulture)));

            //Add element
            xeStyle.AppendChild(xeIconStyle);

            //LabelStyle element
            XmlElement xeLabelStyle = document.CreateElement("LabelStyle");
            xeLabelStyle.AppendChild(CreateElementWithText(document, "color", color));
            xeLabelStyle.AppendChild(CreateElementWithText(document, "scale", showLabel ? "1" : "0"));

            //Add element
            xeStyle.AppendChild(xeLabelStyle);

            //Add Style to main placemark element
            xeMain.AppendChild(xeStyle);

            //Add name element
            xeMain.AppendChild(CreateElementWithText(document, "name", ssidLabel ? wp.Extensions.Ssid + ": " + wp.Extensions.Rssi : wp.Extensions.Rssi.ToString(CultureInfo.InvariantCulture)));

            //Add description element
            xeMain.AppendChild(CreateElementWithText(document, "description", wp.BuildKmlDescription()));
            //Location
            //KML requires Lon,Lat,Alt. It's backwards!
            XmlElement xePoint = document.CreateElement("Point");
            xePoint.AppendChild(CreateElementWithText(document, "coordinates",
                                            string.Format("{0},{1},{2}", 
                                            wp.Longitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                            wp.Latitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                            wp.Elevation.ToString(CultureInfo.InvariantCulture.NumberFormat))));
            xeMain.AppendChild(xePoint);

            return xeMain;
        }