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

58 lines
1.6 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if !WINDOWS_UWP
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
2018-12-20 21:55:12 +01:00
/// Spherical Stereographic Projection.
/// </summary>
public class StereographicProjection : AzimuthalProjection
{
public StereographicProjection()
: this("AUTO2:97002") // GeoServer non-standard CRS ID
{
}
public StereographicProjection(string crsId)
{
CrsId = crsId;
}
public override Point LocationToPoint(Location location)
{
2017-08-16 21:27:12 +02:00
if (location.Equals(ProjectionCenter))
{
return new Point();
}
double azimuth, distance;
2017-08-16 21:27:12 +02:00
GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
2018-12-20 21:55:12 +01:00
var mapDistance = Math.Tan(distance / 2d) * TrueScale * 360d / Math.PI;
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth));
}
public override Location PointToLocation(Point point)
{
if (point.X == 0d && point.Y == 0d)
{
2017-08-16 21:27:12 +02:00
return ProjectionCenter;
}
var azimuth = Math.Atan2(point.X, point.Y);
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
2018-12-20 21:55:12 +01:00
var distance = 2d * Math.Atan(mapDistance / (TrueScale * 360d / Math.PI));
2017-08-16 21:27:12 +02:00
return GetLocation(ProjectionCenter, azimuth, distance);
}
}
}