Skip to content

Commit c58fac4

Browse files
IeuanWalkerCopilot
andauthored
LatitudeLongitude from easting northing helper (#54)
* Refactor LatitudeLongitude class and add conversion method Updated `LatitudeLongitude.cs` to include new using directives for `GeoUK.Ellipsoids` and `GeoUK.Projections`. The class structure has been improved for clarity, and a new static method `FromEastingNorthing` has been added to convert easting and northing coordinates to latitude and longitude using Cartesian transformations and projections. * Update GeoUK/Coordinates/LatitudeLongitude.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix comment typo in LatitudeLongitude.cs Removed incorrect comment about ETRS89 and WGS84. No changes to functionality; transformation logic remains intact. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent be72e40 commit c58fac4

File tree

1 file changed

+67
-47
lines changed

1 file changed

+67
-47
lines changed
Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
1+
using GeoUK.Ellipsoids;
2+
using GeoUK.Projections;
3+
14
namespace GeoUK.Coordinates
25
{
3-
/// <summary>
4-
/// This immutable class represents a set of latitude/longitude/ellipsoidal height coordinates.
5-
/// </summary>
6-
public class LatitudeLongitude
7-
8-
{
9-
10-
/// <summary>
11-
/// Constructor.
12-
/// </summary>
13-
/// <param name="degreesLatitude"></param>
14-
/// <param name="degreesLongitude"></param>
15-
public LatitudeLongitude(double degreesLatitude, double degreesLongitude)
16-
{
17-
Latitude = degreesLatitude;
18-
Longitude = degreesLongitude;
19-
EllipsoidalHeight = 0.0;
20-
}
21-
22-
/// <summary>
23-
/// Constructor.
24-
/// </summary>
25-
/// <param name="degreesLatitude"></param>
26-
/// <param name="degreesLongitude"></param>
27-
/// <param name="ellipsoidalHeight"></param>
28-
public LatitudeLongitude(double degreesLatitude, double degreesLongitude, double ellipsoidalHeight)
29-
{
30-
Latitude = degreesLatitude;
31-
Longitude = degreesLongitude;
32-
EllipsoidalHeight = ellipsoidalHeight;
33-
}
34-
35-
/// <summary>
36-
/// Returns latitude in degrees.
37-
/// </summary>
38-
public double Latitude { get; }
39-
40-
/// <summary>
41-
/// Returns longitude in degrees.
42-
/// </summary>
43-
public double Longitude { get; }
44-
45-
/// <summary>
46-
/// returns ellipsoidal height in meters.
47-
/// </summary>
48-
public double EllipsoidalHeight { get; }
49-
}
6+
/// <summary>
7+
/// This immutable class represents a set of latitude/longitude/ellipsoidal height coordinates.
8+
/// </summary>
9+
public class LatitudeLongitude
10+
{
11+
/// <summary>
12+
/// Constructor.
13+
/// </summary>
14+
/// <param name="degreesLatitude"></param>
15+
/// <param name="degreesLongitude"></param>
16+
public LatitudeLongitude(double degreesLatitude, double degreesLongitude)
17+
{
18+
Latitude = degreesLatitude;
19+
Longitude = degreesLongitude;
20+
EllipsoidalHeight = 0.0;
21+
}
22+
23+
/// <summary>
24+
/// Constructor.
25+
/// </summary>
26+
/// <param name="degreesLatitude"></param>
27+
/// <param name="degreesLongitude"></param>
28+
/// <param name="ellipsoidalHeight"></param>
29+
public LatitudeLongitude(double degreesLatitude, double degreesLongitude, double ellipsoidalHeight)
30+
{
31+
Latitude = degreesLatitude;
32+
Longitude = degreesLongitude;
33+
EllipsoidalHeight = ellipsoidalHeight;
34+
}
35+
36+
/// <summary>
37+
/// Returns latitude in degrees.
38+
/// </summary>
39+
public double Latitude { get; }
40+
41+
/// <summary>
42+
/// Returns longitude in degrees.
43+
/// </summary>
44+
public double Longitude { get; }
45+
46+
/// <summary>
47+
/// returns ellipsoidal height in meters.
48+
/// </summary>
49+
public double EllipsoidalHeight { get; }
50+
51+
/// <summary>
52+
/// Creates a <see cref="LatitudeLongitude"/> object from easting and northing coordinates.
53+
/// </summary>
54+
/// <param name="easting">The easting coordinate in meters.</param>
55+
/// <param name="northing">The northing coordinate in meters.</param>
56+
/// <returns>A <see cref="LatitudeLongitude"/> object representing the converted coordinates.</returns>
57+
public static LatitudeLongitude FromEastingNorthing(double easting, double northing)
58+
{
59+
// Convert to Cartesian
60+
Cartesian cartesian = Convert.ToCartesian(new Airy1830(),
61+
new BritishNationalGrid(),
62+
new EastingNorthing(easting, northing));
63+
64+
// ETRS89 is effectively WGS84
65+
Cartesian wgsCartesian = Transform.Osgb36ToEtrs89(cartesian);
66+
67+
return Convert.ToLatitudeLongitude(new Wgs84(), wgsCartesian);
68+
}
69+
}
5070
}

0 commit comments

Comments
 (0)