// real-time track logging: private bool logTrack(GpsRealTimeData rtData) { bool ret = false; // only good fixes with non-null location reach here string source = this.Label + " " + DateTime.Now; if (trackId == -1) { trackId = ++Project.trackId; string trackName = "VEHICLE-LOG-" + trackId + " " + this.Label; CreateInfo createInfo = new CreateInfo(); createInfo.init("trk"); createInfo.name = trackName; createInfo.id = trackId; createInfo.source = source; totalTrkpt = 0; WaypointsCache.insertWaypoint(createInfo); // actually inserts a track WaypointsCache.isDirty = true; } // garmin sends data every second, even if it is same point. Ignore repetetions to save memory. double[] howfars = new Double[] { 0.0d, 1.0d, 10.0d, 20.0d, 50.0d, 100.0d }; double howFarMeters = howfars[howfarIndex]; GeoCoord loc = new GeoCoord(rtData.location.Lng, rtData.location.Lat, rtData.location.Elev); // tolerance 0.0001 degree = 10 meters if (howfarIndex == 0 || !loc.almostAs(lastLoc, howFarMeters * 0.00001d)) // 0 means every incoming reading { CreateInfo createInfo = new CreateInfo(); createInfo.init("trkpt"); createInfo.id = trackId; // relate waypoint to track createInfo.dateTime = rtData.time; createInfo.lat = rtData.location.Lat; createInfo.lng = rtData.location.Lng; createInfo.elev = rtData.location.Elev; createInfo.source = source; //createInfo.name = "" + totalTrkpt; // track point name lastLat = rtData.location.Lat; lastLng = rtData.location.Lng; lastElev = rtData.location.Elev; totalTrkpt++; ret = true; WaypointsCache.insertWaypoint(createInfo); lastLoc = loc; } return(ret); }
// return array of (two) track IDs or null (if track can't be ungrouped for some reason) public static ArrayList ungroupTrackAtTrackpoint(Track trk, Waypoint trkptBreak) { int trip = 0; int i; // more than one trip, go ahead break it: string newTrackSource = trk.Source; trip = 0; ArrayList ret = new ArrayList(); for (i = 0; i < trk.Trackpoints.Count; i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); if (i == 0 || wpt == trkptBreak) { Project.trackId++; trip++; string newTrackName = trk.Name + "-trip-" + trip; CreateInfo createInfo = new CreateInfo(); createInfo.init(trk.Type); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.url = trk.Url; currentTrack = new Track(createInfo); m_tracksAll.Add(currentTrack); ret.Add(Project.trackId); } if (trip > 0) { Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = Project.trackId; currentTrack.insertWaypoint(cloneWpt); } } foreach (long id in ret) { Track ttrk = getTrackById(id); if (ttrk != null) { ttrk.rebuildTrackBoundaries(); } } isDirty = true; return(ret); }
/// <summary> /// for tracks only /// </summary> /// <returns></returns> public Track toRoute() { if (!this.isRoute) { CreateInfo createInfo = new CreateInfo(); createInfo.init("rte"); Project.trackId++; createInfo.id = Project.trackId; createInfo.name = "From " + this.Name; createInfo.source = "From " + m_source; Track route = new Track(createInfo); int step = (int)Math.Ceiling((double)m_trackpoints.Count / (double)Project.gpsMaxPointsPerRoute); if (step <= 0) { step = 1; } int iLast = 0; for (int i = 0; i < m_trackpoints.Count && route.Trackpoints.Count < Project.gpsMaxPointsPerRoute - 1; i += step) { Waypoint wpt = (Waypoint)m_trackpoints.GetByIndex(i); if (wpt.ThumbImage != null) { i -= step - 1; // move to a trackpoint immediately after the photo point continue; } iLast = i; Waypoint wptClone = new Waypoint(wpt); wptClone.LiveObjectType = LiveObjectTypes.LiveObjectTypeRoutepoint; wptClone.TrackId = route.Id; wptClone.Source = route.Source; route.Trackpoints.Add(wptClone.DateTime, wptClone); } // we want the end of the route to be the end track point: if (iLast < m_trackpoints.Count - 1) { Waypoint wpt = (Waypoint)m_trackpoints.GetByIndex(m_trackpoints.Count - 1); Waypoint wptClone = new Waypoint(wpt); wptClone.TrackId = route.Id; wptClone.Source = route.Source; route.Trackpoints.Add(wptClone.DateTime, wptClone); } route.rebuildTrackBoundaries(); return(route); } return(null); }
// takes array of Track public static Track groupTracks(ArrayList tracks) { Project.trackId++; string tType = ((Track)tracks[0]).Type; string newTrackSource = "joined" + ("trk".Equals(tType) ? (" " + DateTime.Now) : ("-" + Project.trackId)); string newTrackName = newTrackSource; CreateInfo createInfo = new CreateInfo(); createInfo.init(tType); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; Track joinedTrack = new Track(createInfo); m_tracksAll.Add(joinedTrack); DateTime dateTime = new DateTime(8888, 1, 1, 1, 1, 1, 1); // for routes, we make new time sequence foreach (Track trk in tracks) { for (int i = 0; i < trk.Trackpoints.Count; i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = joinedTrack.Id; if (joinedTrack.isRoute) { cloneWpt.DateTime = dateTime; dateTime = dateTime.AddSeconds(1); cloneWpt.NameDisplayed = ""; // let it be the number or Detail } joinedTrack.insertWaypoint(cloneWpt); } } joinedTrack.rebuildTrackBoundaries(); return(joinedTrack); }
private static bool processGcPage(string url, byte[] dataDownloaded) { bool ret = false; int lineno = 0; string line; int state = 0; string lineToSearch = "<span id=\"CacheName\">"; int pos; string cacheName = ""; ASCIIEncoding enc = new ASCIIEncoding(); string pageText = new String(enc.GetChars(dataDownloaded)); CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. StringReader stream = new StringReader(pageText); try { while ((line = stream.ReadLine()) != null && state < 99) { lineno++; switch (state) { case 0: if ((pos = line.IndexOf(lineToSearch)) != -1) { pos += lineToSearch.Length; int pos1 = line.IndexOf("</span>", pos); if (pos1 > pos) { cacheName = line.Substring(pos, pos1 - pos).Trim(); LibSys.StatusBar.Trace("OK: cacheName='" + cacheName + "'"); state = 1; lineToSearch = "<span id=\"LatLon\""; } } break; case 1: if ((pos = line.IndexOf(lineToSearch)) != -1) { pos += lineToSearch.Length; int pos1 = line.IndexOf("</span>", pos); if (pos1 > pos) { string sCacheCoords = line.Substring(pos, pos1 - pos).Trim(); LibSys.StatusBar.Trace("OK: cacheCoords='" + sCacheCoords + "'"); GeoCoord loc = getCleanLocation(sCacheCoords); //LibSys.StatusBar.Trace("OK: loc='" + loc + "'"); createInfo.init("wpt"); createInfo.lat = loc.Lat; createInfo.lng = loc.Lng; createInfo.typeExtra = "geocache"; createInfo.source = url; createInfo.name = cacheName; createInfo.url = url; WaypointsCache.insertWaypoint(createInfo); WaypointsCache.isDirty = true; ret = true; // report successfully parsed page state = 99; lineToSearch = ""; } } break; } } } catch {} return(ret); }
public bool processXml(string url, XmlDocument xmlDoc, string source) { bool ret = true; LibSys.StatusBar.Trace("IP: FileGeocachingLoc:processXml()"); try { XmlNodeList waypointNodes = xmlDoc.SelectNodes("/loc/waypoint"); /* * <waypoint> * <name id="GC37EB"><![CDATA[Gotta Play by Cyn]]></name> * <coord lat="33.6033" lon="-117.651433333333"/> * <type>Geocache</type> * <link text="Cache Details">http://www.geocaching.com/seek/cache_details.aspx?wp=GC37EB</link> * </waypoint> */ CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. // we want to traverse XmlDocument fast, as tile load operations can be numerous // and come in pack. So we avoid using XPath and rely mostly on "foreach child": foreach (XmlNode nnode in waypointNodes) { try { //LibSys.StatusBar.Trace("FileGeocachingLoc:process() node=" + nnode.Name); createInfo.init("wpt"); createInfo.typeExtra = "unknown"; // type: geocache createInfo.source = source; foreach (XmlNode node in nnode.ChildNodes) { //LibSys.StatusBar.Trace(" child node=" + node.Name); switch (node.Name) { case "name": createInfo.name = node.Attributes["id"].InnerText.Trim(); createInfo.urlName = node.InnerText.Trim(); break; case "coord": createInfo.setLat(node.Attributes["lat"].InnerText); createInfo.setLng(node.Attributes["lon"].InnerText); break; case "ele": // just in case createInfo.setElev(node.InnerText); break; case "elev": // just in case createInfo.setElev(node.InnerText); break; case "type": createInfo.typeExtra = node.InnerText.Trim(); if (createInfo.typeExtra.ToLower().IndexOf("geocache") >= 0) { createInfo.sym = "Geocache"; } break; case "link": createInfo.url = node.InnerText.Trim(); //LibSys.StatusBar.Trace(" link='" + createInfo.url + "'"); break; } } m_insertWaypoint(createInfo); } catch (Exception ee) { // bad node - not a big deal... LibSys.StatusBar.Error("FileGeocachingLoc:processXml() node=" + nnode.Name + " " + ee.Message); } } } catch (Exception e) { LibSys.StatusBar.Error("FileGeocachingLoc:processXml() " + e.Message); ret = false; } return(ret); }
public override bool process(string url, string filename, string source) { bool ret = true; LibSys.StatusBar.Trace("IP: FilePlainWpt:process() filename=" + filename); int wpCount = 0; int lineno = 0; try { string line; int state = 0; int numpoints = 0; CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. StreamReader stream = new StreamReader(filename); while ((line = stream.ReadLine()) != null) { lineno++; try { switch (state) { case 0: // look for [WAYPOINTS] if (line.StartsWith("[WAYPOINTS]")) { state = 2; //LibSys.StatusBar.Trace("IP: FilePlainWpt:process() state 2 filename=" + filename); } if (line.StartsWith("[ROUTES]")) { state = 3; //LibSys.StatusBar.Trace("IP: FilePlainWpt:process() state 3 filename=" + filename); break; } break; case 2: // look for "NUMPOINTS=" for wpts case 3: // look for "NUMPOINTS=" for routes if (line.StartsWith("NUMPOINTS=")) { state *= 2; string sNumpoints = line.Substring("NUMPOINTS=".Length); numpoints = Convert.ToInt32(sNumpoints); if (numpoints <= 0) { state = 0; } //LibSys.StatusBar.Trace("IP: FilePlainWpt:process() state " + state + " numpoints=" + numpoints + " filename=" + filename); } break; case 4: // read WPT numpoints lines like: // WPT1=1,5052.677,N,00002.217,E,0000164,M,ME164-,Cliffe Hill ,a if (line.StartsWith("WPT")) { char[] sep = new Char[1] { ',' }; string[] split = line.Split(sep); double lat = Convert.ToDouble(split[1]) / 100.0d; double lng = Convert.ToDouble(split[3]) / 100.0d; createInfo.init("wpt"); createInfo.setLat("" + lat + split[2].ToLower()); createInfo.setLng("" + lng + split[4].ToLower()); createInfo.setElev(split[5]); createInfo.typeExtra = "waypoint"; createInfo.source = source; createInfo.name = split[8]; m_insertWaypoint(createInfo); wpCount++; numpoints--; if (numpoints == 0) { state = 0; // look for command again } } break; case 6: // read ROUTE numpoints lines like: numpoints--; if (numpoints == 0) { state = 0; // look for command again } break; } } catch (Exception ee) { LibSys.StatusBar.Error("FilePlainWpt:process(): file=" + filename + " line=" + lineno + " " + ee.Message); } } } catch (Exception eee) { LibSys.StatusBar.Error("FilePlainWpt:process(): " + eee.Message); ret = false; } //LibSys.StatusBar.Trace("OK: FilePlainWpt:process() filename=" + filename + " lines=" + lineno + " waypoints=" + wpCount); return(ret); }
public override bool process(string url, string filename, string source) { bool ret = true; LibSys.StatusBar.Trace("IP: FileStreetsTripsCsv:process() filename=" + filename); int wpCount = 0; int lineno = 0; try { string line; int state = 0; double zoneShift = 0.0d; CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. StreamReader stream = new StreamReader(filename); while ((line = stream.ReadLine()) != null) { lineno++; try { switch (state) { case 0: // look for "Name,Latitude,Longitude,Name 2,URL,Type" // Name,Latitude,Longitude,Name 2,URL,Type if (line.StartsWith("Name,Latitude,Longitude")) { state = 1; //LibSys.StatusBar.Trace("IP: FileStreetsTripsCsv:process() state 1 filename=" + filename); } break; case 1: // read WPT numpoints lines like: // Active Pass Lighthouse,48.873472,-123.290139,"","","" char[] sep = new Char[1] { ',' }; string[] split = line.Split(sep); if (split.Length < 3) { // possible empty line or something. Reset to searcing for header again. state = 0; break; } string name = stripQuotes(split[0]); double lat = ParseCoord(split[1]); double lng = ParseCoord(split[2]); string name2 = split.Length > 3 ? stripQuotes(split[3]) : null; string wurl = split.Length > 4 ? stripQuotes(split[4]) : null; string type = split.Length > 5 ? stripQuotes(split[5]) : null; double elev = split.Length > 6 ? ParseCoord(split[6]) : 0.0d; string desc = split.Length > 7 ? stripQuotes(split[7]) : null; string stime = split.Length > 8 ? stripQuotes(split[8]) : null; string track = split.Length > 9 ? stripQuotes(split[9]) : null; string speed = split.Length > 10 ? stripQuotes(split[10]) : null; string odometer = split.Length > 11 ? stripQuotes(split[11]) : null; bool found = split.Length > 12 ? ("true".Equals(stripQuotes(split[12]).ToLower()) || "yes".Equals(stripQuotes(split[12]).ToLower())) : false; string strLiveObjectType = "wpt"; switch (type) { case "geocache": strLiveObjectType = type; break; case "trkpt": case "rtept": if (desc == null && track != null) { desc = track; } if (name == null && name2 == null && stime != null) { name2 = stime; } strLiveObjectType = type; break; } createInfo.init(strLiveObjectType); createInfo.lat = lat; createInfo.lng = lng; createInfo.elev = elev; if (name2 != null) { createInfo.urlName = name2; } if (desc != null) { createInfo.desc = desc; } if (wurl != null) { createInfo.url = wurl; } if (name != null) { createInfo.name = name; } if (type != null) { createInfo.typeExtra = type; } if (stime != null && stime.Length >= 4) { try { createInfo.dateTime = Convert.ToDateTime(stime); } catch {} } createInfo.source = source; m_insertWaypoint(createInfo); wpCount++; break; } } catch (Exception ee) { LibSys.StatusBar.Error("FileStreetsTripsCsv:process(): file=" + filename + " line=" + lineno + " " + ee.Message); } } } catch (Exception eee) { LibSys.StatusBar.Error("FileStreetsTripsCsv:process(): " + eee.Message); ret = false; } //LibSys.StatusBar.Trace("OK: FileStreetsTripsCsv:process() filename=" + filename + " lines=" + lineno + " waypoints=" + wpCount); return(ret); }
public static void processApiCall(string strArgs) { ArrayList files = new ArrayList(); // of string bool doMove = false; char[] splitter = { '|' }; string[] args = strArgs.Split(splitter); GeoCoord pos = PictureManager.This.CameraManager.Location.Clone(); switch (args[0]) { case "api": // something like "api|cmd|data...." switch (args[1]) { case "refresh": PictureManager.This.CameraManager.ProcessCameraMove(); break; case "resetzoom": WaypointsCache.resetBoundaries(); break; case "dozoom": PictureManager.This.CameraManager.zoomToCorners(); break; case "newwpt": { double lat = Convert.ToDouble(args[2]); double lng = Convert.ToDouble(args[3]); double elev = Convert.ToDouble(args[4]); DateTime dateTime = Convert.ToDateTime(args[5]); string name = args[6]; // like "GC12345" string urlName = args[7]; // like "Mike's cache" string type = args[8]; // like "geocache" string typeExtra = args[9]; // like "Geocache Found" string sym = args[10]; // like "Geocache" long trackid = Convert.ToInt64(args[11]); // -1 is none, -2 - last track created if (trackid == -2) { trackid = Project.trackId; } string url = args[12]; // can be empty string descr = args[13]; // can be empty string source = args[14]; // can be empty bool keepInView = "true".Equals(args[15].ToLower()); CreateInfo ci = new CreateInfo(); ci.init(type); ci.comment = ""; ci.dateTime = dateTime; ci.desc = descr; ci.elev = elev; ci.id = trackid; ci.lat = lat; ci.lng = lng; //ci.magn = 0.0d; ci.name = name; ci.source = source; ci.sym = sym; ci.typeExtra = typeExtra; ci.url = url; ci.urlName = urlName; WaypointsCache.insertWaypoint(ci); if (keepInView) { GeoCoord loc = new GeoCoord(lng, lat); PictureManager.This.CameraManager.keepInView(loc); } } break; case "delwpt": { string name = args[2]; // like "GC12345" string urlName = args[3]; // like "Mike's cache" string source = args[4]; if (name.Length > 0) { WaypointsCache.RemoveWaypointByName(name); } else if (urlName.Length > 0) { WaypointsCache.RemoveWaypointByUrlname(urlName); } else if (source.Length > 0) { WaypointsCache.RemoveWaypointsBySource(source); } //PictureManager.This.CameraManager.ProcessCameraMove(); } break; case "newtrk": { string trackName = args[2]; // like "trip home" string type = args[3]; // like "trk" or "rte" string source = args[4]; // can be empty CreateInfo ci = new CreateInfo(); Project.trackId++; ci.init(type); ci.name = trackName; ci.id = Project.trackId; ci.source = source; WaypointsCache.insertWaypoint(ci); } break; case "deltrk": // or route { string name = args[2]; // like "track45" - if empty, use source string source = args[3]; // can delete by source - if empty, delete the last one if (name.Length > 0) { WaypointsCache.RemoveTracksByName(name); } else if (source.Length > 0) { WaypointsCache.RemoveTracksBySource(source); } else { // move ID pointer to the highest yet existing track/route: while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null) { Project.trackId--; } if (Project.trackId >= 0) { WaypointsCache.RemoveTrackById(Project.trackId); // move ID pointer to the highest yet existing track/route: while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null) { Project.trackId--; } } } PictureManager.This.CameraManager.ProcessCameraMove(); } break; case "newvehicle": { double lat = Convert.ToDouble(args[2]); double lng = Convert.ToDouble(args[3]); double elev = Convert.ToDouble(args[4]); DateTime dateTime = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now); string name = args[6]; // like "My Chevy" string sym = args[7]; // like "1" "2"... or empty string url = args[8]; // can be empty string source = args[9]; // can be empty string desc = args[10]; // can be empty bool keepInView = "true".Equals(args[11].ToLower()); bool doTrackLog = "true".Equals(args[12].ToLower()); GeoCoord loc = new GeoCoord(lng, lat, elev); GpsRealTimeData rtData = new GpsRealTimeData(); rtData.location = loc; rtData.fix = 2; rtData.time = dateTime; VehicleGps vehicle = new VehicleGps(rtData, name, sym, source, url, desc, doTrackLog); // also adds to VehicleCache vehicle.KeepInView = keepInView; VehiclesCache.addVehicle(vehicle); } break; case "movevehicle": { double lat = Convert.ToDouble(args[2]); double lng = Convert.ToDouble(args[3]); double elev = Convert.ToDouble(args[4]); DateTime dateTime = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now); string name = args[6]; // like "My Chevy" string sym = args[7]; // like "1" "2"... or empty string url = args[8]; // can be empty string source = args[9]; // can be empty string desc = args[10]; // can be empty bool keepInView = "true".Equals(args[11].ToLower()); bool doTrackLog = "true".Equals(args[12].ToLower()); GeoCoord loc = new GeoCoord(lng, lat, elev); GpsRealTimeData rtData = new GpsRealTimeData(); rtData.location = loc; rtData.fix = 2; rtData.time = dateTime; VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name); if (vehicle != null) { if (url.Length > 0) { vehicle.Url = url; } if (sym.Length > 0) { vehicle.Sym = sym; vehicle.setImage(sym); } if (desc.Length > 0) { vehicle.Desc = desc; } vehicle.KeepInView = keepInView; vehicle.doTrackLog = doTrackLog; vehicle.ProcessMove(rtData); } } break; case "delvehicle": { string name = args[2]; // like "My Chevy" or empty string source = args[3]; // can be empty VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name); if (vehicle != null) { bool wasTracking = vehicle.doTrackLog; VehiclesCache.deleteVehicle(vehicle); // takes care of removing it from LayerVehicle if (wasTracking) { PictureManager.This.CameraManager.ProcessCameraMove(); // refresh to have track endpoints } } } break; case "exporttofile": { string fileName = args[2]; int waypointCount = 0; int trkpointCount = 0; int tracksCount = 0; FileAndZipIO.saveGpx(fileName, WaypointsCache.TracksAll, true, WaypointsCache.WaypointsAll, true, out waypointCount, out trkpointCount, out tracksCount); if (waypointCount > 0 || trkpointCount > 0) { LibSys.StatusBar.Trace("OK: " + waypointCount + " waypoints and " + trkpointCount + " legs saved to file " + fileName); } else { LibSys.StatusBar.Error("failed to save to file (0 waypoints, 0 legs): " + fileName); } } break; } break; default: // regular command-line style messages - lon, lat, elev, map, file foreach (string arg in args) { if (arg.StartsWith("/")) { #if DEBUG LibSys.StatusBar.Trace("option: '" + arg + "'"); #endif try { if (arg.ToLower().StartsWith("/lat=")) { double lat = Convert.ToDouble(arg.Substring(5)); if (lat < 90.0d && lat > -90.0d) { pos.Lat = lat; doMove = true; } } else if (arg.ToLower().StartsWith("/lon=")) { double lon = Convert.ToDouble(arg.Substring(5)); if (lon < 180.0d && lon > -180.0d) { pos.Lng = lon; doMove = true; } } else if (arg.ToLower().StartsWith("/elev=")) { double elev = Convert.ToDouble(arg.Substring(6)); if (elev < Project.CAMERA_HEIGHT_MAX * 1000.0d && elev > Project.CAMERA_HEIGHT_MIN_DEFAULT * 1000.0d) { pos.Elev = elev; doMove = true; } } else if (arg.ToLower().StartsWith("/map=")) { string mode = arg.Substring(5); Project.mainCommand.setMapMode(mode); doMove = true; } } catch (Exception ee) { string message = "argument '" + arg + "' - wrong format (" + ee.Message + ")"; LibSys.StatusBar.Error(message); Project.ErrorBox(null, message); } } else { #if DEBUG LibSys.StatusBar.Trace("file: '" + arg + "'"); #endif files.Add(arg); } } if (files.Count > 0) { // similar to drag&drop: Cursor.Current = Cursors.WaitCursor; Project.mainForm.Focus(); Project.mainForm.BringToFront(); try { string[] fileNames = new string[files.Count]; int ii = 0; foreach (string fileName in files) { fileNames[ii] = fileName; ii++; } bool anySuccess = FileAndZipIO.readFiles(fileNames); if (anySuccess) // we need to zoom into whole set of dropped files, or refresh in case of JPG { Project.mainCommand.wptEnabled(true); if (!PictureManager.This.CameraManager.zoomToCorners()) { PictureManager.This.CameraManager.ProcessCameraMove(); // nowhere to zoom in - just refresh } } } catch { LibSys.StatusBar.Trace("* API: cannot accept arguments '" + strArgs + "'"); } Cursor.Current = Cursors.Default; } break; } // end switch if (doMove) { PictureManager.This.CameraManager.Location = pos; // calls ProcesCameraMove() } }
// xmlDoc must be Load'ed; can throw exceptions protected bool processGpx(string url, XmlDocument xmlDoc, string source) { bool ret = true; XmlNodeList waypointNodes = xmlDoc.DocumentElement.ChildNodes; //.SelectNodes("/gpx/wpt"); - this don't work #if DEBUG LibSys.StatusBar.Trace("IP: FileGpx:process() first level nodeCount=" + waypointNodes.Count); #endif /* * <gpx * version="1.0" * creator="EasyGPS 1.1.9 - http://www.topografix.com" * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" * xmlns="http://www.topografix.com/GPX/1/0" * xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/1" * xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd"> * <time>2002-10-04T18:49:55Z</time> * <bounds minlat="25.061783" minlon="-123.003111" maxlat="50.982883" maxlon="121.640267"/> * <wpt lat="33.575106480" lon="-117.735883651"> * <ele>159.703613</ele> * <time>2002-10-04T18:47:47Z</time> * <name><![CDATA[001]]></name> * <cmt><![CDATA[29-AUG-02 11:21:24PM]]></cmt> * <desc><![CDATA[001]]></desc> * <sym>Dot</sym> * <type><![CDATA[Dot]]></type> * </wpt> * <rte> * <name><![CDATA[HOME TO CNTRYC]]></name> * <number>1</number> * <topografix:color>ff0000</topografix:color> * <rtept lat="33.574991229" lon="-117.736144077"> * <time>2002-10-11T05:34:36Z</time> * <name><![CDATA[HOME]]></name> * <cmt><![CDATA[AURORA]]></cmt> * <desc><![CDATA[HOME]]></desc> * <sym>House</sym> * <type><![CDATA[Residence]]></type> * </rtept> * </rte> * <trk> * <name><![CDATA[ACTIVE LOG]]></name> * <number>1</number> * <topografix:color>ff0000</topografix:color> * <trkseg> * <trkpt lat="33.570749483" lon="-117.723665938"> * <ele>106.363037</ele> * <time>2002-10-11T04:32:08Z</time> * <sym>Waypoint</sym> * </trkpt> * <trkpt lat="33.571032289" lon="-117.722491633"> * <ele>99.153076</ele> * <time>2002-10-11T04:32:18Z</time> * <sym>Waypoint</sym> * </trkpt> * </trkseg> * </trk> * </gpx> */ CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. // we want to traverse XmlDocument fast, as tile load operations can be numerous // and come in pack. So we avoid using XPath and rely mostly on "foreach child": foreach (XmlNode nnode in waypointNodes) { try { switch (nnode.Name) { case "author": //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); break; case "desc": //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); break; case "bounds": //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); break; case "wpt": //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); createInfo.init("wpt"); createInfo.setLat(nnode.Attributes["lat"].InnerText); createInfo.setLng(nnode.Attributes["lon"].InnerText); createInfo.typeExtra = "unknown"; // type: ppl, school, park, locale, airport, reservoir, dam, // civil, cemetery, valley, building createInfo.source = source; foreach (XmlNode node in nnode.ChildNodes) { //LibSys.StatusBar.Trace(" child node=" + node.Name); switch (node.Name) { case "time": createInfo.setDateTime(node.InnerText); break; case "ele": createInfo.setElev(node.InnerText); break; case "name": createInfo.name = node.InnerText.Trim(); // number like 001 for route-related wpts or GCSDFX for geocaches break; case "desc": createInfo.desc = node.InnerText.Trim(); break; case "groundspeak:cache": createInfo.node1 = node; // will be parsed in Waypoint() constructor break; case "urlname": // may overwrite name in Pocket Queries createInfo.urlName = node.InnerText.Trim(); break; case "url": createInfo.url = node.InnerText.Trim(); break; case "cmt": createInfo.comment = node.InnerText.Trim(); // may contain time, so try to extract it if possible: try { createInfo.setDateTime(node.InnerText); } catch {} break; case "sym": createInfo.sym = node.InnerText.Trim(); break; case "type": // like "user waypoint" or "geocache" createInfo.typeExtra = node.InnerText.Trim(); break; } } m_insertWaypoint(createInfo); break; case "rte": { string routeName = ""; string routeColor = ""; bool routeCreated = false; foreach (XmlNode nnnode in nnode.ChildNodes) { switch (nnnode.Name) { case "name": // route name routeName = nnnode.InnerText.Trim(); break; case "number": // route number break; case "topografix:color": // like 00ffee routeColor = nnnode.InnerText.Trim(); break; case "rtept": /* * <rtept lat="38.518697986" lon="-122.978969274"> * <ele>4.211426</ele> * <time>2002-10-04T18:48:23Z</time> * <name><![CDATA[006]]></name> * <cmt><![CDATA[28-SEP-02 1:56:26PM]]></cmt> * <desc><![CDATA[006]]></desc> * <sym>Dot</sym> * <type><![CDATA[Dot]]></type> * </rtept> */ //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); if (!routeCreated) { Project.trackId++; createInfo.init("rte"); createInfo.name = routeName; createInfo.id = Project.trackId; createInfo.par1 = nnnode.InnerText.Trim(); // number for route createInfo.source = source; createInfo.par1 = routeColor; m_insertWaypoint(createInfo); // actually inserts a route routeCreated = true; } createInfo.init("rtept"); createInfo.setLat(nnnode.Attributes["lat"].InnerText); createInfo.setLng(nnnode.Attributes["lon"].InnerText); createInfo.id = Project.trackId; // relate waypoint to track createInfo.source = source; foreach (XmlNode node in nnnode.ChildNodes) { //LibSys.StatusBar.Trace(" child node=" + node.Name); switch (node.Name) { case "time": createInfo.setDateTime(node.InnerText); break; case "ele": createInfo.setElev(node.InnerText); break; case "name": createInfo.name = node.InnerText.Trim(); // number like 001 for route-related wpts or GCSDFX for geocaches break; case "desc": createInfo.desc = node.InnerText.Trim(); break; case "urlname": createInfo.urlName = node.InnerText.Trim(); break; case "url": createInfo.url = node.InnerText.Trim(); break; case "cmt": createInfo.comment = node.InnerText.Trim(); break; case "sym": createInfo.sym = node.InnerText.Trim(); if ("Waypoint".Equals(createInfo.sym)) { createInfo.sym = null; } break; case "type": // like "user waypoint" or "geocache" createInfo.typeExtra = node.InnerText.Trim(); break; } } m_insertWaypoint(createInfo); break; } } } break; case "trk": { string trackName = ""; string trackNumber = ""; string trackColor = ""; foreach (XmlNode nnnode in nnode.ChildNodes) { switch (nnnode.Name) { case "name": // track name trackName = nnnode.InnerText.Trim(); break; case "number": // track number trackNumber = nnnode.InnerText.Trim(); break; case "topografix:color": // like 00ffee trackColor = nnnode.InnerText.Trim(); break; case "trkseg": Project.trackId++; createInfo.init("trk"); createInfo.name = trackName; createInfo.id = Project.trackId; createInfo.source = source; createInfo.par1 = trackColor; m_insertWaypoint(createInfo); // actually inserts a track foreach (XmlNode nnnnode in nnnode.ChildNodes) { switch (nnnnode.Name) { case "trkpt": // track point /* * <trkpt lat="33.570749483" lon="-117.723665938"> * <ele>106.363037</ele> * <time>2002-10-11T04:32:08Z</time> * <sym>Waypoint</sym> * </trkpt> */ //LibSys.StatusBar.Trace("FileGpx:process() node=" + nnode.Name); createInfo.init("trkpt"); createInfo.setLat(nnnnode.Attributes["lat"].InnerText); createInfo.setLng(nnnnode.Attributes["lon"].InnerText); createInfo.id = Project.trackId; // relate waypoint to track createInfo.source = source; foreach (XmlNode node in nnnnode.ChildNodes) { //LibSys.StatusBar.Trace(" child node=" + node.Name); switch (node.Name) { case "time": createInfo.setDateTime(node.InnerText); break; case "ele": createInfo.setElev(node.InnerText); break; case "name": createInfo.name = node.InnerText.Trim(); break; case "desc": createInfo.desc = node.InnerText.Trim(); break; case "urlname": createInfo.urlName = node.InnerText.Trim(); break; case "url": createInfo.url = node.InnerText.Trim(); break; case "cmt": createInfo.comment = node.InnerText.Trim(); break; case "sym": createInfo.sym = node.InnerText.Trim(); if ("Waypoint".Equals(createInfo.sym)) { createInfo.sym = null; } break; case "type": // like "user waypoint" or "geocache" createInfo.typeExtra = node.InnerText.Trim(); break; } } m_insertWaypoint(createInfo); break; } } break; } } } break; } } catch (Exception ee) { // bad node - not a big deal... LibSys.StatusBar.Error("FileGpx process node=" + nnode.Name + " " + ee); //.Message); //LibSys.StatusBar.WriteLine("Culture: " + Thread.CurrentThread.CurrentCulture + " (" + Thread.CurrentThread.CurrentCulture.DisplayName + ") UseUserOverride=" + Thread.CurrentThread.CurrentCulture.UseUserOverride); } } return(ret); }
public override bool process(string url, string filename, string source) { bool ret = true; LibSys.StatusBar.Trace("IP: FileDelormeTxt:process() filename=" + filename); int wpCount = 0; int lineno = 0; try { string line; int state = 0; double zoneShift = 0.0d; CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. StreamReader stream = new StreamReader(filename); while ((line = stream.ReadLine()) != null) { lineno++; try { switch (state) { case 0: // look for "Date, Time" // Date, Time ((GMT-05:00) Eastern Time (DST)), Latitude, Longitude, Elevation (ft), Heading, Speed (mi/hr), GPS Status, Log Type if (line.StartsWith("Date, Time")) { state = 1; //LibSys.StatusBar.Trace("IP: FileDelormeTxt:process() state 1 filename=" + filename); Project.trackId++; createInfo.init("trk"); createInfo.id = Project.trackId; createInfo.source = source; createInfo.name = "DeLorme Blue Logger log"; m_insertWaypoint(createInfo); int pos = line.IndexOf("((GMT"); if (pos >= 0) { string sZoneShift = line.Substring(pos + 5, 3); zoneShift = Convert.ToDouble(sZoneShift); } } break; case 1: // read WPT numpoints lines like: // 08/01/2004, 11:04:04, 42:50:54.539, -70:52:16.195, -64.269, 44.08, 32.81, 3, 3 char[] sep = new Char[1] { ',' }; string[] split = line.Split(sep); DateTime dateTime = Convert.ToDateTime(split[0] + " " + split[1]); dateTime = dateTime.AddHours(-zoneShift); double lat = ParseCoord(split[2]); double lng = ParseCoord(split[3]); double elev = Convert.ToDouble(split[4]) * METERS_PER_FOOT; createInfo.init("trkpt"); createInfo.id = Project.trackId; // relate waypoint to track createInfo.dateTime = dateTime; createInfo.lat = lat; createInfo.lng = lng; createInfo.elev = elev; createInfo.source = source; m_insertWaypoint(createInfo); wpCount++; break; } } catch (Exception ee) { LibSys.StatusBar.Error("FileDelormeTxt:process(): file=" + filename + " line=" + lineno + " " + ee.Message); } } } catch (Exception eee) { LibSys.StatusBar.Error("FileDelormeTxt:process(): " + eee.Message); ret = false; } //LibSys.StatusBar.Trace("OK: FileDelormeTxt:process() filename=" + filename + " lines=" + lineno + " waypoints=" + wpCount); return(ret); }
public override bool process(string url, string filename, string source) { bool ret = true; OleDbConnection con = null; LibSys.StatusBar.Trace("IP: processing MDB file: " + filename); try { con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;data source=" + filename + ""); con.Open(); //connection must be opened DataTable dt = con.GetSchema("Tables"); DataRow row = dt.Select("TABLE_TYPE='TABLE'")[0]; string tableName = row["TABLE_NAME"].ToString(); OleDbCommand cmd = new OleDbCommand("SELECT * from [" + tableName + "]", con); // creating query command OleDbDataReader reader = cmd.ExecuteReader(); // executes query int i = 0; int errCnt = 0; while (reader.Read()) // if can read row from database { try { SectionRow sr = new SectionRow() { RECRD = (int)reader.GetValue(0), VESSLTERMS = reader.GetValue(1).ToString(), CHART = reader.GetValue(2).ToString(), AREA = reader.GetValue(3).ToString(), CARTOCODE = reader.GetValue(4).ToString(), SNDINGCODE = reader.GetValue(5).ToString(), DEPTH = reader.GetValue(6).ToString(), NATIVLAT = reader.GetValue(7).ToString(), NATIVLON = reader.GetValue(8).ToString(), LAT83 = reader.GetValue(9).ToString(), LONG83 = reader.GetValue(10).ToString(), LATDEC = (double)reader.GetValue(11), LONDEC = -(double)reader.GetValue(12), NATIVDATUM = reader.GetValue(13).ToString(), CONVERT83 = reader.GetValue(14).ToString(), GPACCURACY = reader.GetValue(15).ToString(), GPQUALITY = reader.GetValue(16).ToString(), GPSOURCE = reader.GetValue(17).ToString(), QUADRANT = reader.GetValue(18).ToString(), History = reader.GetValue(19).ToString(), REFERENCE = reader.GetValue(20).ToString(), YEARSUNK = reader.GetValue(21).ToString() }; CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. createInfo.init("wpt"); createInfo.name = (sr.VESSLTERMS + " " + sr.DEPTH).Trim(); createInfo.desc = sr.YEARSUNK; createInfo.lat = sr.LATDEC; createInfo.lng = sr.LONDEC; createInfo.typeExtra = "unknown"; // type: ppl, school, park, locale, airport, reservoir, dam, civil, cemetery, valley, building createInfo.source = source; createInfo.comment = sr.History.Replace(". ", ".\r\n") + ";\r\n" + sr.REFERENCE; m_insertWaypoint(createInfo); } catch (Exception excr) { errCnt++; } i++; } LibSys.StatusBar.Trace("OK: MDB file: '" + filename + "' processed; found table[" + tableName + "] records/waypoints count=" + i + " errors count=" + errCnt); } catch (Exception e) { LibSys.StatusBar.Error("FileAwoisMdb process() " + e.Message); ret = false; } finally { if (con != null) { con.Close(); } } return(ret); }
// return array of track IDs or null (if track can't be ungrouped) public static ArrayList ungroupTrack(Track trk, double breakTimeMinutes) { double maxJumpMeters = 5000.0d; // for sanity filter. make sure it is big enough, as GPSV makes big gaps. DateTime lastTime = DateTime.MinValue; GeoCoord lastLoc = null; int trip = 0; int i; // first count how many trips we can break the track into: for (i = 0; i < trk.Trackpoints.Count; i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); DateTime wptTime = wpt.DateTime; if (wptTime.CompareTo(lastTime.AddMinutes(breakTimeMinutes)) > 0 || (lastLoc != null && wpt.Location.distanceFrom(lastLoc).Meters > maxJumpMeters)) { trip++; } if (trip > 0) { lastTime = wptTime; } lastLoc = wpt.Location; } if (trip < 2) { return(null); } // more than one trip, go ahead break it: string[] infos = new string[8]; string newTrackSource = trk.Source; lastTime = DateTime.MinValue; lastLoc = null; trip = 0; ArrayList ret = new ArrayList(); for (i = 0; i < trk.Trackpoints.Count; i++) { Waypoint wpt = (Waypoint)trk.Trackpoints.GetByIndex(i); DateTime wptTime = wpt.DateTime; if (wptTime.CompareTo(lastTime.AddMinutes(breakTimeMinutes)) > 0 || (lastLoc != null && wpt.Location.distanceFrom(lastLoc).Meters > maxJumpMeters)) { Project.trackId++; trip++; string newTrackName = trk.Name + "-trip-" + trip; CreateInfo createInfo = new CreateInfo(); createInfo.init(trk.Type); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.url = trk.Url; currentTrack = new Track(createInfo); m_tracksAll.Add(currentTrack); ret.Add(Project.trackId); } if (trip > 0) { Waypoint cloneWpt = new Waypoint(wpt); cloneWpt.TrackId = Project.trackId; currentTrack.insertWaypoint(cloneWpt); lastTime = wptTime; } lastLoc = wpt.Location; } // make sure the speed and odometer values are computed: foreach (long trackId in ret) { Track ttrk = getTrackById(trackId); ttrk.rebuildTrackBoundaries(); } // now apply Sanity Filter: if (Project.sanityFilter) { ArrayList ret1 = new ArrayList(); foreach (long trackId in ret) { Track ttrk = getTrackById(trackId); if (ttrk.Trackpoints.Count >= 5 && ttrk.Odometer > 10.0f) // odometer in meters, eliminates standing points { ret1.Add(trackId); } else { RemoveTrackById(trackId); } } if (ret1.Count < 2) { //return null; } ret = ret1; } if (ret != null) { isDirty = true; } return(ret); }
public override bool process(string url, string filename, string source) { bool ret = true; LibSys.StatusBar.Trace("IP: FileNmeaLog:process() filename=" + filename); int wpCount = 0; int lineno = 0; int packetsCount = 0; Cursor.Current = Cursors.WaitCursor; try { string line; double zoneShift = 0.0d; NmeaPacketReceived packetIn = null; CreateInfo createInfo = new CreateInfo(); // we will recycle it in place, filling every time. double lat = 0.0d; double lng = 0.0d; // we allow elev and dateTime to stay in the cycle and be promoted/inherited to points that do not have this data in NMEA sentence. double elev = 0.0d; // alt above mean sea level DateTime dateTime = DateTime.Now; StreamReader stream = new StreamReader(filename); while ((line = stream.ReadLine()) != null) { lineno++; // we are in a VERY long cycle here, need to make sure Windows events and memory are managed Application.DoEvents(); if (lineno % 1000 == 0) { GC.Collect(); } line = line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } try { // first see if that was a proprietary, non-NMEA packet: if (line.IndexOf("*") < 0) { LibSys.StatusBar.Trace("proprietary packet: " + line); if (packetIn != null && packetIn.isGood) { LibSys.StatusBar.Trace("last good NMEA packet: " + packetIn); } if (line.StartsWith("$ADVER,")) { Project.trackId++; createInfo.init("trk"); createInfo.id = Project.trackId; createInfo.source = source; createInfo.name = "GPS NMEA Log"; insertWaypoint(createInfo); } } else { packetIn = new NmeaPacketReceived(); packetIn.isGood = false; packetIn.m_string = line; if (!NmeaPacket.checksumVerify(packetIn.m_string)) { packetIn.isGood = false; LibSys.StatusBar.Error("bad checksum, line " + lineno + " bad packet: " + line); } else { packetIn.isGood = packetIn.basicParse(packetIn.m_string); // packet is good and parsed, so the fields array is filled //LibSys.StatusBar.Trace("NMEA packet: " + packetIn); if (packetIn.header.EndsWith("GGA")) // NMEA GGA expected for location { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); try { NmeaPacket pvt = packetIn.fromString(); /* * $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 * * Where: * GGA Global Positioning System Fix Data * 0 123519 Fix taken at 12:35:19 UTC * 1 4807.038,N Latitude 48 deg 07.038' N * 3 01131.000,E Longitude 11 deg 31.000' E * 5 1 Fix quality: 0 = invalid * 1 = GPS fix * 2 = DGPS fix * 6 = estimated (2.3 feature) * 6 08 Number of satellites being tracked * 7 0.9 Horizontal dilution of position * 8 545.4,M Altitude, Meters, above mean sea level * 10 46.9,M Height of geoid (mean sea level) above WGS84 * ellipsoid * 12 (empty field) time in seconds since last DGPS update * 13 (empty field) DGPS station ID number * 47 the checksum data, always begins with * */ lat = pvt.parseLat(1); lng = pvt.parseLng(1); elev = pvt.parseElev(8); // alt above mean sea level // time component (don't know the date): dateTime = pvt.parseNmeaTime(0, dateTime); // UTC dateTime = dateTime.AddHours(-zoneShift); // errors and velocity: double posError = 0; double posErrorH = 0; double posErrorV = 0; double fix = 0; // failed integrity check switch ((string)pvt.fields[5]) { case "0": // invalid fix = 1; // invalid break; case "1": // GPS fix fix = 2; // two dimensional break; case "2": // DGPS fix fix = 4; // two dimensional differential break; case "6": // estimated fix = 6; // estimated break; } string comment = "received " + packetIn.header; //realtimeCallback(pvtData); createInfo.init("trkpt"); createInfo.id = Project.trackId; // relate waypoint to track createInfo.dateTime = dateTime; createInfo.lat = lat; createInfo.lng = lng; createInfo.elev = elev; createInfo.source = source; insertWaypoint(createInfo); wpCount++; packetsCount++; } catch (Exception ee) { LibSys.StatusBar.Error("StartRealTime: " + ee.Message); } } else if (packetIn.header.EndsWith("RMC")) // NMEA RMC may come { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); try { NmeaPacket pvt = packetIn.fromString(); // $GPRMC,052458.73,V,3334.6441,N,11739.6622,W,00.0,000.0,290103,13,E*4F /* * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference * * RMC - NMEA has its own version of essential gps pvt (position, velocity, time) data. * It is called RMC, The Recommended Minimum, which might look like: * * $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A * $GPRMC,050821.000,A,3334.5551,N,11739.7705,W,0.00,,251006,,,A*67 * * Where: * RMC Recommended Minimum sentence C * 0 123519 Fix taken at 12:35:19 UTC * 1 A Status A=active or V=Void. * 2 4807.038,N Latitude 48 deg 07.038' N * 4 01131.000,E Longitude 11 deg 31.000' E * 6 022.4 Speed over the ground in knots * 7 084.4 Track angle in degrees True * 8 230394 Date - 23rd of March 1994 * 9 003.1,W Magnetic Variation * 6A The checksum data, always begins with * * * Note that, as of the 2.3 release of NMEA, there is a new field in the RMC sentence * at the end just prior to the checksum. The value of the entry is * A=autonomous, D=differential, E=estimated, N=Data not valid. */ bool status = "A".Equals(pvt.fields[1]); if (status) { lat = pvt.parseLat(2); lng = pvt.parseLng(2); //double elev = 0.0d; // inherit elevation from a GGA //LibSys.StatusBar.Trace("coord=" + pvtData.location); // time component (only time part): dateTime = pvt.parseNmeaDateTime(0, 8); // UTC dateTime = dateTime.AddHours(-zoneShift); //if (!"".Equals(pvt.fields[6])) //{ // double knots = Convert.ToDouble(pvt.fields[6]); // pvtData.velocity = knots * Distance.METERS_PER_NAUTICAL_MILE / 3600.0d; // // calculate velocity vector based on track angle: // if (!"".Equals(pvt.fields[7])) // { // double trackAngleRad = Convert.ToDouble(pvt.fields[7]) * Math.PI / 180.0d; // pvtData.velocityNorth = pvtData.velocity * Math.Cos(trackAngleRad); // pvtData.velocityEast = pvtData.velocity * Math.Sin(trackAngleRad); // } //} //pvtData.fix = 2; // assume two-dimensional //pvtData.comment = "received " + received.header; createInfo.init("trkpt"); createInfo.id = Project.trackId; // relate waypoint to track createInfo.dateTime = dateTime; createInfo.lat = lat; createInfo.lng = lng; createInfo.elev = elev; createInfo.source = source; insertWaypoint(createInfo); wpCount++; } packetsCount++; } catch (Exception ee) { LibSys.StatusBar.Error("StartRealTime: " + ee.Message); } } else if (packetIn.header.EndsWith("WPL")) // NMEA WPL may come as a result of manually marking a location { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); try { NmeaPacket pvt = packetIn.fromString(); // $GPWPL,3334.7038,N,11739.7796,W,00001*61 /* * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference * * WPL - Waypoint Location data provides essential waypoint data. It is output when navigating to indicate data about the destination * and is sometimes supported on input to redefine a waypoint location. Note that waypoint data as defined in the standard * does not define altitude, comments, or icon data. When a route is active, this sentence is sent once for each waypoint in * the route, in sequence. When all waypoints have been reported, the RTE sentence is sent in the next data set. * In any group of sentences, only one WPL sentence, or an RTE sentence, will be sent. * * $GPWPL,4807.038,N,01131.000,E,WPTNME*5C * * With an interpretation of: * * WPL Waypoint Location * 0 4807.038,N Latitude * 1 01131.000,E Longitude * 2 WPTNME Waypoint Name * 5C The checksum data, always begins with * * */ lat = pvt.parseLat(0); lng = pvt.parseLng(0); //elev = 0.0d; // inherit elevation //LibSys.StatusBar.Trace("coord=" + pvtData.location); createInfo.init("wpt"); createInfo.lat = lat; createInfo.lng = lng; createInfo.elev = elev; createInfo.dateTime = dateTime; createInfo.name = "" + pvt.fields[4]; createInfo.source = source; insertWaypoint(createInfo); wpCount++; packetsCount++; } catch (Exception ee) { LibSys.StatusBar.Error("StartRealTime: " + ee.Message); } } //else if (packetIn.header.EndsWith("GLL")) // NMEA GLL may come //{ // LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); // try // { // NmeaPacket pvt = packetIn.fromString(); // // $GPGLL,3334.6464,N,11739.6583,W,052707.129,A*29 // /* // * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference // * // GLL - Geographic Latitude and Longitude is a holdover from Loran data and some old units // may not send the time and data valid information if they are emulating Loran data. // If a gps is emulating Loran data they may use the LC Loran prefix instead of GP. // $GPGLL,4916.45,N,12311.12,W,225444,A,*31 // Where: // GLL Geographic position, Latitude and Longitude // 0 4916.46,N Latitude 49 deg. 16.45 min. North // 2 12311.12,W Longitude 123 deg. 11.12 min. West // 4 225444 Fix taken at 22:54:44 UTC // 5 A Data valid or V (void) // *31 checksum data // */ // bool status = "A".Equals(pvt.fields[5]); // if (status) // { // double lat = pvt.parseLat(0); // double lng = pvt.parseLng(0); // double elev = 0.0d; // // time component (only time part): // //pvtData.time = pvt.parseNmeaTime(4); // UTC // //pvtData.fix = 2; // assume two-dimensional // //pvtData.comment = "received " + received.header; // createInfo.init("trkpt"); // createInfo.id = Project.trackId; // relate waypoint to track // //createInfo.dateTime = dateTime; // createInfo.lat = lat; // createInfo.lng = lng; // createInfo.elev = elev; // createInfo.source = source; // insertWaypoint(createInfo); // wpCount++; // } // packetsCount++; // } // catch (Exception ee) // { // LibSys.StatusBar.Error("StartRealTime: " + ee.Message); // } //} else if (packetIn.header.EndsWith("GSV")) // NMEA GSV may come for satellite reception status { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); // /* // * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference // * // $GPGSV,3,1,08,14,69,204,,15,57,105,36,18,45,047,36,03,42,263,36*71 // $GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75 // Where: // GSV Satellites in view // 0 2 Number of sentences for full data // 1 1 sentence 1 of 2 // 2 08 Number of satellites in view // for up to 4 satellites per sentence { // 3 01 Satellite PRN number // 4 40 Elevation, degrees // 5 083 Azimuth, degrees // 6 46 Signal strength - higher is better // } // *75 the checksum data, always begins with * // */ // //MPacket pvt = received.fromString(); // //pvtData.comment = "received"; // //realtimeCallback(pvtData); packetsCount++; } else if (packetIn.header.EndsWith("VTG")) // NMEA GSA may come { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); // $GPVTG,309.62,T,,M,0.13,N,0.2,K*6E /* * VTG - Course Over Ground and Ground Speed * * Name Example Units Description * Message ID $GPVTG VTG protocol header * Course 309.62 degrees Measured heading * Reference T True * Course degrees Measured heading * Reference M Magnetic * Speed 0.13 knots Measured horizontal speed * Units N Knots * Speed 0.2 Km/hr Measured horizontal speed * Units K Kilometers per hour */ packetsCount++; } else if (packetIn.header.EndsWith("GSA")) // NMEA GSA may come { //LibSys.StatusBar.Trace("process: " + packetIn.header + " packet, count=" + packetsCount + " content=" + packetIn); // $GPGSA,A,2,15,18,14,31,,,,,,,,,05.6,05.6,*17 /* * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference * * GSA - GPS DOP and active satellites. This sentence provides details on the nature of the * fix. It includes the numbers of the satellites being used in the current solution and * the DOP. DOP (dilution of precision) is an indication of the effect of satellite geometry * on the accuracy of the fix. It is a unitless number where smaller is better. For 3D fixes * using 4 satellites a 1.0 would be considered to be a perfect number. For overdetermined * solutions it is possible to see numbers below 1.0. There are differences in the way the * PRN's are presented which can effect the ability of some programs to display this data. * For example, in the example shown below there are 5 satellites in the solution and * the null fields are scattered indicating that the almanac would show satellites in * the null positions that are not being used as part of this solution. Other receivers * might output all of the satellites used at the beginning of the sentence with the * null field all stacked up at the end. This difference accounts for some satellite * display programs not always being able to display the satellites being tracked. * * $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39 * * Where: * GSA Satellite status * A Auto selection of 2D or 3D fix (M = manual) * 3 3D fix - other values include: 1 = no fix * 2 = 2D fix * 04,05... PRNs of satellites used for fix (space for 12) * 2.5 PDOP (dilution of precision) * 1.3 Horizontal dilution of precision (HDOP) * 2.1 Vertical dilution of precision (VDOP) * 39 the checksum data, always begins with * * */ packetsCount++; } else { LibSys.StatusBar.Trace("StartRealTime: good other (unrecognized) packet received, count=" + packetsCount + " content=" + packetIn); } } } } catch (Exception ee) { LibSys.StatusBar.Error("FileNmeaLog:process(): file=" + filename + " line=" + lineno + " " + ee.Message); } } } catch (Exception eee) { LibSys.StatusBar.Error("FileNmeaLog:process(): " + eee.Message); ret = false; } finally { Cursor.Current = Cursors.Default; Application.DoEvents(); } LibSys.StatusBar.Trace("OK: FileNmeaLog:process() filename=" + filename + " lines=" + lineno + ", packets=" + packetsCount + " waypoints=" + wpCount); return(ret); }
} // time zulu private void addToRoute(GeoCoord location, Waypoint wpt, Earthquake eq) { rteptNumber++; string wptName = "" + rteptNumber; if (m_routeTrack == null) { // first route-making click on the map, create track to hold the new route string newTrackSource = "route - user created " + DateTime.Now; Project.trackId++; rteptNumber = 1; m_lastWpt = null; string newTrackName = "Route-" + Project.trackId; CreateInfo createInfo = new CreateInfo(); createInfo.init("rte"); createInfo.id = Project.trackId; createInfo.name = newTrackName; createInfo.source = newTrackSource; createInfo.par1 = "" + rteNumber; rteNumber++; if (rteNumber > 20) { rteNumber = 1; } m_routeTrack = new Track(createInfo); m_routeTrack.isRoute = true; WaypointsCache.TracksAll.Add(m_routeTrack); wptName = "Start route"; } m_speed = null; if (m_lastWpt != null && m_lastWpt.HasSpeed) { m_speed = new Speed(m_lastWpt.Speed); } else { m_speed = new Speed(Project.routeSpeed); } TimeSpan dur = new TimeSpan(100000); Waypoint routeWpt = null; bool wasNew = false; if (wpt != null) { routeWpt = new Waypoint(wpt); routeWpt.LiveObjectType = LiveObjectTypes.LiveObjectTypeRoutepoint; routeWpt.DateTime = m_dateTimeRte; } else if (eq != null) { //wptName = eq.ToString(); wptName = string.Format("{0:F1} - ", eq.Magn) + eq.sDateTime + " - " + eq.Comment; routeWpt = new Waypoint(eq.Location, m_dateTimeRte, LiveObjectTypes.LiveObjectTypeRoutepoint, Project.trackId, wptName, eq.Source, eq.Url); } else { // location must not be null then: routeWpt = new Waypoint(location, m_dateTimeRte, LiveObjectTypes.LiveObjectTypeRoutepoint, Project.trackId, "", "user created", ""); // no URL routeWpt.NameDisplayed = wptName; wasNew = true; } if (m_speed != null) { routeWpt.Speed = (float)m_speed.Meters; } if (m_lastWpt != null && m_lastWpt.TrackId == Project.trackId) { Distance dist = routeWpt.distanceFrom(m_lastWpt.Location); double durSeconds = m_speed.Meters <= 0.0d ? 0.000001d : (dist.Meters / m_speed.Meters * 3600.0d); dur = new TimeSpan((long)(durSeconds * 10000000.0d)); m_dateTimeRte += dur; } routeWpt.DateTime = m_dateTimeRte; m_lastWpt = routeWpt; // we need to make sure that the point added is different from the last point in track. // Magellan will not accept routes with zero-length legs. Waypoint lastWpt = null; if (m_routeTrack.Trackpoints.Count > 0) { lastWpt = (Waypoint)m_routeTrack.Trackpoints.GetByIndex(m_routeTrack.Trackpoints.Count - 1); } if (lastWpt == null || lastWpt.Location.distanceFrom(routeWpt.Location).Meters > 2.0d) { if (wasNew && lastWpt != null) { routeWpt.Location.Elev = lastWpt.Location.Elev; } m_routeTrack.Trackpoints.Add(routeWpt.DateTime, routeWpt); m_routeTrack.PutOnMap(this, null, this); if (wptName.Length > 2) { //m_cameraManager.MarkLocation(mouseGeoLocation, 0); m_cameraManager.ProcessCameraMove(); // make sure label is positionsed on the map } else { // invalidate picture region around just created leg: Waypoint prevWpt = (Waypoint)m_routeTrack.Trackpoints.GetByIndex(m_routeTrack.Trackpoints.Count - 2); Point p1 = m_cameraManager.toPixelLocation(routeWpt.Location, null); Point p2 = m_cameraManager.toPixelLocation(prevWpt.Location, null); int x = Math.Min(p1.X, p2.X); int y = Math.Min(p1.Y, p2.Y); int w = Math.Abs(p1.X - p2.X); int h = Math.Abs(p1.Y - p2.Y); Rectangle toInv = new Rectangle(x, y, w, h); toInv.Offset(-5, -5); toInv.Inflate(10, 10); m_pictureManager.Invalidate(toInv); } } }