XAML-Map-Control/MapControl/Shared/StereographicProjection.cs

53 lines
1.6 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
2024-05-22 11:25:32 +02:00
#if WPF
using System.Windows;
2025-08-19 19:43:02 +02:00
#elif AVALONIA
using Avalonia;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Spherical Stereographic Projection - AUTO2:97002.
2025-02-24 11:22:17 +01:00
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.157-160.
/// </summary>
2026-01-19 21:38:18 +01:00
public class StereographicProjection : AzimuthalProjection
{
2026-01-10 22:48:14 +01:00
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS identifier
2022-01-19 16:43:00 +01:00
2026-01-10 23:29:42 +01:00
public StereographicProjection() // parameterless constructor for XAML
: this(DefaultCrsId)
{
}
public StereographicProjection(string crsId)
{
2024-07-12 13:57:27 +02:00
CrsId = crsId;
}
2026-01-19 21:38:18 +01:00
public override Point RelativeScale(double latitude, double longitude)
{
2026-01-19 21:38:18 +01:00
(var cosC, var _, var _) = GetPointValues(latitude, longitude);
var k = 2d / (1d + cosC); // p.157 (21-4), k0 == 1
2026-01-19 21:38:18 +01:00
return new Point(k, k);
}
2026-01-19 21:38:18 +01:00
public override Point? LocationToMap(double latitude, double longitude)
{
(var cosC, var x, var y) = GetPointValues(latitude, longitude);
var k = 2d / (1d + cosC); // p.157 (21-4), k0 == 1
2026-01-19 21:38:18 +01:00
return new Point(EarthRadius * k * x, EarthRadius * k * y); // p.157 (21-2/3)
}
public override Location MapToLocation(double x, double y)
{
2026-01-19 21:38:18 +01:00
var rho = Math.Sqrt(x * x + y * y);
var c = 2d * Math.Atan(rho / (2d * EarthRadius)); // p.159 (21-15), k0 == 1
2026-01-19 21:38:18 +01:00
return GetLocation(x, y, rho, Math.Sin(c));
}
}
}