2025-02-27 18:46:32 +01:00
|
|
|
|
using System;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#if WPF
|
2017-06-25 23:05:48 +02:00
|
|
|
|
using System.Windows;
|
2026-01-20 09:48:16 +01:00
|
|
|
|
using System.Windows.Media;
|
2025-08-19 19:43:02 +02:00
|
|
|
|
#elif AVALONIA
|
|
|
|
|
|
using Avalonia;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2026-01-10 22:48:14 +01:00
|
|
|
|
/// Spherical Azimuthal Equidistant Projection - No standard CRS identifier.
|
2025-02-24 11:22:17 +01:00
|
|
|
|
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.195-197.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
2026-01-19 21:38:18 +01:00
|
|
|
|
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-10 22:48:14 +01:00
|
|
|
|
public const string DefaultCrsId = "AUTO2:97003"; // proprietary CRS identifier
|
2024-07-12 13:57:27 +02:00
|
|
|
|
|
2026-01-10 23:29:42 +01:00
|
|
|
|
public AzimuthalEquidistantProjection() // parameterless constructor for XAML
|
2024-08-28 14:58:06 +02:00
|
|
|
|
: this(DefaultCrsId)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AzimuthalEquidistantProjection(string crsId)
|
2022-03-05 18:40:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
CrsId = crsId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 09:48:16 +01:00
|
|
|
|
public override Matrix RelativeScale(double latitude, double longitude)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-19 21:38:18 +01:00
|
|
|
|
(var cosC, var _, var _) = GetPointValues(latitude, longitude);
|
|
|
|
|
|
var k = 1d;
|
|
|
|
|
|
|
|
|
|
|
|
if (cosC < 1d)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-19 21:38:18 +01:00
|
|
|
|
var c = Math.Acos(cosC);
|
|
|
|
|
|
k = c / Math.Sin(c); // p.195 (25-2)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-20 09:48:16 +01:00
|
|
|
|
return new Matrix(k, 0d, 0d, k, 0d, 0d);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 21:38:18 +01:00
|
|
|
|
public override Point? LocationToMap(double latitude, double longitude)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-19 21:38:18 +01:00
|
|
|
|
(var cosC, var x, var y) = GetPointValues(latitude, longitude);
|
|
|
|
|
|
var k = 1d;
|
|
|
|
|
|
|
|
|
|
|
|
if (cosC < 1d)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-19 21:38:18 +01:00
|
|
|
|
var c = Math.Acos(cosC);
|
|
|
|
|
|
k = c / Math.Sin(c); // p.195 (25-2)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 21:38:18 +01:00
|
|
|
|
return new Point(EarthRadius * k * x, EarthRadius * k * y); // p.195 (22-4/5)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Location MapToLocation(double x, double y)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rho = Math.Sqrt(x * x + y * y);
|
|
|
|
|
|
var c = rho / EarthRadius; // p.196 (25-15)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2026-01-19 21:38:18 +01:00
|
|
|
|
return GetLocation(x, y, rho, Math.Sin(c));
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|