/// <summary> /// Performs an OSGB36/ODN to ETRS89 datum transformation. Accuracy is approximately 10 centimeters. /// Whilst very accurate this method is much slower than the Helmert transformation. /// </summary> public static LatitudeLongitude OsgbToEtrs89(Osgb36 coordinates, OstnVersionEnum ostnVersion = OstnVersionEnum.OSTN15) { //calculate shifts from OSGB36 point double errorN = double.MaxValue; double errorE = double.MaxValue; EastingNorthing enCoordinates = null; Shifts shiftsA = GetShifts(coordinates, ostnVersion); //0.0001 error meters int iter = 0; while ((errorN > 0.0001 || errorE > 0.0001) && iter < 10) { enCoordinates = new EastingNorthing(coordinates.Easting - shiftsA.Se, coordinates.Northing - shiftsA.Sn); Shifts shiftsB = GetShifts(enCoordinates, ostnVersion); errorE = Math.Abs(shiftsA.Se - shiftsB.Se); errorN = Math.Abs(shiftsA.Sn - shiftsB.Sn); shiftsA = shiftsB; iter++; } return(Convert.ToLatitudeLongitude(new Wgs84(), new BritishNationalGrid(), enCoordinates)); }
public static void Examples() { Console.WriteLine("-- OS Map reference --"); // Convert to Osgb36 coordinates by creating a new object passing // in the EastingNorthing object to the constructor. EastingNorthing eastingNorthing = new EastingNorthing(319267, 175189); Console.WriteLine("INPUT"); Console.WriteLine($"Easting: {eastingNorthing.Easting}"); Console.WriteLine($"Northing: {eastingNorthing.Northing}"); Osgb36 osgb36EN = new Osgb36(eastingNorthing); string mapReference = osgb36EN.MapReference; Console.WriteLine("OUTPUT"); Console.WriteLine($"Map reference: {mapReference}"); Console.WriteLine(); }
public static void Example() { Console.WriteLine("-- Obtaining Greater Accuracy --"); LatitudeLongitude latLong = new LatitudeLongitude(51.469886, -3.1636964, 108.05); Console.WriteLine("INPUT"); Console.WriteLine($"Latitude: {latLong.Latitude}"); Console.WriteLine($"Longitude: {latLong.Longitude}"); Console.WriteLine($"Ellipsoidal Height: {latLong.EllipsoidalHeight}"); Osgb36 bng = GeoUK.OSTN.Transform.Etrs89ToOsgb(latLong); Console.WriteLine("OUTPUT"); Console.WriteLine($"Map reference: {bng.MapReference}"); Console.WriteLine($"Easting: {bng.Easting}"); Console.WriteLine($"Northing: {bng.Northing}"); Console.WriteLine($"Height: {bng.Height}"); Console.WriteLine(); }
public LatitudeLongitude ConvertEastNorthToLatLong_HigherAccuracySlow(double easting, double northing) { Osgb36 accurate = new Osgb36(easting, northing); return(GeoUK.OSTN.Transform.OsgbToEtrs89(accurate)); }
public void Etrs89ToOsgb_OSTN15_Test() { string inputFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDataFiles_OSGM15_OSTN15/OSTN15_OSGM15_TestInput_ETRStoOSGB.txt"); string outputFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestDataFiles_OSGM15_OSTN15/OSTN15_OSGM15_TestOutput_ETRStoOSGB.txt"); List <DataPoint> inputData = new List <DataPoint>(); Dictionary <string, DataPoint> outputData = new Dictionary <string, DataPoint>(); using (StreamReader inputFile = new StreamReader(inputFileName)) { string line; while ((line = inputFile.ReadLine()) != null) { if (string.IsNullOrEmpty(line) || !line.StartsWith("TP")) { continue; } string[] values = line.Split(','); DataPoint point = new DataPoint { PointID = values[0], X = double.Parse(values[1]), Y = double.Parse(values[2]), Height = double.Parse(values[3]) }; inputData.Add(point); } } using (StreamReader outputFile = new StreamReader(outputFileName)) { string line; while ((line = outputFile.ReadLine()) != null) { if (string.IsNullOrEmpty(line) || !line.StartsWith("TP")) { continue; } string[] values = line.Split(','); DataPoint point = new DataPoint { PointID = values[0], X = double.Parse(values[1]), Y = double.Parse(values[2]), Height = double.Parse(values[3]) }; outputData[point.PointID] = point; } } foreach (DataPoint dataPoint in inputData) { Osgb36 transformation = Transform.Etrs89ToOsgb(new LatitudeLongitude(dataPoint.X, dataPoint.Y, dataPoint.Height)); // Comparing values with a precision of 3 decimals, as they are given in the output file. bool latitudesEqual = outputData[dataPoint.PointID].X .IsApproximatelyEqualTo(transformation.Easting, 0.001); bool longitudesEqual = outputData[dataPoint.PointID].Y .IsApproximatelyEqualTo(transformation.Northing, 0.001); bool heightsEqual = outputData[dataPoint.PointID].Height .IsApproximatelyEqualTo(transformation.Height, 0.001); Assert.True(latitudesEqual); Assert.True(longitudesEqual); Assert.True(heightsEqual); } }