public static double SpatialDistanceBetweenPlaces(Wgs84Coordinates a, Wgs84Coordinates b) { var fablat = new DotSpatial.Positioning.Latitude((double)a.Latitude); var fablng = new DotSpatial.Positioning.Longitude((double)a.Longitude); var sglat = new DotSpatial.Positioning.Latitude((double)b.Latitude); var sglng = new DotSpatial.Positioning.Longitude((double)b.Longitude); var fab = new DotSpatial.Positioning.Position(fablat, fablng); var sg = new DotSpatial.Positioning.Position(sglat, sglng); DotSpatial.Positioning.Distance dist = fab.DistanceTo(sg); return(dist.ToMeters().Value); } // End Function SpatialDistanceBetweenPlaces
} // End Function SpatialDistanceBetweenPlaces public static double SpatialDistanceBetweenPlacesDotSpatial( double lat1 , double lng1 , double lat2 , double lng2) { var fablat = new DotSpatial.Positioning.Latitude(lat1); var fablng = new DotSpatial.Positioning.Longitude(lng1); var sglat = new DotSpatial.Positioning.Latitude(lat2); var sglng = new DotSpatial.Positioning.Longitude(lng2); var fab = new DotSpatial.Positioning.Position(fablat, fablng); var sg = new DotSpatial.Positioning.Position(sglat, sglng); DotSpatial.Positioning.Distance dist = fab.DistanceTo(sg); return(dist.ToMeters().Value); } // End Function SpatialDistanceBetweenPlacesDotSpatial
/// <summary> /// Encode the Nav data. /// </summary> /// <param name="ens">Ensemble.</param> /// <returns>String for Nav data.</returns> private string EncodeNavData(DataSet.Ensemble ens) { if (ens.IsNmeaAvail) { double lat_sec = 0; double lon_sec = 0; double speed = 0; double course = 0; if (ens.NmeaData.IsGpggaAvail()) { // Latitude DotSpatial.Positioning.Latitude lat = ens.NmeaData.GPGGA.Position.Latitude; if (!lat.IsInvalid) { lat_sec = (int)Math.Truncate(lat.DecimalDegrees) * 60; // Degrees converted to minutes lat_sec += (int)Math.Truncate((double)lat.Minutes); // Minutes convert to Minutes lat_sec += lat.Seconds / 60.0; // Seconds convert to minutes lat_sec *= 60; // Convert to seconds lat_sec *= 1000; // Convert to thousands of second if (lat.Hemisphere == DotSpatial.Positioning.LatitudeHemisphere.South) { lat_sec *= -1; // Make negative } } // Longitude DotSpatial.Positioning.Longitude lon = ens.NmeaData.GPGGA.Position.Longitude; if (!lon.IsInvalid) { lon_sec = (int)Math.Truncate(lon.DecimalDegrees) * 60; // Degrees converted to minutes lon_sec += (int)Math.Truncate((double)lon.Minutes); // Minutes convert to Minutes lon_sec += lon.Seconds / 60.0; // Seconds convert to minutes lon_sec *= 60; // Convert to seconds lon_sec *= 1000; // Convert to thousands of second if (lon.Hemisphere == DotSpatial.Positioning.LongitudeHemisphere.West) { lon_sec *= -1; // Make negative } } } if (ens.NmeaData.IsGpvtgAvail()) { // Velocity speed = ens.NmeaData.GPVTG.Speed.ToMetersPerSecond().Value * 1000; // Make mm/s } if (ens.NmeaData.IsGphdtAvail()) { // Course course = ens.NmeaData.GPHDT.Heading.DecimalDegrees * 100; // Make hundreth of degree } StringBuilder sb = new StringBuilder(); sb.Append("8"); // 8 Header sb.Append("\t" + ((int)Math.Round(lat_sec)).ToString()); // Latitude in thousandths of a second sb.Append(" " + ((int)Math.Round(lon_sec)).ToString()); // Longitude in thousandths of a second sb.Append(" " + ((int)Math.Round(speed)).ToString()); // Speed in mm/s sb.Append(" " + ((int)Math.Round(course)).ToString()); // Course in hundreth of second sb.Append(" 0 0"); sb.Append("\r\n"); return(sb.ToString()); } return(""); }