public void GetBearingThrowsArgumentExceptionWithInvalidOriginCoordinates()
        {
            Coordinate origin      = Constants.Coordinates.LatitudeBelowMinimum;
            Coordinate destination = Constants.Coordinates.ValidCoordinate;

            var ex = Assert.Throws <ArgumentException>(() => GeoCalculator.GetBearing(origin.Latitude, origin.Longitude, destination.Latitude, destination.Longitude));

            Assert.AreEqual("Invalid origin coordinates supplied.", ex.Message);
        }
        public void GetBearingWithCoordinateObjectReturnsCorrectResult()
        {
            Coordinate origin      = Constants.Coordinates.ValidCoordinate;
            Coordinate destination = Constants.Coordinates.ValidDestinationCoordinate;

            double       distance       = GeoCalculator.GetBearing(origin, destination);
            const double expectedResult = 337.39007167195172;

            Assert.AreEqual(expectedResult, distance);
        }
        public void GetBearingReturnsCorrectResult()
        {
            Coordinate origin      = Constants.Coordinates.ValidCoordinate;
            Coordinate destination = Constants.Coordinates.ValidDestinationCoordinate;

            double       distance       = GeoCalculator.GetBearing(origin.Latitude, origin.Longitude, destination.Latitude, destination.Longitude);
            const double expectedResult = 337.39007167195172;

            Assert.AreEqual(distance, expectedResult);
        }
Exemplo n.º 4
0
        void konekin_NewSerialDataReceived(object sender, Koneksi.SerialDataEventArgs e)
        {
            Thread.Sleep(1000);
            try
            {
                pesan = e.Data;
            }
            catch { }

            {
                //pesan = pesan.Replace('.', ',');
                data = pesan.Split(' ');
                Dispatcher.Invoke((Action)(() => SerialMonitor.Text += pesan + " " + data.Length.ToString() + "\n"));


                try
                {
                    // 0        1   2   3       4       5           6          7
                    //GPSTIME Lat Long  Suhu Tekananan Kelembaban Ketinggian CO2
                    if (data.Length == 8)
                    {
                        try
                        {
                            double distance = GeoCalculator.GetDistance(Convert.ToDouble(data[1]), Convert.ToDouble(data[2]), -7.76395814, 110.3767115, 4);
                            double bearing  = GeoCalculator.GetBearing(-7.76395814, 110.3767115, Convert.ToDouble(data[1]), Convert.ToDouble(data[2]));
                            double vertikal = itung(distance * 1609.34, Convert.ToDouble(data[6]));
                            this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate()
                            {
                                #region terminal text
                                try
                                {
                                    //SerialMonitor.AppendText("MAHESWARA_KOMBAT2016 " + " " + data[4] + " " + data[6] + " " + data[5] + " " + data[3] +  " " + data[2] + " " + data[1] + "\n");
                                    using (StreamWriter writer = File.AppendText(logName))
                                    {
                                        //konekin.tulis(data[9] + " " + data[10]);
                                        writer.WriteLine("MAHESWARAUGM" + " " + data[0] + " " + data[1] + " " + data[2] + " " + data[3] + " " + data[4] + " " + data[5] + " " + data[6] + " " + data[7] + " " + bearing + " " + vertikal + " " + distance * 1609.34);
                                    }
                                }
                                catch { }
                                inpulat.Text  = bearing.ToString("F0");
                                inputver.Text = vertikal.ToString("F0");
                                SerialMonitor.ScrollToEnd();
                                Dispatcher.Invoke((Action)(() => konekin.tulis(bearing.ToString("F0") + " " + inputver.Text)));
                                #endregion
                            }));
                        }
                        catch (Exception) { }
                    }
                }
                catch (Exception) { }
            }
        }
        public static Coordinate GetStepCoordinates(Coordinate from, Coordinate to, double distance)
        {
            var bearing = GeoCalculator.GetBearing(from, to);

            var angle = GetRelativeBearingToClosestDirection(bearing);

            var(latitudeFactor, longitudeFactor) = CorrectionFactors(angle, bearing);

            var boundaries = new CoordinateBoundaries(from, distance, DistanceUnit.Meters);

            var maxLongitude = GetMaxLongitudeFromBearing(boundaries, bearing);
            var maxLatitude  = GetMaxLatitudeFromBearing(boundaries, bearing);

            var newLongitude = from.Longitude + (maxLongitude - from.Longitude) * longitudeFactor;
            var newLatitude  = from.Latitude + (maxLatitude - from.Latitude) * latitudeFactor;

            return(new Coordinate(newLatitude, newLongitude));
        }