mirror of
https://github.com/IeuanWalker/GeoUK.git
synced 2025-10-25 15:19:15 +00:00
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>
This commit is contained in:
@@ -1,50 +1,70 @@
|
||||
using GeoUK.Ellipsoids;
|
||||
using GeoUK.Projections;
|
||||
|
||||
namespace GeoUK.Coordinates
|
||||
{
|
||||
/// <summary>
|
||||
/// This immutable class represents a set of latitude/longitude/ellipsoidal height coordinates.
|
||||
/// </summary>
|
||||
public class LatitudeLongitude
|
||||
/// <summary>
|
||||
/// This immutable class represents a set of latitude/longitude/ellipsoidal height coordinates.
|
||||
/// </summary>
|
||||
public class LatitudeLongitude
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="degreesLatitude"></param>
|
||||
/// <param name="degreesLongitude"></param>
|
||||
public LatitudeLongitude(double degreesLatitude, double degreesLongitude)
|
||||
{
|
||||
Latitude = degreesLatitude;
|
||||
Longitude = degreesLongitude;
|
||||
EllipsoidalHeight = 0.0;
|
||||
}
|
||||
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="degreesLatitude"></param>
|
||||
/// <param name="degreesLongitude"></param>
|
||||
/// <param name="ellipsoidalHeight"></param>
|
||||
public LatitudeLongitude(double degreesLatitude, double degreesLongitude, double ellipsoidalHeight)
|
||||
{
|
||||
Latitude = degreesLatitude;
|
||||
Longitude = degreesLongitude;
|
||||
EllipsoidalHeight = ellipsoidalHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="degreesLatitude"></param>
|
||||
/// <param name="degreesLongitude"></param>
|
||||
public LatitudeLongitude(double degreesLatitude, double degreesLongitude)
|
||||
{
|
||||
Latitude = degreesLatitude;
|
||||
Longitude = degreesLongitude;
|
||||
EllipsoidalHeight = 0.0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns latitude in degrees.
|
||||
/// </summary>
|
||||
public double Latitude { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="degreesLatitude"></param>
|
||||
/// <param name="degreesLongitude"></param>
|
||||
/// <param name="ellipsoidalHeight"></param>
|
||||
public LatitudeLongitude(double degreesLatitude, double degreesLongitude, double ellipsoidalHeight)
|
||||
{
|
||||
Latitude = degreesLatitude;
|
||||
Longitude = degreesLongitude;
|
||||
EllipsoidalHeight = ellipsoidalHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns longitude in degrees.
|
||||
/// </summary>
|
||||
public double Longitude { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns latitude in degrees.
|
||||
/// </summary>
|
||||
public double Latitude { get; }
|
||||
/// <summary>
|
||||
/// returns ellipsoidal height in meters.
|
||||
/// </summary>
|
||||
public double EllipsoidalHeight { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns longitude in degrees.
|
||||
/// </summary>
|
||||
public double Longitude { get; }
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LatitudeLongitude"/> object from easting and northing coordinates.
|
||||
/// </summary>
|
||||
/// <param name="easting">The easting coordinate in meters.</param>
|
||||
/// <param name="northing">The northing coordinate in meters.</param>
|
||||
/// <returns>A <see cref="LatitudeLongitude"/> object representing the converted coordinates.</returns>
|
||||
public static LatitudeLongitude FromEastingNorthing(double easting, double northing)
|
||||
{
|
||||
// Convert to Cartesian
|
||||
Cartesian cartesian = Convert.ToCartesian(new Airy1830(),
|
||||
new BritishNationalGrid(),
|
||||
new EastingNorthing(easting, northing));
|
||||
|
||||
/// <summary>
|
||||
/// returns ellipsoidal height in meters.
|
||||
/// </summary>
|
||||
public double EllipsoidalHeight { get; }
|
||||
}
|
||||
// ETRS89 is effectively WGS84
|
||||
Cartesian wgsCartesian = Transform.Osgb36ToEtrs89(cartesian);
|
||||
|
||||
return Convert.ToLatitudeLongitude(new Wgs84(), wgsCartesian);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user