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

51 lines
1.4 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
/// Equirectangular Projection - EPSG:4326.
/// Equidistant cylindrical projection with zero standard parallel and central meridian.
2025-02-24 11:22:17 +01:00
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.90-91.
/// </summary>
public class EquirectangularProjection : MapProjection
{
2024-07-12 14:14:42 +02:00
public const string DefaultCrsId = "EPSG:4326";
2022-01-19 16:43:00 +01:00
public EquirectangularProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public EquirectangularProjection(string crsId)
{
2022-03-05 18:40:57 +01:00
Type = MapProjectionType.NormalCylindrical;
2024-07-12 13:57:27 +02:00
CrsId = crsId;
2020-04-16 23:15:03 +02:00
}
public override Point GetRelativeScale(Location location)
{
return new Point(
1d / Math.Cos(location.Latitude * Math.PI / 180d),
1d);
}
public override Point? LocationToMap(Location location)
{
return new Point(
2022-03-02 22:03:18 +01:00
Wgs84MeterPerDegree * location.Longitude,
Wgs84MeterPerDegree * location.Latitude);
}
public override Location MapToLocation(Point point)
{
return new Location(
2022-03-02 22:03:18 +01:00
point.Y / Wgs84MeterPerDegree,
point.X / Wgs84MeterPerDegree);
}
}
}