Updated Auto-UTM projections

This commit is contained in:
ClemensFischer 2026-01-10 08:28:10 +01:00
parent 8630c6ed70
commit b16d2b8c9b
13 changed files with 132 additions and 98 deletions

View file

@ -3,7 +3,7 @@
namespace MapControl
{
/// <summary>
/// ETRS89 UTM Projection with zone number.
/// ETRS89 Universal Transverse Mercator Projection.
/// </summary>
public class Etrs89UtmProjection : TransverseMercatorProjection
{

View file

@ -33,7 +33,7 @@ namespace MapControl
break;
case Wgs84AutoUtmProjection.DefaultCrsId:
projection = new Wgs84AutoUtmProjection();
projection = new Wgs84AutoUtmProjection("");
break;
case Wgs84AutoTmProjection.DefaultCrsId:

View file

@ -3,7 +3,7 @@
namespace MapControl
{
/// <summary>
/// NAD27 UTM Projection with zone number.
/// NAD27 Universal Transverse Mercator Projection.
/// </summary>
public class Nad27UtmProjection : TransverseMercatorProjection
{

View file

@ -3,7 +3,7 @@
namespace MapControl
{
/// <summary>
/// NAD83 UTM Projection with zone number.
/// NAD83 Universal Transverse Mercator Projection.
/// </summary>
public class Nad83UtmProjection : TransverseMercatorProjection
{

View file

@ -9,7 +9,8 @@ namespace MapControl
{
/// <summary>
/// Transverse Mercator Projection.
/// See https://en.wikipedia.org/wiki/Transverse_Mercator_projection.
/// See https://en.wikipedia.org/wiki/Transverse_Mercator_projection
/// and https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system.
/// </summary>
public class TransverseMercatorProjection : MapProjection
{

View file

@ -0,0 +1,61 @@
using System;
namespace MapControl
{
/// <summary>
/// WGS84 Universal Transverse Mercator Projection with
/// automatic zone selection from projection center.
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
public const string DefaultCrsId = "AUTO2:42001";
private readonly string autoCrsId;
public Wgs84AutoUtmProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
/// <summary>
/// When the crsId parameter is null or empty, the projection will use EPSG:32***.
/// </summary>
public Wgs84AutoUtmProjection(string crsId)
: base(31, true)
{
autoCrsId = crsId;
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
public override Location Center
{
get => base.Center;
protected internal set
{
if (!base.Center.Equals(value))
{
base.Center = value;
var lon = Location.NormalizeLongitude(value.Longitude);
var zone = (int)Math.Floor(lon / 6d) + 31;
var north = value.Latitude >= 0d;
if (Zone != zone || IsNorth != north)
{
SetZone(zone, north);
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
}
}
}
}
}

View file

@ -3,8 +3,7 @@
namespace MapControl
{
/// <summary>
/// WGS84 UTM Projection with zone number and north/south flag.
/// See https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system.
/// WGS84 Universal Transverse Mercator Projection.
/// </summary>
public class Wgs84UtmProjection : TransverseMercatorProjection
{
@ -42,47 +41,4 @@ namespace MapControl
FalseNorthing = north ? 0d : 1e7;
}
}
/// <summary>
/// WGS84 UTM Projection with automatic zone selection from projection center.
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
public const string DefaultCrsId = "AUTO2:42001";
public Wgs84AutoUtmProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public Wgs84AutoUtmProjection(string crsId)
: base(31, true)
{
CrsId = crsId;
}
public override Location Center
{
get => base.Center;
protected internal set
{
if (!base.Center.Equals(value))
{
base.Center = value;
var lon = Location.NormalizeLongitude(value.Longitude);
var zone = (int)Math.Floor(lon / 6d) + 31;
var north = value.Latitude >= 0d;
if (Zone != zone || IsNorth != north)
{
var crsId = CrsId;
SetZone(zone, north);
CrsId = crsId;
}
}
}
}
}
}

View file

@ -3,7 +3,7 @@
namespace MapControl.Projections
{
/// <summary>
/// ED50 UTM Projection with zone number.
/// ED50 Universal Transverse Mercator Projection.
/// </summary>
public class Ed50UtmProjection : GeoApiProjection
{

View file

@ -3,7 +3,7 @@
namespace MapControl.Projections
{
/// <summary>
/// ETRS89 UTM Projection with zone number.
/// ETRS89 Universal Transverse Mercator Projection.
/// </summary>
public class Etrs89UtmProjection : GeoApiProjection
{

View file

@ -3,8 +3,7 @@
namespace MapControl.Projections
{
/// <summary>
/// NAD27 UTM Projection with zone number.
/// Appears to be less accurate than MapControl.Nad27UtmProjection.
/// NAD27 Universal Transverse Mercator Projection.
/// </summary>
public class Nad27UtmProjection : GeoApiProjection
{

View file

@ -3,7 +3,7 @@
namespace MapControl.Projections
{
/// <summary>
/// NAD83 UTM Projection with zone number.
/// NAD83 Universal Transverse Mercator Projection.
/// </summary>
public class Nad83UtmProjection : GeoApiProjection
{

View file

@ -0,0 +1,59 @@
using System;
namespace MapControl.Projections
{
/// <summary>
/// WGS84 Universal Transverse Mercator Projection with
/// automatic zone selection from projection center.
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
private readonly string autoCrsId;
public Wgs84AutoUtmProjection()
: this(MapControl.Wgs84AutoUtmProjection.DefaultCrsId)
{
// XAML needs parameterless constructor
}
/// <summary>
/// When the crsId parameter is null or empty, the projection will use EPSG:32***.
/// </summary>
public Wgs84AutoUtmProjection(string crsId)
: base(31, true)
{
autoCrsId = crsId;
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
public override Location Center
{
get => base.Center;
protected set
{
if (!base.Center.Equals(value))
{
base.Center = value;
var lon = Location.NormalizeLongitude(value.Longitude);
var zone = (int)Math.Floor(lon / 6d) + 31;
var north = value.Latitude >= 0d;
if (Zone != zone || IsNorth != north)
{
SetZone(zone, north);
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
}
}
}
}
}

View file

@ -4,8 +4,7 @@ using System;
namespace MapControl.Projections
{
/// <summary>
/// WGS84 UTM Projection with zone number and north/south flag.
/// See https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system.
/// WGS84 Universal Transverse Mercator Projection.
/// </summary>
public class Wgs84UtmProjection : GeoApiProjection
{
@ -36,45 +35,4 @@ namespace MapControl.Projections
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, IsNorth);
}
}
/// <summary>
/// WGS84 UTM Projection with automatic zone selection from projection center.
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
public Wgs84AutoUtmProjection()
: this(MapControl.Wgs84AutoUtmProjection.DefaultCrsId)
{
// XAML needs parameterless constructor
}
public Wgs84AutoUtmProjection(string crsId)
: base(31, true)
{
CrsId = crsId;
}
public override Location Center
{
get => base.Center;
protected set
{
if (!base.Center.Equals(value))
{
base.Center = value;
var lon = Location.NormalizeLongitude(value.Longitude);
var zone = (int)Math.Floor(lon / 6d) + 31;
var north = value.Latitude >= 0d;
if (Zone != zone || IsNorth != north)
{
var crsId = CrsId;
SetZone(zone, north);
CrsId = crsId;
}
}
}
}
}
}