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

59 lines
1.7 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;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Spherical Gnomonic Projection - AUTO2:97001.
2025-02-24 11:22:17 +01:00
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.165-167.
/// </summary>
public class GnomonicProjection : AzimuthalProjection
{
2022-01-19 16:43:00 +01:00
public const string DefaultCrsId = "AUTO2:97001"; // GeoServer non-standard CRS ID
public GnomonicProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public GnomonicProjection(string crsId)
{
2024-07-12 13:57:27 +02:00
CrsId = crsId;
}
public override Point? LocationToMap(Location location)
{
if (location.Equals(Center))
{
return new Point();
}
2020-04-16 19:24:38 +02:00
GetAzimuthDistance(Center, location, out double azimuth, out double distance);
var mapDistance = distance < Math.PI / 2d
? Math.Tan(distance) * Wgs84EquatorialRadius
: double.PositiveInfinity;
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth));
}
public override Location MapToLocation(Point point)
{
if (point.X == 0d && point.Y == 0d)
{
return new Location(Center.Latitude, Center.Longitude);
}
var azimuth = Math.Atan2(point.X, point.Y);
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
var distance = Math.Atan(mapDistance / Wgs84EquatorialRadius);
return GetLocation(Center, azimuth, distance);
}
}
}