public bool Equals(GeoCoordinate gc) { // If parameter is null return false: if ((object)gc == null) { return false; } // Return true if the fields match: return (this.Latitude == gc.Latitude) && (this.Longitude == gc.Longitude); }
// Track length in meters public static double GetTrackLength(string databaseFile) { StreamReader streamReader = new StreamReader(databaseFile); string line = null; GeoCoordinate gc = new GeoCoordinate(); // To avoid anussigned variable issue double distance = 0; // "Zero" iteration if ((line = streamReader.ReadLine()) != null) gc = GeoCoordinate.GetFromLine(line); // Iterating further while ((line = streamReader.ReadLine()) != null) { distance += GeoMath.DistanceBetweenCoordinatesMeters(gc, (gc = GeoCoordinate.GetFromLine(line))); } streamReader.Close(); return distance; }
public TrackObjectRecord(GeoCoordinate MessageCoordinate, double Distance, byte[] TReceptionDataExBytes) { this.MessageCoordinate = MessageCoordinate; this.Distance = Distance; this.TReceptionDataExBytes = TReceptionDataExBytes; }
// Distance between coordinates in kilometers public static double DistanceBetweenCoordinates(GeoCoordinate c1, GeoCoordinate c2) { return GeoMath.DistanceBetweenCoordinates(c1.Latitude, c1.Longitude, c2.Latitude, c2.Longitude); }
// s — distance in meters to the point to be added in (c1,c2) derection after c2 public static GeoCoordinate CoordinateSurplus(GeoCoordinate c1, GeoCoordinate c2, double s) { double distance = DistanceBetweenCoordinatesMeters(c1, c2); double f = (distance + s) / distance; return IntermediateCoordinate(c1, c2, f); }
// f is distance from (xi. yi) to (x1,y1) divided by distance between (x1,y1) and (x2,y2) public static GeoCoordinate IntermediateCoordinate(GeoCoordinate c1, GeoCoordinate c2, double f) { return new GeoCoordinate() { Longitude = c1.Longitude + f * (c2.Longitude - c1.Longitude), Latitude = c1.Latitude + f * (c2.Latitude - c1.Latitude) }; }
public static int FindNearest(GeoCoordinate point, List<GeoCoordinate> path) { double d_mm = 0; int i_mm = -1; double d_m = Metrics(point.Latitude, point.Longitude, path[0].Latitude, path[0].Longitude); int i_m = 0; double d = 0; int i = -1; for (i = 1; i < path.Count - 1; i++) { d = Metrics(point.Latitude, point.Longitude, path[i].Latitude, path[i].Longitude); if (d < d_m) { d_mm = d_m; i_mm = i_m; d_m = d; i_m = i; } } return i_m; }
// Distance between coordinates in meters public static double DistanceBetweenCoordinatesMeters(GeoCoordinate c1, GeoCoordinate c2) { return GeoMath.DistanceBetweenCoordinates(c1, c2) * 1000; }