public void Datum_ConvertToWgsAndStringAndLatLng_TheyShouldAllBeEqual() { var attempts = 1000; while (--attempts != 0) { var latlng = RandomLatLng(); // Create a test position var datum = new Terratype.CoordinateSystems.Gcj02.DatumType() { Latitude = latlng.Latitude, Longitude = latlng.Longitude }; var gcj02 = new Terratype.CoordinateSystems.Gcj02(datum); var parse = gcj02.ToString(); gcj02.Parse(parse); var parse2 = gcj02.ToString(); Assert.AreEqual(parse, parse2); var compare = gcj02.Datum; Assert.AreEqual(datum.Latitude, compare.Latitude, Delta); Assert.AreEqual(datum.Longitude, compare.Longitude, Delta); } }
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); } } } }