Removed azimuthal and "auto" map projections

Removing these projections - which were never really well implemented - greatly simplifies the code. There is no ProjectionCenter anymore and MapProjection methods do not return null Locations or Points.
This commit is contained in:
ClemensFischer 2026-01-29 16:27:34 +01:00
parent f4481c31f0
commit 76b879dfac
37 changed files with 181 additions and 1076 deletions

View file

@ -76,22 +76,16 @@ namespace MapControl.Projections
return new Matrix(1d, 0d, 0d, 1d, 0d, 0d);
}
public override Point? LocationToMap(double latitude, double longitude)
public override Point LocationToMap(double latitude, double longitude)
{
if (LocationToMapTransform == null)
{
throw new InvalidOperationException("The CoordinateSystem property is not set.");
}
try
{
var coordinate = LocationToMapTransform.Transform([longitude, latitude]);
return new Point(coordinate[0], coordinate[1]);
}
catch
{
return null;
}
var coordinate = LocationToMapTransform.Transform([longitude, latitude]);
return new Point(coordinate[0], coordinate[1]);
}
public override Location MapToLocation(double x, double y)
@ -101,15 +95,9 @@ namespace MapControl.Projections
throw new InvalidOperationException("The CoordinateSystem property is not set.");
}
try
{
var coordinate = MapToLocationTransform.Transform([x, y]);
return new Location(coordinate[1], coordinate[0]);
}
catch
{
return null;
}
var coordinate = MapToLocationTransform.Transform([x, y]);
return new Location(coordinate[1], coordinate[0]);
}
}
}

View file

@ -32,9 +32,6 @@ namespace MapControl.Projections
MapControl.WorldMercatorProjection.DefaultCrsId => new WorldMercatorProjection(),
MapControl.Wgs84UpsNorthProjection.DefaultCrsId => new Wgs84UpsNorthProjection(),
MapControl.Wgs84UpsSouthProjection.DefaultCrsId => new Wgs84UpsSouthProjection(),
MapControl.Wgs84AutoUtmProjection.DefaultCrsId => new Wgs84AutoUtmProjection(),
MapControl.OrthographicProjection.DefaultCrsId => new Wgs84OrthographicProjection(),
MapControl.StereographicProjection.DefaultCrsId => new Wgs84StereographicProjection(),
_ => GetProjectionFromEpsgCode(crsId) ?? base.GetProjection(crsId)
};
}

View file

@ -1,46 +0,0 @@
using System;
namespace MapControl.Projections
{
/// <summary>
/// WGS84 Universal Transverse Mercator Projection with automatic zone selection from
/// the projection center. If the CRS identifier passed to the constructor is null or empty,
/// appropriate values from EPSG:32601 to EPSG:32660 and EPSG:32701 to EPSG:32760 are used.
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
private readonly string autoCrsId;
public Wgs84AutoUtmProjection() // parameterless constructor for XAML
: this(MapControl.Wgs84AutoUtmProjection.DefaultCrsId)
{
}
public Wgs84AutoUtmProjection(string crsId)
: base(31, Hemisphere.North)
{
autoCrsId = crsId;
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
protected override void CenterChanged()
{
var zone = (int)Math.Floor(Center.Longitude / 6d) + 31;
var hemisphere = Center.Latitude >= 0d ? Hemisphere.North : Hemisphere.South;
if (Zone != zone || Hemisphere != hemisphere)
{
SetZone(zone, hemisphere);
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
}
}
}

View file

@ -1,44 +0,0 @@
using System.Globalization;
#if WPF
using System.Windows.Media;
#endif
namespace MapControl.Projections
{
/// <summary>
/// Spherical Orthographic Projection - AUTO2:42003.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.148-150.
/// </summary>
public class Wgs84OrthographicProjection : ProjNetMapProjection
{
public Wgs84OrthographicProjection()
{
EnableCenterUpdates();
}
protected override void CenterChanged()
{
var wktFormat =
"PROJCS[\"WGS 84 / World Mercator\"," +
WktConstants.GeogCsWgs84 + "," +
"PROJECTION[\"Orthographic\"]," +
"PARAMETER[\"latitude_of_origin\",{0:0.########}]," +
"PARAMETER[\"central_meridian\",{1:0.########}]," +
"UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]," +
"AXIS[\"Easting\",EAST]," +
"AXIS[\"Northing\",NORTH]" +
"AUTHORITY[\"AUTO2\",\"42003\"]]";
CoordinateSystemWkt = string.Format(
CultureInfo.InvariantCulture, wktFormat, Center.Latitude, Center.Longitude);
}
public override Matrix RelativeTransform(double latitude, double longitude)
{
var p = new AzimuthalProjection.ProjectedPoint(Center.Latitude, Center.Longitude, latitude, longitude);
(var scaleX, var scaleY) = p.RelativeScale(p.CosC, 1d); // p.149 (20-5), k == 1
return RelativeTransform(latitude, longitude, scaleX, scaleY);
}
}
}

View file

@ -1,44 +0,0 @@
using System.Globalization;
#if WPF
using System.Windows.Media;
#endif
namespace MapControl.Projections
{
/// <summary>
/// Spherical Stereographic Projection - AUTO2:97002.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.157-160.
/// </summary>
public class Wgs84StereographicProjection : ProjNetMapProjection
{
public Wgs84StereographicProjection()
{
EnableCenterUpdates();
}
protected override void CenterChanged()
{
var wktFormat =
"PROJCS[\"WGS 84 / World Mercator\"," +
WktConstants.GeogCsWgs84 + "," +
"PROJECTION[\"Oblique_Stereographic\"]," +
"PARAMETER[\"latitude_of_origin\",{0:0.########}]," +
"PARAMETER[\"central_meridian\",{1:0.########}]," +
"UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]," +
"AXIS[\"Easting\",EAST]," +
"AXIS[\"Northing\",NORTH]" +
"AUTHORITY[\"AUTO2\",\"97002\"]]";
CoordinateSystemWkt = string.Format(
CultureInfo.InvariantCulture, wktFormat, Center.Latitude, Center.Longitude);
}
public override Matrix RelativeTransform(double latitude, double longitude)
{
var p = new AzimuthalProjection.ProjectedPoint(Center.Latitude, Center.Longitude, latitude, longitude);
var k = 2d / (1d + p.CosC); // p.157 (21-4), k0 == 1
return RelativeTransform(latitude, longitude, k, k);
}
}
}

View file

@ -23,9 +23,7 @@ namespace MapControl.Projections
public override Matrix RelativeTransform(double latitude, double longitude)
{
var k = PolarStereographicProjection.RelativeScale(Hemisphere.North, Wgs84Flattening, 0.994, latitude);
return RelativeTransform(latitude, longitude, k, k);
return PolarStereographicProjection.RelativeScale(Hemisphere.North, Wgs84Flattening, 0.994, latitude, longitude);
}
}
@ -48,9 +46,7 @@ namespace MapControl.Projections
public override Matrix RelativeTransform(double latitude, double longitude)
{
var k = PolarStereographicProjection.RelativeScale(Hemisphere.South, Wgs84Flattening, 0.994, latitude);
return RelativeTransform(latitude, longitude, k, k);
return PolarStereographicProjection.RelativeScale(Hemisphere.North, Wgs84Flattening, 0.994, latitude, longitude);
}
}
}