2018-08-29 20:54:42 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2025-01-01 18:57:55 +01:00
|
|
|
|
// Copyright © Clemens Fischer
|
2018-08-29 20:54:42 +02:00
|
|
|
|
// 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;
|
2018-08-29 20:54:42 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl.Projections
|
|
|
|
|
|
{
|
2022-12-14 18:02:19 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// WGS84 UTM Projection with zone number and north/south flag.
|
|
|
|
|
|
/// </summary>
|
2022-01-23 14:02:04 +01:00
|
|
|
|
public class Wgs84UtmProjection : GeoApiProjection
|
2018-08-29 20:54:42 +02:00
|
|
|
|
{
|
2022-12-14 18:02:19 +01:00
|
|
|
|
public const int FirstZone = 1;
|
|
|
|
|
|
public const int LastZone = 60;
|
|
|
|
|
|
public const int FirstZoneNorthEpsgCode = 32600 + FirstZone;
|
|
|
|
|
|
public const int LastZoneNorthEpsgCode = 32600 + LastZone;
|
|
|
|
|
|
public const int FirstZoneSouthEpsgCode = 32700 + FirstZone;
|
|
|
|
|
|
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
|
|
|
|
|
|
|
|
|
|
|
public int Zone { get; private set; }
|
|
|
|
|
|
public bool IsNorth { get; private set; }
|
|
|
|
|
|
|
2022-01-23 14:02:04 +01:00
|
|
|
|
public Wgs84UtmProjection(int zone, bool north)
|
2018-10-03 11:27:55 +02:00
|
|
|
|
{
|
2022-12-14 18:02:19 +01:00
|
|
|
|
SetZone(zone, north);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void SetZone(int zone, bool north)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (zone < FirstZone || zone > LastZone)
|
2022-01-21 00:17:01 +01:00
|
|
|
|
{
|
2022-12-14 18:02:19 +01:00
|
|
|
|
throw new ArgumentException($"Invalid WGS84 UTM zone {zone}.", nameof(zone));
|
2022-01-21 00:17:01 +01:00
|
|
|
|
}
|
2018-10-03 11:27:55 +02:00
|
|
|
|
|
2022-12-14 18:02:19 +01:00
|
|
|
|
Zone = zone;
|
|
|
|
|
|
IsNorth = north;
|
|
|
|
|
|
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, IsNorth);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// WGS84 UTM Projection with automatic zone selection from projection center.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
|
|
|
|
|
|
{
|
2024-07-12 13:57:27 +02:00
|
|
|
|
private readonly string autoCrsId;
|
|
|
|
|
|
|
2024-09-10 22:04:44 +02:00
|
|
|
|
public Wgs84AutoUtmProjection(string crsId = MapControl.Wgs84AutoUtmProjection.DefaultCrsId)
|
2024-07-12 13:57:27 +02:00
|
|
|
|
: base(31, true)
|
2022-12-14 18:02:19 +01:00
|
|
|
|
{
|
2024-07-12 13:57:27 +02:00
|
|
|
|
autoCrsId = crsId;
|
2022-12-14 18:02:19 +01:00
|
|
|
|
|
2024-07-12 13:57:27 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(autoCrsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
CrsId = autoCrsId;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-14 18:02:19 +01:00
|
|
|
|
|
|
|
|
|
|
public override Location Center
|
|
|
|
|
|
{
|
|
|
|
|
|
get => base.Center;
|
2024-07-12 13:57:27 +02:00
|
|
|
|
protected set
|
2022-12-14 18:02:19 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (!Equals(base.Center, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Center = value;
|
|
|
|
|
|
|
2024-07-12 13:57:27 +02:00
|
|
|
|
var lon = Location.NormalizeLongitude(value.Longitude);
|
|
|
|
|
|
var zone = (int)Math.Floor(lon / 6d) + 31;
|
|
|
|
|
|
var north = value.Latitude >= 0d;
|
2022-12-14 18:02:19 +01:00
|
|
|
|
|
2024-07-12 13:57:27 +02:00
|
|
|
|
if (Zone != zone || IsNorth != north)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetZone(zone, north);
|
2022-12-14 18:02:19 +01:00
|
|
|
|
|
2024-07-12 13:57:27 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(autoCrsId))
|
|
|
|
|
|
{
|
|
|
|
|
|
CrsId = autoCrsId;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-14 18:02:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-10-03 11:27:55 +02:00
|
|
|
|
}
|
2018-08-29 20:54:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|