コード例 #1
0
        public void LatLng_ConvertToWgsAndStringAndDatum_TheyShouldAllBeEqual()
        {
            var attempts = 1000;

            while (--attempts != 0)
            {
                //  Create a test position
                var latlng = RandomLatLng();

                var gcj02 = new Terratype.CoordinateSystems.Gcj02(latlng);

                var parse = gcj02.ToString();
                gcj02.Parse(parse);

                var parse2 = gcj02.ToString();

                Assert.AreEqual(parse, parse2);

                var datum = gcj02.Datum;
                gcj02.Datum = datum;

                var compare = gcj02.ToWgs84();

                Assert.AreEqual(latlng.Latitude, compare.Latitude, Delta);
                Assert.AreEqual(latlng.Longitude, compare.Longitude, Delta);
            }
        }
コード例 #2
0
        public void StringWithDifferentCulture_ConvertToWgsAndDatumAndLatLng_TheyShouldAllBeEqual()
        {
            foreach (var culture in Cultures)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
                var attempts = 1000;
                while (--attempts != 0)
                {
                    var latlng = RandomLatLng();
                    //  Create a test position
                    var test = latlng.Latitude.ToString(CultureInfo.InvariantCulture) + "," +
                               latlng.Longitude.ToString(CultureInfo.InvariantCulture);

                    var gcj02 = new Terratype.CoordinateSystems.Gcj02(test);

                    var parse = gcj02.ToString();
                    gcj02.Parse(parse);

                    var parse2 = gcj02.ToString();

                    Assert.AreEqual(parse, parse2);

                    var datum = gcj02.Datum;
                    Assert.AreEqual(latlng.Latitude, datum.Latitude, Delta);
                    Assert.AreEqual(latlng.Longitude, datum.Longitude, Delta);

                    var compare = gcj02.ToWgs84();

                    if (gcj02.IsChina)
                    {
                        //  Calculate the maximum difference at this latitute between wgs84 and gcj02. We are allowing upto 2km difference
                        var maximumDifference = MetersToDecimalDegrees(2000.0, compare.Latitude);

                        var latitudeDifference = Math.Abs(latlng.Latitude - compare.Latitude);
                        Assert.IsTrue(latitudeDifference < maximumDifference);

                        var longitudeDifference = Math.Abs(latlng.Longitude - compare.Longitude);
                        Assert.IsTrue(longitudeDifference < maximumDifference);
                    }
                    else
                    {
                        //  If this isn't china then the datum will hold a wgs84 position
                        Assert.AreEqual(latlng.Latitude, compare.Latitude, Delta);
                        Assert.AreEqual(latlng.Longitude, compare.Longitude, Delta);
                    }
                }
            }
        }