Exemple #1
0
        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
Exemple #2
0
        } // 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>
        /// If GGA NMEA data is available, calculate the magnitude and direction
        /// of the current position to the start.
        /// </summary>
        /// <param name="ensemble"></param>
        private void AccumulateGps(DataSet.Ensemble ensemble)
        {
            // If the previous postion has not been set, we cannot calculate yet
            if (_firstGpsPos == DotSpatial.Positioning.Position.Empty)
            {
                if (ensemble.IsNmeaAvail)
                {
                    if (ensemble.NmeaData.IsGpggaAvail() && !ensemble.NmeaData.GPGGA.Position.IsInvalid && ensemble.NmeaData.GPGGA.Position.Longitude.DecimalDegrees != Double.NaN)
                    {
                        _firstGpsPos = ensemble.NmeaData.GPGGA.Position;

                        GpsPoints.Points.Add(new DataPoint(0 + XOffset, 0 + YOffset));
                    }
                }

                // Nothing to calculate yet
                return;
            }

            // Calculate the magnitude and direction
            // Use the first position and the current position
            // If the previous postion has not been set, we cannot calculate yet
            if (_firstGpsPos != DotSpatial.Positioning.Position.Empty && !_firstGpsPos.IsInvalid)
            {
                if (ensemble.IsNmeaAvail)
                {
                    if (ensemble.NmeaData.IsGpggaAvail() && !ensemble.NmeaData.GPGGA.Position.IsInvalid && ensemble.NmeaData.GPGGA.Position.Longitude.DecimalDegrees != Double.NaN)
                    {
                        GpsMag = _firstGpsPos.DistanceTo(ensemble.NmeaData.GPGGA.Position).ToMeters().Value;     // Meters           Distance Made Good
                        GpsDir = _firstGpsPos.BearingTo(ensemble.NmeaData.GPGGA.Position).DecimalDegrees;        // Decimal Degrees  Course Made Good
                        //GpsDir = ensemble.NmeaData.GPGGA.Position.BearingTo(_firstGpsPos).DecimalDegrees;       // Decimal Degrees  Course Over Ground

                        // Generate X,Y point
                        double x = YOffset + (GpsMag * Math.Sin(MathHelper.DegreeToRadian(GpsDir)));
                        double y = XOffset + (GpsMag * Math.Cos(MathHelper.DegreeToRadian(GpsDir)));

                        // Add the point to the line series
                        GpsPoints.Points.Add(new DataPoint(x, y));
                    }
                }
            }
        }