public void TestDistanceTo()
        {
            var a = new LatLongCoordinate(30, 30);
            var b = new LatLongCoordinate(40, 31);

            Assert.AreEqual(1113141.546, a.DistanceTo(b, ReferenceEllipsoid.Wgs84), 0.0000001);
        }
        public void TestParse()
        {
            var latLongCoordinate = LatLongCoordinate.Parse("n 54 30 w 100 15");

            Assert.AreEqual(54.5, latLongCoordinate.Latitude);
            Assert.AreEqual(-100.25, latLongCoordinate.Longitude);
        }
        public void TestFromDecimalDegrees()
        {
            var latLongCoordinate = LatLongCoordinate.FromDecimalDegrees("N54.5 W100.25");

            Assert.AreEqual(54.5, latLongCoordinate.Latitude);
            Assert.AreEqual(-100.25, latLongCoordinate.Longitude);
        }
Beispiel #4
0
        public void LatLongToSvy21Test()
        {
            Svy21Coordinate   expected, actual;
            LatLongCoordinate test;

            // SVY21 Reference Point.
            expected = new Svy21Coordinate(38744.572, 28001.642);
            test     = new LatLongCoordinate(1.366666, 103.833333);
            actual   = Svy21.ComputeSvy21(test);
            Assert.AreEqual(expected.Northing, actual.Northing, ToleranceSvy21);
            Assert.AreEqual(expected.Easting, actual.Easting, ToleranceSvy21);

            // Corner of Ang Mo Kio 66kV Substation.
            expected = new Svy21Coordinate(39105.269, 30629.967);
            test     = new LatLongCoordinate(1.3699278977737488, 103.85695034976466);
            actual   = Svy21.ComputeSvy21(test);
            Assert.AreEqual(expected.Northing, actual.Northing, ToleranceSvy21);
            Assert.AreEqual(expected.Easting, actual.Easting, ToleranceSvy21);

            // Corner of Jurong Lake Canal 400kV Cable Bridge.
            expected = new Svy21Coordinate(36307.704, 16272.970);
            test     = new LatLongCoordinate(1.3446255443241177, 103.72794378041792);
            actual   = Svy21.ComputeSvy21(test);
            Assert.AreEqual(expected.Northing, actual.Northing, ToleranceSvy21);
            Assert.AreEqual(expected.Easting, actual.Easting, ToleranceSvy21);

            // Corner of Sembawang 66kV Substation.
            expected = new Svy21Coordinate(48187.789, 27720.130);
            test     = new LatLongCoordinate(1.4520670518379692, 103.83080332777138);
            actual   = Svy21.ComputeSvy21(test);
            Assert.AreEqual(expected.Northing, actual.Northing, ToleranceSvy21);
            Assert.AreEqual(expected.Easting, actual.Easting, ToleranceSvy21);
        }
        public void TestFromConvertible()
        {
            var latLongCoordinate = LatLongCoordinate.FromConvertibleString("-1, -10");

            Assert.AreEqual(-1, latLongCoordinate.Latitude);
            Assert.AreEqual(-10, latLongCoordinate.Longitude);
        }
        public void TestToDmsString()
        {
            var a = new LatLongCoordinate(1, 10);

            Assert.AreEqual("1, 10", a.ToString());
            Assert.AreEqual("1, 10", a.ToString("g"));
            Assert.AreEqual("N1 00.000 E10 00.000", a.ToString("dm"));
            Assert.AreEqual("N1° 0' 0.0\" E10° 0' 0.0\"", a.ToString("dms"));

            var b = new LatLongCoordinate(-1, 10);

            Assert.AreEqual("-1, 10", b.ToString());
            Assert.AreEqual("-1, 10", b.ToString("g"));
            Assert.AreEqual("S1 00.000 E10 00.000", b.ToString("dm"));
            Assert.AreEqual("S1° 0' 0.0\" E10° 0' 0.0\"", b.ToString("dms"));

            var c = new LatLongCoordinate(1, -10);

            Assert.AreEqual("1, -10", c.ToString());
            Assert.AreEqual("1, -10", c.ToString("g"));
            Assert.AreEqual("N1 00.000 W10 00.000", c.ToString("dm"));
            Assert.AreEqual("N1° 0' 0.0\" W10° 0' 0.0\"", c.ToString("dms"));

            var d = new LatLongCoordinate(-1, -10);

            Assert.AreEqual("-1, -10", d.ToString());
            Assert.AreEqual("-1, -10", d.ToString("g"));
            Assert.AreEqual("S1 00.000 W10 00.000", d.ToString("dm"));
            Assert.AreEqual("S1° 0' 0.0\" W10° 0' 0.0\"", d.ToString("dms"));
        }
        public void TestSphereDistanceTo()
        {
            var a = new LatLongCoordinate(30, 30);
            var b = new LatLongCoordinate(40, 31);

            Assert.AreEqual(1116900.07417898, a.SphereDistanceTo(b), 0.0000001);
        }
        public void TestFromLatLong()
        {
            var ll            = new LatLongCoordinate(49.354435f, -114.524994f);
            var ntsGridSystem = ll.ToBcNtsGridSystem();

            Assert.AreEqual("C-022-H/082-G-07", ntsGridSystem.ToString());
        }
        public void TestConstructDm()
        {
            //Degrees/Minutes
            var latLongCoordinate = new LatLongCoordinate(50, 3, 100, 1);

            Assert.AreEqual(50.0499992370605, latLongCoordinate.Latitude, 0.00000001);
            Assert.AreEqual(100.016670227051, latLongCoordinate.Longitude, 0.00000001);
        }
        public void TestClone()
        {
            var latLongCoordinate = LatLongCoordinate.FromRadians((float)Math.PI, (float)Math.PI / 2);
            var cloned            = latLongCoordinate.Clone();

            Assert.AreNotSame(latLongCoordinate, cloned);
            Assert.AreEqual(latLongCoordinate, cloned);
        }
        public void TestConstructDms()
        {
            //Degrees/Minute/Seconds
            var latLongCoordinate = new LatLongCoordinate(50, 3, 4, 100, 1, 2);

            Assert.AreEqual(50.0511093139648, latLongCoordinate.Latitude, 0.00000001);
            Assert.AreEqual(100.017219543457, latLongCoordinate.Longitude, 0.00000001);
        }
        public void TestGreatCircleAngle()
        {
            var a = new LatLongCoordinate(30, 30);
            var b = new LatLongCoordinate(40, 31);

            var d = LatLongCoordinate.GreatCircleAngle(a, b);

            Assert.AreEqual(10.033284074692, d.Degrees, 0.00000001);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <param name="bearing">องศา</param>
        /// <param name="dis">เมตร</param>
        /// <returns>[0] = lat, [1] = lon</returns>
        public double[] AnotherPoint(double lat, double lon, double bearing, double dis)
        {
            UtmCoordinate utm     = ConversionFunctions.LLToUtm(23, lat, lon);
            UtmCoordinate utm_out = ConversionFunctions.LocationFromRangeBearing(utm, dis, bearing);

            LatLongCoordinate ll = ConversionFunctions.UtmToLL(23, utm_out);

            double[] output = new double[] { ll.Latitude, ll.Longitude };
            return(output);
        }
        public void TestFromRadians()
        {
            var latLongCoordinate = LatLongCoordinate.FromRadians((float)Math.PI, (float)Math.PI / 2);

            Assert.AreEqual(90, latLongCoordinate.Latitude);
            Assert.AreEqual(90, latLongCoordinate.Longitude);

            Assert.AreEqual(Math.PI / 2, latLongCoordinate.RadiansLat, 0.000001);
            Assert.AreEqual(Math.PI / 2, latLongCoordinate.RadiansLon, 0.000001);
        }
        public static List <Carpark> fixURACarparkData()
        {
            FetchPublicAPI publicAPI = new FetchPublicAPI();

            var carparks = new List <Carpark>();

            // URA Carpark Info
            var task = Task.Run(async() => await publicAPI.GetURAParkingInfoAsync());

            var URACarparkInfo = task.Result;

            var carparkNo = "";

            foreach (var r in URACarparkInfo)
            {
                if (carparkNo != r.ppCode)
                {
                    double xcoord = 0.00, ycoord = 0.00;

                    if (r.geometries != null)
                    {
                        var uncooord = r.geometries[0].coordinates.Split(",");
                        var x        = uncooord[0];
                        var y        = uncooord[1];

                        Svy21Coordinate svy21 = new Svy21Coordinate(double.Parse(x), double.Parse(y));

                        LatLongCoordinate latLong = svy21.ToLatLongCoordinate();

                        xcoord = latLong.Latitude;
                        ycoord = latLong.Longitude;
                    }

                    Carpark carpark = new Carpark()
                    {
                        Id            = Guid.NewGuid(),
                        CarparkId     = r.ppCode,
                        CarparkName   = r.ppName,
                        Address       = r.ppName,
                        AgencyType    = "URA",
                        IsCentral     = false,
                        XCoord        = xcoord.ToString(),
                        YCoord        = ycoord.ToString(),
                        ParkingSystem = "",
                        LotType       = ""
                    };

                    carparks.Add(carpark);
                }

                carparkNo = r.ppCode;
            }

            return(carparks);
        }
        public void TestInequality()
        {
            var a = new LatLongCoordinate(1, 10);
            var b = new LatLongCoordinate(2, 10);

            Assert.IsFalse(a == b);
            Assert.IsTrue(a != b);

            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
        }
        public void TestBcGeographicSystem2()
        {
            // A-1-A/83-J-3
            var nts = new LatLongCoordinate(54, -115).ToBcNtsGridSystem();

            Assert.AreEqual('A', nts.QuarterUnit);
            Assert.AreEqual(1, nts.Unit);
            Assert.AreEqual('A', nts.Block);

            Assert.AreEqual(83, nts.Series);
            Assert.AreEqual('J', nts.MapArea);
            Assert.AreEqual(3, nts.Sheet);
        }
        public void TestDirectionTo()
        {
            var a = new LatLongCoordinate(30, 30);
            var b = new LatLongCoordinate(30, 30);

            Assert.AreEqual(Angle.FromRadians(0), a.DirectionTo(b));
            Assert.AreEqual(Angle.FromRadians(0), b.DirectionTo(a));

            var c = new LatLongCoordinate(0, 0);

            Assert.AreEqual(Angle.FromRadians(3.903035f).Degrees, a.DirectionTo(c).Degrees, 0.0001);
            Assert.AreEqual(Angle.FromRadians(0.7614422f).Degrees, c.DirectionTo(a).Degrees, 0.0001);
        }
        public void TestBcGeographicSystem1()
        {
            // A-1-A/82-O-1
            var a   = new LatLongCoordinate(51, -114);
            var nts = a.ToBcNtsGridSystem();

            Assert.AreEqual('A', nts.QuarterUnit);
            Assert.AreEqual(1, nts.Unit);
            Assert.AreEqual('A', nts.Block);

            Assert.AreEqual(82, nts.Series);
            Assert.AreEqual('O', nts.MapArea);
            Assert.AreEqual(1, nts.Sheet);
        }
        public void TestToBcGeographicSystem()
        {
            var bc = new LatLongCoordinate(54, -112).ToBcNtsGridSystem();

            Assert.IsNotNull(bc);

            Assert.AreEqual('A', bc.QuarterUnit);
            Assert.AreEqual(1, bc.Unit);
            Assert.AreEqual('A', bc.Block);

            Assert.AreEqual(83, bc.Series);
            Assert.AreEqual('I', bc.MapArea);
            Assert.AreEqual(1, bc.Sheet);
        }
        public void TestDlsSystem2()
        {
            var dls = new LatLongCoordinate(54, -115).ToDlsSystem();

            //9-8-58-7-W5
            Assert.AreEqual('W', dls.Direction);
            Assert.AreEqual(5, dls.Meridian);
            Assert.AreEqual(58, dls.Township);
            Assert.AreEqual(7, dls.Range);

            Assert.AreEqual(8, dls.Section);
            Assert.AreEqual("NE", dls.Quarter);
            Assert.AreEqual(9, dls.LegalSubdivision);
        }
        public void TestDlsSystemNearFifth()
        {
            var coordinate = new LatLongCoordinate(51, -114);

            var dls = LatLongCoordinate.ToDlsSystem(coordinate);

            //5-33-23-29-W4
            Assert.AreEqual(23, dls.Township);
            Assert.AreEqual(29, dls.Range);
            Assert.AreEqual('W', dls.Direction);
            Assert.AreEqual(4, dls.Meridian);

            Assert.AreEqual(33, dls.Section);
            Assert.AreEqual("SW", dls.Quarter);
            Assert.AreEqual(5, dls.LegalSubdivision);
        }
Beispiel #23
0
        public void Test4()
        {
            double easting            = 27720.130;
            double northing           = 48187.789;
            CoordinateConverter cc    = new CoordinateConverter();
            Coordinate          input = new Coordinate();

            input.X = easting;
            input.Y = northing;
            Coordinate actualonemap = cc.Fr3414To4326Async(input).Result;

            Svy21Coordinate   test      = new Svy21Coordinate(northing, easting);
            LatLongCoordinate actualnus = Svy21.ComputeLatitudeLongitude(test);

            Assert.AreEqual(actualonemap.longitude, actualnus.Longitude, ToleranceLatLong);
            Assert.AreEqual(actualonemap.latitude, actualnus.Latitude, ToleranceLatLong);
        }
Beispiel #24
0
        public void Test4()
        {
            double longitude = 103.83080332777138;
            double latitude  = 1.4520670518379692;

            CoordinateConverter cc    = new CoordinateConverter();
            Coordinate          input = new Coordinate();

            input.longitude = longitude;
            input.latitude  = latitude;
            Coordinate actualonemap = cc.Fr4326To3414Async(input).Result;

            LatLongCoordinate test      = new LatLongCoordinate(latitude, longitude);
            Svy21Coordinate   actualnus = Svy21.ComputeSvy21(test);

            Assert.AreEqual(actualonemap.Y, actualnus.Northing, ToleranceSvy21);
            Assert.AreEqual(actualonemap.X, actualnus.Easting, ToleranceSvy21);
        }
Beispiel #25
0
        public void Test3()
        {
            double longitude = 103.72794378041792;
            double latitude  = 1.3446255443241177;

            CoordinateConverter cc    = new CoordinateConverter();
            Coordinate          input = new Coordinate();

            input.longitude = longitude;
            input.latitude  = latitude;
            Coordinate actualonemap = cc.Fr4326To3414Async(input).Result;

            LatLongCoordinate test      = new LatLongCoordinate(latitude, longitude);
            Svy21Coordinate   actualnus = Svy21.ComputeSvy21(test);

            Assert.AreEqual(actualonemap.Y, actualnus.Northing, ToleranceSvy21);
            Assert.AreEqual(actualonemap.X, actualnus.Easting, ToleranceSvy21);
        }
Beispiel #26
0
        public void Test2()
        {
            double longitude = 103.856950349764668;
            double latitude  = 1.3699278977737488;

            CoordinateConverter cc    = new CoordinateConverter();
            Coordinate          input = new Coordinate();

            input.longitude = longitude;
            input.latitude  = latitude;
            Coordinate actualonemap = cc.Fr4326To3414Async(input).Result;

            LatLongCoordinate test      = new LatLongCoordinate(latitude, longitude);
            Svy21Coordinate   actualnus = Svy21.ComputeSvy21(test);

            Assert.AreEqual(actualonemap.Y, actualnus.Northing, ToleranceSvy21);
            Assert.AreEqual(actualonemap.X, actualnus.Easting, ToleranceSvy21);
        }
Beispiel #27
0
        public void EnsureRelativeTests()
        {
            var dlsWest      = new DlsSystem(8, 36, 23, 1, 5);
            var dlsEast      = new DlsSystem(5, 33, 23, 29, 4);
            var dlsNorthWest = new DlsSystem(9, 36, 23, 1, 5);

            var latWest      = dlsWest.ToLatLong();
            var latEast      = dlsEast.ToLatLong();
            var latNorthWest = dlsNorthWest.ToLatLong();

            Assert.IsTrue(latWest.Longitude < latEast.Longitude);

            var latTest = new LatLongCoordinate(51, -114);
            var a       = latTest.RelativeDistanceTo(latWest);
            var b       = latTest.RelativeDistanceTo(latEast);
            var c       = latTest.RelativeDistanceTo(latNorthWest);

            //assert that location b is closest to the test location
            Assert.IsTrue(b < a);
            Assert.IsTrue(b < c);
        }
Beispiel #28
0
        public void TestAddBoat()
        {
            bool      result    = false;
            BoatModel boatModel = new BoatModel {
                name = "boat 1", capacity = 300, pricePerHour = 30, seasonId = 1, imagePath = "Public/images"
            };
            LatLongCoordinate point = new LatLongCoordinate(5, 4, "asd");

            point.saveInDB();
            // Get location
            Location location = MainClass.Instance.getLocations().Find(v => v.id == 3007);

            if (MainClass.Instance.addLocation(new Location(point, location.name)))
            {
                if (location != null)
                {
                    if (location.addBoat(new Boat(boatModel.name, boatModel.capacity, boatModel.pricePerHour, boatModel.seasonId, boatModel.imagePath)))
                    {
                        result = true;
                    }
                }
            }
            Assert.IsTrue(result);
        }
Beispiel #29
0
 protected bool Equals(LatLongCoordinate other)
 {
     return(Latitude.Equals(other.Latitude) && Longitude.Equals(other.Longitude));
 }
Beispiel #30
0
 protected bool Equals(LatLongCoordinate other)
 {
     return Latitude.Equals(other.Latitude) && Longitude.Equals(other.Longitude);
 }