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>
|
2022-02-23 23:19:32 +01:00
|
|
|
|
/// Spherical Orthographic Projection - AUTO2:42003.
|
2025-02-24 11:22:17 +01:00
|
|
|
|
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.148-150.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
2026-01-19 21:38:18 +01:00
|
|
|
|
public class OrthographicProjection : AzimuthalProjection
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2022-01-19 16:43:00 +01:00
|
|
|
|
public const string DefaultCrsId = "AUTO2:42003";
|
|
|
|
|
|
|
2026-01-10 23:29:42 +01:00
|
|
|
|
public OrthographicProjection() // parameterless constructor for XAML
|
2024-08-28 14:58:06 +02:00
|
|
|
|
: this(DefaultCrsId)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OrthographicProjection(string crsId)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2024-07-12 13:57:27 +02:00
|
|
|
|
CrsId = crsId;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
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-20 15:48:30 +01:00
|
|
|
|
var p = GetProjectedPoint(latitude, longitude);
|
|
|
|
|
|
var h = p.CosC; // p.149 (20-5)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2026-01-20 10:24:26 +01:00
|
|
|
|
var scale = new Matrix(h, 0d, 0d, 1d, 0d, 0d);
|
2026-01-20 15:48:30 +01:00
|
|
|
|
scale.Rotate(-Math.Atan2(p.Y, p.X) * 180d / Math.PI);
|
2026-01-20 09:48:16 +01:00
|
|
|
|
return scale;
|
2026-01-19 21:38:18 +01:00
|
|
|
|
}
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2026-01-19 21:38:18 +01:00
|
|
|
|
public override Point? LocationToMap(double latitude, double longitude)
|
|
|
|
|
|
{
|
2026-01-20 15:48:30 +01:00
|
|
|
|
var p = GetProjectedPoint(latitude, longitude);
|
2022-03-04 22:28:18 +01:00
|
|
|
|
|
2026-01-20 15:48:30 +01:00
|
|
|
|
return p.CosC >= 0d ? new Point(EarthRadius * p.X, EarthRadius * p.Y) : null; // p.149 (20-3/4)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 21:28:45 +01:00
|
|
|
|
public override Location MapToLocation(double x, double y)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2026-01-19 21:38:18 +01:00
|
|
|
|
var rho = Math.Sqrt(x * x + y * y);
|
|
|
|
|
|
var sinC = rho / EarthRadius; // p.150 (20-19)
|
2026-01-13 23:24:48 +01:00
|
|
|
|
|
2026-01-19 21:38:18 +01:00
|
|
|
|
return sinC <= 1d ? GetLocation(x, y, rho, sinC) : null;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|