mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Extend map projections
This commit is contained in:
parent
57e614978b
commit
d8d1cbccaf
27 changed files with 448 additions and 207 deletions
|
|
@ -6,15 +6,26 @@ using System;
|
|||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
/// <summary>
|
||||
/// ED50 UTM Projection with zone number.
|
||||
/// </summary>
|
||||
public class Ed50UtmProjection : GeoApiProjection
|
||||
{
|
||||
public const int FirstZone = 28;
|
||||
public const int LastZone = 38;
|
||||
public const int FirstZoneEpsgCode = 23000 + FirstZone;
|
||||
public const int LastZoneEpsgCode = 23000 + LastZone;
|
||||
|
||||
public int Zone { get; }
|
||||
|
||||
public Ed50UtmProjection(int zone)
|
||||
{
|
||||
if (zone < 28 || zone > 38)
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
throw new ArgumentException($"Invalid UTM zone {zone}.", nameof(zone));
|
||||
throw new ArgumentException($"Invalid ED50 UTM zone {zone}.", nameof(zone));
|
||||
}
|
||||
|
||||
Zone = zone;
|
||||
CoordinateSystemWkt
|
||||
= $"PROJCS[\"ED50 / UTM zone {zone}N\","
|
||||
+ "GEOGCS[\"ED50\","
|
||||
|
|
@ -23,10 +34,8 @@ namespace MapControl.Projections
|
|||
+ "AUTHORITY[\"EPSG\",\"7022\"]],"
|
||||
+ "TOWGS84[-87,-98,-121,0,0,0,0],"
|
||||
+ "AUTHORITY[\"EPSG\",\"6230\"]],"
|
||||
+ "PRIMEM[\"Greenwich\",0,"
|
||||
+ "AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,"
|
||||
+ "AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "AUTHORITY[\"EPSG\",\"4230\"]],"
|
||||
+ "PROJECTION[\"Transverse_Mercator\"],"
|
||||
+ "PARAMETER[\"latitude_of_origin\",0],"
|
||||
|
|
@ -34,8 +43,7 @@ namespace MapControl.Projections
|
|||
+ "PARAMETER[\"scale_factor\",0.9996],"
|
||||
+ "PARAMETER[\"false_easting\",500000],"
|
||||
+ "PARAMETER[\"false_northing\",0],"
|
||||
+ "UNIT[\"metre\",1,"
|
||||
+ "AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "AXIS[\"Easting\",EAST],"
|
||||
+ "AXIS[\"Northing\",NORTH],"
|
||||
+ $"AUTHORITY[\"EPSG\",\"230{zone}\"]]";
|
||||
|
|
|
|||
|
|
@ -6,15 +6,26 @@ using System;
|
|||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
/// <summary>
|
||||
/// ETRS89 UTM Projection with zone number.
|
||||
/// </summary>
|
||||
public class Etrs89UtmProjection : GeoApiProjection
|
||||
{
|
||||
public const int FirstZone = 28;
|
||||
public const int LastZone = 38;
|
||||
public const int FirstZoneEpsgCode = 25800 + FirstZone;
|
||||
public const int LastZoneEpsgCode = 25800 + LastZone;
|
||||
|
||||
public int Zone { get; }
|
||||
|
||||
public Etrs89UtmProjection(int zone)
|
||||
{
|
||||
if (zone < 28 || zone > 38)
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
throw new ArgumentException($"Invalid UTM zone {zone}.", nameof(zone));
|
||||
throw new ArgumentException($"Invalid ETRS89 UTM zone {zone}.", nameof(zone));
|
||||
}
|
||||
|
||||
Zone = zone;
|
||||
CoordinateSystemWkt
|
||||
= $"PROJCS[\"ETRS89 / UTM zone {zone}N\","
|
||||
+ "GEOGCS[\"ETRS89\","
|
||||
|
|
@ -23,10 +34,8 @@ namespace MapControl.Projections
|
|||
+ "AUTHORITY[\"EPSG\",\"7019\"]],"
|
||||
+ "TOWGS84[0,0,0,0,0,0,0],"
|
||||
+ "AUTHORITY[\"EPSG\",\"6258\"]],"
|
||||
+ "PRIMEM[\"Greenwich\",0,"
|
||||
+ "AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,"
|
||||
+ "AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "AUTHORITY[\"EPSG\",\"4258\"]],"
|
||||
+ "PROJECTION[\"Transverse_Mercator\"],"
|
||||
+ "PARAMETER[\"latitude_of_origin\",0],"
|
||||
|
|
@ -34,8 +43,7 @@ namespace MapControl.Projections
|
|||
+ "PARAMETER[\"scale_factor\",0.9996],"
|
||||
+ "PARAMETER[\"false_easting\",500000],"
|
||||
+ "PARAMETER[\"false_northing\",0],"
|
||||
+ "UNIT[\"metre\",1,"
|
||||
+ "AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "AXIS[\"Easting\",EAST],"
|
||||
+ "AXIS[\"Northing\",NORTH],"
|
||||
+ $"AUTHORITY[\"EPSG\",\"258{zone}\"]]";
|
||||
|
|
|
|||
|
|
@ -8,17 +8,6 @@ namespace MapControl.Projections
|
|||
{
|
||||
public class GeoApiProjectionFactory : MapProjectionFactory
|
||||
{
|
||||
private const int WorldMercator = 3395;
|
||||
private const int WebMercator = 3857;
|
||||
private const int Ed50UtmFirst = 23028;
|
||||
private const int Ed50UtmLast = 23038;
|
||||
private const int Etrs89UtmFirst = 25828;
|
||||
private const int Etrs89UtmLast = 25838;
|
||||
private const int Wgs84UtmNorthFirst = 32601;
|
||||
private const int Wgs84UtmNorthLast = 32660;
|
||||
private const int Wgs84UtmSouthFirst = 32701;
|
||||
private const int Wgs84UtmSouthLast = 32760;
|
||||
|
||||
public Dictionary<int, string> CoordinateSystemWkts { get; } = new Dictionary<int, string>();
|
||||
|
||||
public override MapProjection GetProjection(int epsgCode)
|
||||
|
|
@ -33,27 +22,35 @@ namespace MapControl.Projections
|
|||
{
|
||||
switch (epsgCode)
|
||||
{
|
||||
case WorldMercator:
|
||||
case WorldMercatorProjection.DefaultEpsgCode:
|
||||
projection = new WorldMercatorProjection();
|
||||
break;
|
||||
|
||||
case WebMercator:
|
||||
case WebMercatorProjection.DefaultEpsgCode:
|
||||
projection = new WebMercatorProjection();
|
||||
break;
|
||||
|
||||
case int c when c >= Ed50UtmFirst && c <= Ed50UtmLast:
|
||||
case int c when c >= Ed50UtmProjection.FirstZoneEpsgCode && c <= Ed50UtmProjection.LastZoneEpsgCode:
|
||||
projection = new Ed50UtmProjection(epsgCode % 100);
|
||||
break;
|
||||
|
||||
case int c when c >= Etrs89UtmFirst && c <= Etrs89UtmLast:
|
||||
case var c when c >= Etrs89UtmProjection.FirstZoneEpsgCode && c <= Etrs89UtmProjection.LastZoneEpsgCode:
|
||||
projection = new Etrs89UtmProjection(epsgCode % 100);
|
||||
break;
|
||||
|
||||
case int c when c >= Wgs84UtmNorthFirst && c <= Wgs84UtmNorthLast:
|
||||
case var c when c >= Nad27UtmProjection.FirstZoneEpsgCode && c <= Nad27UtmProjection.LastZoneEpsgCode:
|
||||
projection = new Nad27UtmProjection(epsgCode % 100);
|
||||
break;
|
||||
|
||||
case var c when c >= Nad83UtmProjection.FirstZoneEpsgCode && c <= Nad83UtmProjection.LastZoneEpsgCode:
|
||||
projection = new Nad83UtmProjection(epsgCode % 100);
|
||||
break;
|
||||
|
||||
case var c when c >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && c <= Wgs84UtmProjection.LastZoneNorthEpsgCode:
|
||||
projection = new Wgs84UtmProjection(epsgCode % 100, true);
|
||||
break;
|
||||
|
||||
case int c when c >= Wgs84UtmSouthFirst && c <= Wgs84UtmSouthLast:
|
||||
case var c when c >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && c <= Wgs84UtmProjection.LastZoneSouthEpsgCode:
|
||||
projection = new Wgs84UtmProjection(epsgCode % 100, false);
|
||||
break;
|
||||
|
||||
|
|
|
|||
50
MapProjections/Shared/Nad27UtmProjection.cs
Normal file
50
MapProjections/Shared/Nad27UtmProjection.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
/// <summary>
|
||||
/// NAD27 UTM Projection with zone number.
|
||||
/// </summary>
|
||||
public class Nad27UtmProjection : GeoApiProjection
|
||||
{
|
||||
public const int FirstZone = 1;
|
||||
public const int LastZone = 22;
|
||||
public const int FirstZoneEpsgCode = 26700 + FirstZone;
|
||||
public const int LastZoneEpsgCode = 26700 + LastZone;
|
||||
|
||||
public int Zone { get; }
|
||||
|
||||
public Nad27UtmProjection(int zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
throw new ArgumentException($"Invalid NAD27 UTM zone {zone}.", nameof(zone));
|
||||
}
|
||||
|
||||
Zone = zone;
|
||||
CoordinateSystemWkt
|
||||
= $"PROJCS[\"NAD27 / UTM zone {zone}N\","
|
||||
+ "GEOGCS[\"NAD27\","
|
||||
+ "DATUM[\"North_American_Datum_1927\","
|
||||
+ "SPHEROID[\"Clarke 1866\",6378206.4,294.978698213898],"
|
||||
+ "]," //"EXTENSION[\"PROJ4_GRIDS\",\"NTv2_0.gsb\"]]," -- not recognized
|
||||
+ "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "AUTHORITY[\"EPSG\",\"4267\"]],"
|
||||
+ "PROJECTION[\"Transverse_Mercator\"],"
|
||||
+ "PARAMETER[\"latitude_of_origin\",0],"
|
||||
+ $"PARAMETER[\"central_meridian\",{6 * zone - 183}],"
|
||||
+ "PARAMETER[\"scale_factor\",0.9996],"
|
||||
+ "PARAMETER[\"false_easting\",500000],"
|
||||
+ "PARAMETER[\"false_northing\",0],"
|
||||
+ "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "AXIS[\"Easting\",EAST],"
|
||||
+ "AXIS[\"Northing\",NORTH],"
|
||||
+ $"AUTHORITY[\"EPSG\",\"267{zone}\"]]";
|
||||
}
|
||||
}
|
||||
}
|
||||
50
MapProjections/Shared/Nad83UtmProjection.cs
Normal file
50
MapProjections/Shared/Nad83UtmProjection.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
/// <summary>
|
||||
/// NAD83 UTM Projection with zone number.
|
||||
/// </summary>
|
||||
public class Nad83UtmProjection : GeoApiProjection
|
||||
{
|
||||
public const int FirstZone = 1;
|
||||
public const int LastZone = 23;
|
||||
public const int FirstZoneEpsgCode = 26900 + FirstZone;
|
||||
public const int LastZoneEpsgCode = 26900 + LastZone;
|
||||
|
||||
public int Zone { get; }
|
||||
|
||||
public Nad83UtmProjection(int zone)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
throw new ArgumentException($"Invalid NAD83 UTM zone {zone}.", nameof(zone));
|
||||
}
|
||||
|
||||
Zone = zone;
|
||||
CoordinateSystemWkt
|
||||
= $"PROJCS[\"NAD83 / UTM zone {zone}N\","
|
||||
+ "GEOGCS[\"NAD83\","
|
||||
+ "DATUM[\"North_American_Datum_1983\","
|
||||
+ "SPHEROID[\"GRS 1980\",6378137,298.257222101],"
|
||||
+ "TOWGS84[0,0,0,0,0,0,0]],"
|
||||
+ "PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],"
|
||||
+ "UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],"
|
||||
+ "AUTHORITY[\"EPSG\",\"4269\"]],"
|
||||
+ "PROJECTION[\"Transverse_Mercator\"],"
|
||||
+ "PARAMETER[\"latitude_of_origin\",0],"
|
||||
+ $"PARAMETER[\"central_meridian\",{6 * zone - 183}],"
|
||||
+ "PARAMETER[\"scale_factor\",0.9996],"
|
||||
+ "PARAMETER[\"false_easting\",500000],"
|
||||
+ "PARAMETER[\"false_northing\",0],"
|
||||
+ "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||
+ "AXIS[\"Easting\",EAST],"
|
||||
+ "AXIS[\"Northing\",NORTH],"
|
||||
+ $"AUTHORITY[\"EPSG\",\"269{zone}\"]]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,8 @@ namespace MapControl.Projections
|
|||
/// </summary>
|
||||
public class WebMercatorProjection : GeoApiProjection
|
||||
{
|
||||
public const int DefaultEpsgCode = 3857;
|
||||
|
||||
public WebMercatorProjection()
|
||||
{
|
||||
CoordinateSystem = ProjectedCoordinateSystem.WebMercator;
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using ProjNet.CoordinateSystems;
|
||||
using System;
|
||||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
public class Wgs84AutoUtmProjection : GeoApiProjection
|
||||
{
|
||||
public const string DefaultCrsId = "AUTO2:42001";
|
||||
|
||||
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
|
||||
{
|
||||
UseZoneCrsId = useZoneCrsId;
|
||||
UpdateZone();
|
||||
}
|
||||
|
||||
public int Zone { get; private set; }
|
||||
public bool IsNorth { get; private set; }
|
||||
public bool UseZoneCrsId { get; }
|
||||
|
||||
public override Location Center
|
||||
{
|
||||
get => base.Center;
|
||||
set
|
||||
{
|
||||
if (!Equals(base.Center, value))
|
||||
{
|
||||
base.Center = value;
|
||||
UpdateZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateZone()
|
||||
{
|
||||
var lon = Location.NormalizeLongitude(Center.Longitude);
|
||||
var zone = (int)Math.Floor(lon / 6d) + 31;
|
||||
var north = Center.Latitude >= 0d;
|
||||
|
||||
if (Zone != zone || IsNorth != north)
|
||||
{
|
||||
Zone = zone;
|
||||
IsNorth = north;
|
||||
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, IsNorth);
|
||||
|
||||
if (!UseZoneCrsId)
|
||||
{
|
||||
CrsId = DefaultCrsId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,16 +7,86 @@ using System;
|
|||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
/// <summary>
|
||||
/// WGS84 UTM Projection with zone number and north/south flag.
|
||||
/// </summary>
|
||||
public class Wgs84UtmProjection : GeoApiProjection
|
||||
{
|
||||
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; }
|
||||
|
||||
protected Wgs84UtmProjection()
|
||||
{
|
||||
}
|
||||
|
||||
public Wgs84UtmProjection(int zone, bool north)
|
||||
{
|
||||
if (zone < 1 || zone > 60)
|
||||
SetZone(zone, north);
|
||||
}
|
||||
|
||||
protected void SetZone(int zone, bool north)
|
||||
{
|
||||
if (zone < FirstZone || zone > LastZone)
|
||||
{
|
||||
throw new ArgumentException($"Invalid UTM zone {zone}.", nameof(zone));
|
||||
throw new ArgumentException($"Invalid WGS84 UTM zone {zone}.", nameof(zone));
|
||||
}
|
||||
|
||||
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(zone, north);
|
||||
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
|
||||
{
|
||||
public const string DefaultCrsId = "AUTO2:42001";
|
||||
|
||||
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
|
||||
{
|
||||
UseZoneCrsId = useZoneCrsId;
|
||||
UpdateZone();
|
||||
}
|
||||
|
||||
public bool UseZoneCrsId { get; }
|
||||
|
||||
public override Location Center
|
||||
{
|
||||
get => base.Center;
|
||||
set
|
||||
{
|
||||
if (!Equals(base.Center, value))
|
||||
{
|
||||
base.Center = value;
|
||||
UpdateZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateZone()
|
||||
{
|
||||
var lon = Location.NormalizeLongitude(Center.Longitude);
|
||||
var zone = (int)Math.Floor(lon / 6d) + 31;
|
||||
var north = Center.Latitude >= 0d;
|
||||
|
||||
if (Zone != zone || IsNorth != north || string.IsNullOrEmpty(CrsId))
|
||||
{
|
||||
SetZone(zone, north);
|
||||
|
||||
if (!UseZoneCrsId)
|
||||
{
|
||||
CrsId = DefaultCrsId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace MapControl.Projections
|
|||
/// </summary>
|
||||
public class WorldMercatorProjection : GeoApiProjection
|
||||
{
|
||||
public const int DefaultEpsgCode = 3395;
|
||||
|
||||
public WorldMercatorProjection()
|
||||
{
|
||||
CoordinateSystemWkt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue