mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Unified map projections
This commit is contained in:
parent
a4bd11e26d
commit
9fe7dccd68
21 changed files with 370 additions and 377 deletions
|
|
@ -14,7 +14,7 @@ namespace MapControl
|
|||
|
||||
public int Zone { get; }
|
||||
|
||||
public Etrs89UtmProjection(int zone)
|
||||
public Etrs89UtmProjection(int zone) : base(zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
|
|
@ -27,7 +27,6 @@ namespace MapControl
|
|||
// GRS 1980
|
||||
EquatorialRadius = 6378137d;
|
||||
Flattening = 1d / 298.257222101;
|
||||
CentralMeridian = zone * 6d - 183d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,16 +43,15 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public string CrsId { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the projection is normal cylindrical, see
|
||||
/// https://en.wikipedia.org/wiki/Map_projection#Normal_cylindrical.
|
||||
/// </summary>
|
||||
public double EquatorialRadius { get; protected set; } = Wgs84EquatorialRadius;
|
||||
public double Flattening { get; protected set; } = Wgs84Flattening;
|
||||
public double ScaleFactor { get; protected set; } = 1d;
|
||||
public double CentralMeridian { get; protected set; }
|
||||
public double LatitudeOfOrigin { get; protected set; }
|
||||
public double FalseEasting { get; protected set; }
|
||||
public double FalseNorthing { get; protected set; }
|
||||
public bool IsNormalCylindrical { get; protected set; }
|
||||
|
||||
public double EquatorialRadius { get; set; } = Wgs84EquatorialRadius;
|
||||
public double CentralMeridian { get; set; }
|
||||
public double LatitudeOfOrigin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the grid convergence angle in degrees at the specified geographic coordinates.
|
||||
/// Used for rotating the Rect resulting from BoundingBoxToMap in non-normal-cylindrical
|
||||
|
|
@ -64,7 +63,12 @@ namespace MapControl
|
|||
/// Gets the relative transform at the specified geographic coordinates.
|
||||
/// The returned Matrix represents the local relative scale and rotation.
|
||||
/// </summary>
|
||||
public abstract Matrix RelativeTransform(double latitude, double longitude);
|
||||
public virtual Matrix RelativeTransform(double latitude, double longitude)
|
||||
{
|
||||
var transform = new Matrix(ScaleFactor, 0d, 0d, ScaleFactor, 0d, 0d);
|
||||
transform.Rotate(-GridConvergence(latitude, longitude));
|
||||
return transform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms geographic coordinates to a Point in projected map coordinates.
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ namespace MapControl
|
|||
var c when c is >= Nad83UtmProjection.FirstZoneEpsgCode
|
||||
and <= Nad83UtmProjection.LastZoneEpsgCode => new Nad83UtmProjection(c % 100),
|
||||
var c when c is >= Wgs84UtmProjection.FirstZoneNorthEpsgCode
|
||||
and <= Wgs84UtmProjection.LastZoneNorthEpsgCode => new Wgs84UtmProjection(c % 100, Hemisphere.North),
|
||||
and <= Wgs84UtmProjection.LastZoneNorthEpsgCode => new Wgs84UtmProjection(c % 100, true),
|
||||
var c when c is >= Wgs84UtmProjection.FirstZoneSouthEpsgCode
|
||||
and <= Wgs84UtmProjection.LastZoneSouthEpsgCode => new Wgs84UtmProjection(c % 100, Hemisphere.South),
|
||||
and <= Wgs84UtmProjection.LastZoneSouthEpsgCode => new Wgs84UtmProjection(c % 100, false),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace MapControl
|
|||
|
||||
public int Zone { get; }
|
||||
|
||||
public Nad27UtmProjection(int zone)
|
||||
public Nad27UtmProjection(int zone) : base(zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
|
|
@ -27,7 +27,6 @@ namespace MapControl
|
|||
// Clarke 1866
|
||||
EquatorialRadius = 6378206.4;
|
||||
Flattening = 1d / 294.978698213898;
|
||||
CentralMeridian = zone * 6d - 183d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace MapControl
|
|||
|
||||
public int Zone { get; }
|
||||
|
||||
public Nad83UtmProjection(int zone)
|
||||
public Nad83UtmProjection(int zone) : base(zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
|
|
@ -27,7 +27,6 @@ namespace MapControl
|
|||
// GRS 1980
|
||||
EquatorialRadius = 6378137d;
|
||||
Flattening = 1d / 298.257222101;
|
||||
CentralMeridian = zone * 6d - 183d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,13 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class PolarStereographicProjection : MapProjection
|
||||
{
|
||||
public double Flattening { get; set; } = Wgs84Flattening;
|
||||
public double ScaleFactor { get; set; } = 0.994;
|
||||
public double FalseEasting { get; set; } = 2e6;
|
||||
public double FalseNorthing { get; set; } = 2e6;
|
||||
public PolarStereographicProjection(bool north)
|
||||
{
|
||||
LatitudeOfOrigin = north ? 90d : -90d;
|
||||
ScaleFactor = 0.994;
|
||||
FalseEasting = 2e6;
|
||||
FalseNorthing = 2e6;
|
||||
}
|
||||
|
||||
public override double GridConvergence(double latitude, double longitude)
|
||||
{
|
||||
|
|
@ -29,20 +32,17 @@ namespace MapControl
|
|||
{
|
||||
var sign = Math.Sign(LatitudeOfOrigin);
|
||||
var phi = sign * latitude * Math.PI / 180d;
|
||||
|
||||
var e = Math.Sqrt((2d - Flattening) * Flattening);
|
||||
var eSinPhi = e * Math.Sin(phi);
|
||||
|
||||
var t = Math.Tan(Math.PI / 4d - phi / 2d)
|
||||
/ Math.Pow((1d - eSinPhi) / (1d + eSinPhi), e / 2d); // p.161 (15-9)
|
||||
|
||||
// r == ρ/a
|
||||
var r = 2d * ScaleFactor * t / Math.Sqrt(Math.Pow(1d + e, 1d + e) * Math.Pow(1d - e, 1d - e)); // p.161 (21-33)
|
||||
var m = Math.Cos(phi) / Math.Sqrt(1d - eSinPhi * eSinPhi); // p.160 (14-15)
|
||||
var k = r / m; // p.161 (21-32)
|
||||
|
||||
var transform = new Matrix(k, 0d, 0d, k, 0d, 0d);
|
||||
transform.Rotate(-sign * longitude);
|
||||
transform.Rotate(-sign * (longitude - CentralMeridian));
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
|
@ -99,10 +99,9 @@ namespace MapControl
|
|||
{
|
||||
}
|
||||
|
||||
public Wgs84UpsNorthProjection(string crsId)
|
||||
public Wgs84UpsNorthProjection(string crsId) : base(true)
|
||||
{
|
||||
CrsId = crsId;
|
||||
LatitudeOfOrigin = 90d;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,10 +117,9 @@ namespace MapControl
|
|||
{
|
||||
}
|
||||
|
||||
public Wgs84UpsSouthProjection(string crsId)
|
||||
public Wgs84UpsSouthProjection(string crsId) : base(false)
|
||||
{
|
||||
CrsId = crsId;
|
||||
LatitudeOfOrigin = -90d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace MapControl
|
|||
"{0},1,{1:0.########},{2:0.########}", crsId, centerLongitude, centerLatitude);
|
||||
}
|
||||
|
||||
public override double GridConvergence(double latitude, double longitude)
|
||||
private void GetScaleAndGridConvergence(double latitude, double longitude, out double scale, out double gamma)
|
||||
{
|
||||
var phi0 = LatitudeOfOrigin * Math.PI / 180d; // φ1
|
||||
var phi1 = latitude * Math.PI / 180d;
|
||||
|
|
@ -44,13 +44,26 @@ namespace MapControl
|
|||
var dCosPhi = k2 * cosPhi2 - k1 * cosPhi1;
|
||||
var dSinPhi = k2 * sinPhi2 - k1 * sinPhi1;
|
||||
|
||||
return Math.Atan2(-sinLambda * dCosPhi,
|
||||
scale = k1;
|
||||
gamma = Math.Atan2(-sinLambda * dCosPhi,
|
||||
cosPhi0 * dSinPhi - sinPhi0 * cosLambda * dCosPhi) * 180d / Math.PI;
|
||||
}
|
||||
|
||||
public override double GridConvergence(double latitude, double longitude)
|
||||
{
|
||||
GetScaleAndGridConvergence(latitude, longitude, out double _, out double gamma);
|
||||
|
||||
return gamma;
|
||||
}
|
||||
|
||||
public override Matrix RelativeTransform(double latitude, double longitude)
|
||||
{
|
||||
return new Matrix(1d, 0d, 0d, 1d, 0d, 0d);
|
||||
GetScaleAndGridConvergence(latitude, longitude, out double scale, out double gamma);
|
||||
|
||||
var transform = new Matrix(scale, 0d, 0d, scale, 0d, 0d);
|
||||
transform.Rotate(-gamma);
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
public override Point LocationToMap(double latitude, double longitude)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class TransverseMercatorProjection : MapProjection
|
||||
{
|
||||
private double f;
|
||||
private double n;
|
||||
private double a1; // α1
|
||||
private double a2; // α2
|
||||
private double a3; // α3
|
||||
|
|
@ -28,38 +30,36 @@ namespace MapControl
|
|||
private double f1; // A/a
|
||||
private double f2; // 2*sqrt(n)/(1+n)
|
||||
|
||||
private void InitializeParameters()
|
||||
{
|
||||
f = Flattening;
|
||||
n = f / (2d - f);
|
||||
var n2 = n * n;
|
||||
var n3 = n * n2;
|
||||
a1 = n / 2d - n2 * 2d / 3d + n3 * 5d / 16d;
|
||||
a2 = n2 * 13d / 48d - n3 * 3d / 5d;
|
||||
a3 = n3 * 61d / 240d;
|
||||
b1 = n / 2d - n2 * 2d / 3d + n3 * 37d / 96d;
|
||||
b2 = n2 / 48d + n3 / 15d;
|
||||
b3 = n3 * 17d / 480d;
|
||||
d1 = n * 2d - n2 * 2d / 3d - n3 * 2d;
|
||||
d2 = n2 * 7d / 3d - n3 * 8d / 5d;
|
||||
d3 = n3 * 56d / 15d;
|
||||
f1 = (1d + n2 / 4d + n2 * n2 / 64d) / (1d + n);
|
||||
f2 = 2d * Math.Sqrt(n) / (1d + n);
|
||||
}
|
||||
|
||||
public TransverseMercatorProjection()
|
||||
{
|
||||
Flattening = Wgs84Flattening;
|
||||
}
|
||||
|
||||
public double Flattening
|
||||
public TransverseMercatorProjection(int utmZone) : this()
|
||||
{
|
||||
get;
|
||||
set
|
||||
{
|
||||
field = value;
|
||||
var n = field / (2d - field);
|
||||
var n2 = n * n;
|
||||
var n3 = n * n2;
|
||||
a1 = n / 2d - n2 * 2d / 3d + n3 * 5d / 16d;
|
||||
a2 = n2 * 13d / 48d - n3 * 3d / 5d;
|
||||
a3 = n3 * 61d / 240d;
|
||||
b1 = n / 2d - n2 * 2d / 3d + n3 * 37d / 96d;
|
||||
b2 = n2 / 48d + n3 / 15d;
|
||||
b3 = n3 * 17d / 480d;
|
||||
d1 = n * 2d - n2 * 2d / 3d - n3 * 2d;
|
||||
d2 = n2 * 7d / 3d - n3 * 8d / 5d;
|
||||
d3 = n3 * 56d / 15d;
|
||||
f1 = (1d + n2 / 4d + n2 * n2 / 64d) / (1d + n);
|
||||
f2 = 2d * Math.Sqrt(n) / (1d + n);
|
||||
}
|
||||
CentralMeridian = utmZone * 6d - 183d;
|
||||
ScaleFactor = 0.9996;
|
||||
FalseEasting = 5e5;
|
||||
}
|
||||
|
||||
public double ScaleFactor { get; set; } = 0.9996;
|
||||
public double FalseEasting { get; set; } = 5e5;
|
||||
public double FalseNorthing { get; set; }
|
||||
|
||||
public override double GridConvergence(double latitude, double longitude)
|
||||
{
|
||||
// φ
|
||||
|
|
@ -74,6 +74,11 @@ namespace MapControl
|
|||
|
||||
public override Matrix RelativeTransform(double latitude, double longitude)
|
||||
{
|
||||
if (f != Flattening)
|
||||
{
|
||||
InitializeParameters();
|
||||
}
|
||||
|
||||
// φ
|
||||
var phi = latitude * Math.PI / 180d;
|
||||
var sinPhi = Math.Sin(phi);
|
||||
|
|
@ -99,7 +104,6 @@ namespace MapControl
|
|||
4d * a2 * Math.Sin(4d * xi_) * Math.Sinh(4d * eta_) +
|
||||
6d * a3 * Math.Sin(6d * xi_) * Math.Sinh(6d * eta_);
|
||||
|
||||
var n = Flattening / (2d - Flattening);
|
||||
var m = (1d - n) / (1d + n) * Math.Tan(phi);
|
||||
var k = ScaleFactor * f1 * Math.Sqrt((1d + m * m) * (sigma * sigma + tau * tau) / (t * t + cosLambda * cosLambda));
|
||||
|
||||
|
|
@ -114,6 +118,11 @@ namespace MapControl
|
|||
|
||||
public override Point LocationToMap(double latitude, double longitude)
|
||||
{
|
||||
if (f != Flattening)
|
||||
{
|
||||
InitializeParameters();
|
||||
}
|
||||
|
||||
// φ
|
||||
var phi = latitude * Math.PI / 180d;
|
||||
var sinPhi = Math.Sin(phi);
|
||||
|
|
@ -143,6 +152,11 @@ namespace MapControl
|
|||
|
||||
public override Location MapToLocation(double x, double y)
|
||||
{
|
||||
if (f != Flattening)
|
||||
{
|
||||
InitializeParameters();
|
||||
}
|
||||
|
||||
// k0 * A
|
||||
var k0A = ScaleFactor * EquatorialRadius * f1;
|
||||
// ξ
|
||||
|
|
|
|||
|
|
@ -15,10 +15,16 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class TransverseMercatorProjectionSnyder : MapProjection
|
||||
{
|
||||
public double Flattening { get; set; } = Wgs84Flattening;
|
||||
public double ScaleFactor { get; set; } = 0.9996;
|
||||
public double FalseEasting { get; set; } = 5e5;
|
||||
public double FalseNorthing { get; set; }
|
||||
public TransverseMercatorProjectionSnyder()
|
||||
{
|
||||
}
|
||||
|
||||
public TransverseMercatorProjectionSnyder(int utmZone) : this()
|
||||
{
|
||||
CentralMeridian = utmZone * 6d - 183d;
|
||||
ScaleFactor = 0.9996;
|
||||
FalseEasting = 5e5;
|
||||
}
|
||||
|
||||
public override double GridConvergence(double latitude, double longitude)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,12 +2,6 @@
|
|||
|
||||
namespace MapControl
|
||||
{
|
||||
public enum Hemisphere
|
||||
{
|
||||
North,
|
||||
South
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WGS84 Universal Transverse Mercator Projection -
|
||||
/// EPSG:32601 to EPSG:32660 and EPSG:32701 to EPSG:32760.
|
||||
|
|
@ -22,9 +16,8 @@ namespace MapControl
|
|||
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
||||
|
||||
public int Zone { get; }
|
||||
public Hemisphere Hemisphere { get; }
|
||||
|
||||
public Wgs84UtmProjection(int zone, Hemisphere hemisphere)
|
||||
public Wgs84UtmProjection(int zone, bool north) : base(zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
|
|
@ -32,10 +25,8 @@ namespace MapControl
|
|||
}
|
||||
|
||||
Zone = zone;
|
||||
Hemisphere = hemisphere;
|
||||
CrsId = $"EPSG:{(hemisphere == Hemisphere.North ? 32600 : 32700) + zone}";
|
||||
CentralMeridian = zone * 6d - 183d;
|
||||
FalseNorthing = hemisphere == Hemisphere.North ? 0d : 1e7;
|
||||
CrsId = $"EPSG:{(north ? 32600 : 32700) + zone}";
|
||||
FalseNorthing = north ? 0d : 1e7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ namespace MapControl
|
|||
{
|
||||
public const string DefaultCrsId = "EPSG:3395";
|
||||
|
||||
public double Flattening { get; set; } = Wgs84Flattening;
|
||||
|
||||
public WorldMercatorProjection() // parameterless constructor for XAML
|
||||
: this(DefaultCrsId)
|
||||
{
|
||||
|
|
@ -31,8 +29,8 @@ namespace MapControl
|
|||
|
||||
public override Matrix RelativeTransform(double latitude, double longitude)
|
||||
{
|
||||
var phi = latitude * Math.PI / 180d;
|
||||
var e2 = (2d - Flattening) * Flattening;
|
||||
var phi = latitude * Math.PI / 180d;
|
||||
var sinPhi = Math.Sin(phi);
|
||||
var k = Math.Sqrt(1d - e2 * sinPhi * sinPhi) / Math.Cos(phi); // p.44 (7-8)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue