XAML-Map-Control/MapControl/Shared/StereographicProjection.cs
2026-01-19 21:38:18 +01:00

53 lines
1.6 KiB
C#

using System;
#if WPF
using System.Windows;
#elif AVALONIA
using Avalonia;
#endif
namespace MapControl
{
/// <summary>
/// Spherical Stereographic Projection - AUTO2:97002.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.157-160.
/// </summary>
public class StereographicProjection : AzimuthalProjection
{
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS identifier
public StereographicProjection() // parameterless constructor for XAML
: this(DefaultCrsId)
{
}
public StereographicProjection(string crsId)
{
CrsId = crsId;
}
public override Point RelativeScale(double latitude, double longitude)
{
(var cosC, var _, var _) = GetPointValues(latitude, longitude);
var k = 2d / (1d + cosC); // p.157 (21-4), k0 == 1
return new Point(k, k);
}
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
return new Point(EarthRadius * k * x, EarthRadius * k * y); // p.157 (21-2/3)
}
public override Location MapToLocation(double x, double y)
{
var rho = Math.Sqrt(x * x + y * y);
var c = 2d * Math.Atan(rho / (2d * EarthRadius)); // p.159 (21-15), k0 == 1
return GetLocation(x, y, rho, Math.Sin(c));
}
}
}