Ejemplo n.º 1
0
 public Datum(DateTime time, Latitude latitude, Longitude longitude, Length altitude = null, Speed speed = null, Heading heading = null)
 {
     _time = time;
     _location = new GeoPosition(latitude, longitude, altitude);
     _speed = speed;
     _heading = heading;
 }
 public Decoded(GeoPosition currentLocation, DateTime currentTime, Heading currentHeading, Speed currentSpeed)
 {
     CurrentLocation = currentLocation;
     CurrentTime = currentTime;
     CurrentHeading = currentHeading;
     CurrentSpeed = currentSpeed;
 }
Ejemplo n.º 3
0
 public void VerifyDistance(double lat1, double long1, double lat2, double long2, double expectedLengthInMeters)
 {
     GeoPosition start = new GeoPosition(lat1, long1);
     GeoPosition stop = new GeoPosition(lat2, long2);
     GreatArc.Distance(start, stop)
             .In(LengthUnit.Kilometer)
             .ShouldEqualWithinPrecision(expectedLengthInMeters, 2);
 }
            public bool IsInside(GeoPosition position)
            {
                //todo first check if in bounding box

                bool result = false;
                for (int i = 0,
                         j = _corners.Count - 1;
                    i < _corners.Count;
                    j = i, i++) {
                    var p1 = _corners[i];
                    var p2 = _corners[j];
                    if (p1.Latitude < position.Latitude && position.Latitude <= p2.Latitude
                        || p2.Latitude < position.Latitude && position.Latitude <= p1.Latitude) {
                        if (p1.Longitude + (position.Latitude - p1.Latitude) / (p2.Latitude - p1.Latitude) * (p2.Longitude - p1.Longitude) < position.Longitude) {
                            result = !result;
                        }
                    }
                }
                return result;
            }
Ejemplo n.º 5
0
        //http://www.movable-type.co.uk/scripts/latlong.html
        public static Length Distance(GeoPosition start, GeoPosition stop)
        {
            var phi1 = new Angle(start.Latitude, AngleUnit.Degree) {
                Units = AngleUnit.Radian
            };
            var phi2 = new Angle(stop.Latitude, AngleUnit.Degree) {
                Units = AngleUnit.Radian
            };
            var deltaPhi = new Angle(stop.Latitude - start.Latitude, AngleUnit.Degree) {
                Units = AngleUnit.Radian
            };
            var deltaLong = new Angle(stop.Longitude - start.Longitude, AngleUnit.Degree) {
                Units = AngleUnit.Radian
            };

            var sinOfHalfPhi = Math.Sin(deltaPhi.Value / 2);
            var sinOfHalfLong = Math.Sin(deltaLong.Value / 2);

            var a = sinOfHalfPhi * sinOfHalfPhi + Math.Cos(phi1.Value) * Math.Cos(phi2.Value) * sinOfHalfLong * sinOfHalfLong;
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            return EarthsRadius * c;
        }
 public Decoded(GeoPosition currentLocation, DateTime currentTime)
 {
     CurrentLocation = currentLocation;
     CurrentTime = currentTime;
 }
Ejemplo n.º 7
0
 public static Circle AsCircle(string id, GeoPosition center, Length radius)
 {
     return new Circle(id, center, radius);
 }
 public LocationChangedEventArgs(GeoPosition position, Heading heading)
 {
     _position = position;
     _heading = heading;
 }
Ejemplo n.º 9
0
        public GpsUnit(IProvideSentences nmeaProvider)
        {
            MinimumFixForNotification = GpsFixType.ThreeD;
            CurrentLocation = new GeoPosition(0, 0, new Length(0, LengthUnit.Meter));
            CurrentHeading = Heading.Unknown;

            _nmeaProvider = nmeaProvider;
            _nmeaProvider.SentenceReceived += sentence => {
                                                  Message message = _parser.Parse(sentence);
                                                  if (message == null) {
                                                      return;
                                                  }
                                                  //NB set all values then raise all notifications
                                                  if (message.Value is IProvideSatelliteInfo) {
                                                      foreach (SatelliteInfo satellite in message.ValueAs<IProvideSatelliteInfo>()
                                                                                                 .Satellites) {
                                                          _satellites[satellite.Prn] = satellite;
                                                      }
                                                  }
                                                  if (message.Value is IProvideActiveSatellites) {
                                                      _activeSatellitePrns.Clear();
                                                      foreach (int prn in message.ValueAs<IProvideActiveSatellites>()
                                                                                 .ActiveSatellitePrns.Where(prn => prn != 0)) {
                                                          _activeSatellitePrns.Add(prn);
                                                      }
                                                  }
                                                  if (message.Value is IProvideFixType) {
                                                      CurentFixType = message.ValueAs<IProvideFixType>()
                                                                             .CurrentFix;
                                                  }
                                                  if (message.Value is IProvideDilutionOfPrecision) {
                                                      var dop = message.ValueAs<IProvideDilutionOfPrecision>();
                                                      _positionDop = dop.PositionDop;
                                                      _horizontalDop = dop.HorizontalDop;
                                                      _verticalDop = dop.VerticalDop;
                                                  }
                                                  if (message.Value is IProvideTime) {
                                                      CurrentTime = message.ValueAs<IProvideTime>()
                                                                           .CurrentTime;
                                                  }
                                                  if (message.Value is IProvideTrajectory) {
                                                      //NB heading and speed are correlated
                                                      IProvideTrajectory trajectory = message.ValueAs<IProvideTrajectory>();
                                                      CurrentSpeed = trajectory.CurrentSpeed;
                                                      // NB don't update heading when speed is near zero
                                                      if (CurrentSpeed > MinimumSpeedForHeadingUpdate) {
                                                          CurrentHeading = trajectory.CurrentHeading;
                                                      }
                                                  }
                                                  if (message.Value is IProvideGeoPosition) {
                                                      var newLocation = message.ValueAs<IProvideGeoPosition>()
                                                                               .CurrentLocation;
                                                      CurrentLocation = newLocation.Altitude == null
                                                                            ? new GeoPosition(newLocation.Latitude,
                                                                                              newLocation.Longitude,
                                                                                              CurrentLocation.Altitude)
                                                                            : newLocation;
                                                      RaiseLocationChanged();
                                                  }
                                              };

            _nmeaProvider.Open();
        }