XAML-Map-Control/MapProjections/Shared/UtmProjection.cs

35 lines
961 B
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
2018-12-20 21:55:12 +01:00
using ProjNet.CoordinateSystems;
2022-01-21 00:17:01 +01:00
using System;
namespace MapControl.Projections
{
public class UtmProjection : GeoApiProjection
{
2022-01-21 00:17:01 +01:00
public UtmProjection(int zone, bool north)
2022-01-19 23:40:05 +01:00
{
2022-01-21 00:17:01 +01:00
SetZone(zone, north);
2022-01-19 23:40:05 +01:00
}
public UtmProjection(Location location)
{
2022-01-21 16:55:00 +01:00
var zone = Math.Min((int)Math.Floor(Location.NormalizeLongitude(location.Longitude) + 180d) / 6 + 1, 60);
2022-01-21 16:55:00 +01:00
SetZone(zone, location.Latitude >= 0d);
}
2022-01-21 16:55:00 +01:00
protected void SetZone(int zone, bool north)
{
2022-01-21 00:17:01 +01:00
if (zone < 1 || zone > 60)
{
throw new ArgumentException("Invalid UTM zone number.", nameof(zone));
}
2022-01-21 00:17:01 +01:00
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(zone, north);
}
}
}