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

55 lines
1.7 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2021-11-17 23:17:11 +01:00
#if !WINUI && !UWP
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Spherical Stereographic Projection - AUTO2:97002.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.157-160.
/// </summary>
public class StereographicProjection : AzimuthalProjection
{
2022-01-19 16:43:00 +01:00
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
public StereographicProjection()
{
2022-01-19 16:43:00 +01:00
CrsId = DefaultCrsId;
}
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 = Math.Tan(distance / 2d) * 2d * Wgs84EquatorialRadius;
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 = 2d * Math.Atan(mapDistance / (2d * Wgs84EquatorialRadius));
return GetLocation(Center, azimuth, distance);
}
}
}