mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
EPSG Codes & CRS IDs
This commit is contained in:
parent
b74e5aaf7a
commit
ce6f190bf1
|
|
@ -18,10 +18,10 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:42004";
|
public const string DefaultCrsId = "AUTO2:42004";
|
||||||
|
|
||||||
public AutoEquirectangularProjection()
|
public AutoEquirectangularProjection(string crsId = DefaultCrsId)
|
||||||
{
|
{
|
||||||
Type = MapProjectionType.NormalCylindrical;
|
Type = MapProjectionType.NormalCylindrical;
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point? LocationToMap(Location location)
|
public override Point? LocationToMap(Location location)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
||||||
{
|
{
|
||||||
public AzimuthalEquidistantProjection(string crsId)
|
public const string DefaultCrsId = "AUTO2:97003"; // proprietary CRS ID
|
||||||
|
|
||||||
|
public AzimuthalEquidistantProjection(string crsId = DefaultCrsId)
|
||||||
{
|
{
|
||||||
CrsId = crsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EquirectangularProjection : MapProjection
|
public class EquirectangularProjection : MapProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 4326;
|
public const int EpsgCode = 4326;
|
||||||
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
|
||||||
|
|
||||||
public EquirectangularProjection()
|
public EquirectangularProjection(string crsId = "EPSG:4326")
|
||||||
{
|
{
|
||||||
Type = MapProjectionType.NormalCylindrical;
|
Type = MapProjectionType.NormalCylindrical;
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(Location location)
|
public override Point GetRelativeScale(Location location)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone = zone;
|
Zone = zone;
|
||||||
CrsId = $"EPSG:{Zone - FirstZone + FirstZoneEpsgCode}";
|
CrsId = $"EPSG:{25800 + Zone}";
|
||||||
|
|
||||||
// GRS 1980
|
// GRS 1980
|
||||||
EquatorialRadius = 6378137d;
|
EquatorialRadius = 6378137d;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:97001"; // GeoServer non-standard CRS ID
|
public const string DefaultCrsId = "AUTO2:97001"; // GeoServer non-standard CRS ID
|
||||||
|
|
||||||
public GnomonicProjection()
|
public GnomonicProjection(string crsId = DefaultCrsId)
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point? LocationToMap(Location location)
|
public override Point? LocationToMap(Location location)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace MapControl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets an optional projection center.
|
/// Gets or sets an optional projection center.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Location Center { get; set; } = new Location();
|
public virtual Location Center { get; protected internal set; } = new Location();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the relative map scale at the specified Location.
|
/// Gets the relative map scale at the specified Location.
|
||||||
|
|
@ -118,7 +118,7 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual string GetCrsValue()
|
public virtual string GetCrsValue()
|
||||||
{
|
{
|
||||||
return CrsId.StartsWith("AUTO:") || CrsId.StartsWith("AUTO2:")
|
return CrsId.StartsWith("AUTO2:") || CrsId.StartsWith("AUTO:")
|
||||||
? string.Format(CultureInfo.InvariantCulture, "{0},1,{1},{2}", CrsId, Center.Longitude, Center.Latitude)
|
? string.Format(CultureInfo.InvariantCulture, "{0},1,{1},{2}", CrsId, Center.Longitude, Center.Latitude)
|
||||||
: CrsId;
|
: CrsId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,93 +16,67 @@ namespace MapControl
|
||||||
|
|
||||||
public virtual MapProjection GetProjection(int epsgCode)
|
public virtual MapProjection GetProjection(int epsgCode)
|
||||||
{
|
{
|
||||||
MapProjection projection = null;
|
|
||||||
|
|
||||||
switch (epsgCode)
|
switch (epsgCode)
|
||||||
{
|
{
|
||||||
case WorldMercatorProjection.DefaultEpsgCode:
|
case WorldMercatorProjection.EpsgCode:
|
||||||
projection = new WorldMercatorProjection();
|
return new WorldMercatorProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case WebMercatorProjection.DefaultEpsgCode:
|
case WebMercatorProjection.EpsgCode:
|
||||||
projection = new WebMercatorProjection();
|
return new WebMercatorProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case EquirectangularProjection.DefaultEpsgCode:
|
case EquirectangularProjection.EpsgCode:
|
||||||
projection = new EquirectangularProjection();
|
return new EquirectangularProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case UpsNorthProjection.DefaultEpsgCode:
|
case UpsNorthProjection.EpsgCode:
|
||||||
projection = new UpsNorthProjection();
|
return new UpsNorthProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case UpsSouthProjection.DefaultEpsgCode:
|
case UpsSouthProjection.EpsgCode:
|
||||||
projection = new UpsSouthProjection();
|
return new UpsSouthProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case var c when c >= Etrs89UtmProjection.FirstZoneEpsgCode && c <= Etrs89UtmProjection.LastZoneEpsgCode:
|
case var c when c >= Etrs89UtmProjection.FirstZoneEpsgCode && c <= Etrs89UtmProjection.LastZoneEpsgCode:
|
||||||
projection = new Etrs89UtmProjection(epsgCode % 100);
|
return new Etrs89UtmProjection(epsgCode % 100);
|
||||||
break;
|
|
||||||
|
|
||||||
case var c when c >= Nad83UtmProjection.FirstZoneEpsgCode && c <= Nad83UtmProjection.LastZoneEpsgCode:
|
case var c when c >= Nad83UtmProjection.FirstZoneEpsgCode && c <= Nad83UtmProjection.LastZoneEpsgCode:
|
||||||
projection = new Nad83UtmProjection(epsgCode % 100);
|
return new Nad83UtmProjection(epsgCode % 100);
|
||||||
break;
|
|
||||||
|
|
||||||
case var c when c >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && c <= Wgs84UtmProjection.LastZoneNorthEpsgCode:
|
case var c when c >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && c <= Wgs84UtmProjection.LastZoneNorthEpsgCode:
|
||||||
projection = new Wgs84UtmProjection(epsgCode % 100, true);
|
return new Wgs84UtmProjection(epsgCode % 100, true);
|
||||||
break;
|
|
||||||
|
|
||||||
case var c when c >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && c <= Wgs84UtmProjection.LastZoneSouthEpsgCode:
|
case var c when c >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && c <= Wgs84UtmProjection.LastZoneSouthEpsgCode:
|
||||||
projection = new Wgs84UtmProjection(epsgCode % 100, false);
|
return new Wgs84UtmProjection(epsgCode % 100, false);
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return projection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual MapProjection GetProjection(string crsId)
|
public virtual MapProjection GetProjection(string crsId)
|
||||||
{
|
{
|
||||||
if (crsId.StartsWith("EPSG:") && int.TryParse(crsId.Substring(5), out int epsgCode))
|
|
||||||
{
|
|
||||||
return GetProjection(epsgCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
MapProjection projection = null;
|
|
||||||
|
|
||||||
switch (crsId)
|
switch (crsId)
|
||||||
{
|
{
|
||||||
case Wgs84AutoUtmProjection.DefaultCrsId:
|
case Wgs84AutoUtmProjection.DefaultCrsId:
|
||||||
projection = new Wgs84AutoUtmProjection();
|
return new Wgs84AutoUtmProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case OrthographicProjection.DefaultCrsId:
|
case OrthographicProjection.DefaultCrsId:
|
||||||
projection = new OrthographicProjection();
|
return new OrthographicProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case AutoEquirectangularProjection.DefaultCrsId:
|
case AutoEquirectangularProjection.DefaultCrsId:
|
||||||
projection = new AutoEquirectangularProjection();
|
return new AutoEquirectangularProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case GnomonicProjection.DefaultCrsId:
|
case GnomonicProjection.DefaultCrsId:
|
||||||
projection = new GnomonicProjection();
|
return new GnomonicProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case StereographicProjection.DefaultCrsId:
|
case StereographicProjection.DefaultCrsId:
|
||||||
projection = new StereographicProjection();
|
return new StereographicProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
case "AUTO2:97003": // proprietary CRS ID
|
case AzimuthalEquidistantProjection.DefaultCrsId:
|
||||||
projection = new AzimuthalEquidistantProjection(crsId);
|
return new AzimuthalEquidistantProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return crsId.StartsWith("EPSG:") && int.TryParse(crsId.Substring(5), out int epsgCode)
|
||||||
|
? GetProjection(epsgCode)
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return projection;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone = zone;
|
Zone = zone;
|
||||||
CrsId = $"EPSG:{Zone - FirstZone + FirstZoneEpsgCode}";
|
CrsId = $"EPSG:{26900 + Zone}";
|
||||||
|
|
||||||
// GRS 1980
|
// GRS 1980
|
||||||
EquatorialRadius = 6378137d;
|
EquatorialRadius = 6378137d;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:42003";
|
public const string DefaultCrsId = "AUTO2:42003";
|
||||||
|
|
||||||
public OrthographicProjection()
|
public OrthographicProjection(string crsId = DefaultCrsId)
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point? LocationToMap(Location location)
|
public override Point? LocationToMap(Location location)
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,11 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UpsNorthProjection : PolarStereographicProjection
|
public class UpsNorthProjection : PolarStereographicProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 32661;
|
public const int EpsgCode = 32661;
|
||||||
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
|
||||||
|
|
||||||
public UpsNorthProjection()
|
public UpsNorthProjection(string crsId = "EPSG:32661")
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
IsNorth = true;
|
IsNorth = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,12 +131,11 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UpsSouthProjection : PolarStereographicProjection
|
public class UpsSouthProjection : PolarStereographicProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 32761;
|
public const int EpsgCode = 32761;
|
||||||
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
|
||||||
|
|
||||||
public UpsSouthProjection()
|
public UpsSouthProjection(string crsId = "EPSG:32761")
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
IsNorth = false;
|
IsNorth = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
|
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
|
||||||
|
|
||||||
public StereographicProjection()
|
public StereographicProjection(string crsId = DefaultCrsId)
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point? LocationToMap(Location location)
|
public override Point? LocationToMap(Location location)
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,12 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WebMercatorProjection : MapProjection
|
public class WebMercatorProjection : MapProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 3857;
|
public const int EpsgCode = 3857;
|
||||||
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
|
||||||
|
|
||||||
public WebMercatorProjection()
|
public WebMercatorProjection(string crsId = "EPSG:3857")
|
||||||
{
|
{
|
||||||
Type = MapProjectionType.WebMercator;
|
Type = MapProjectionType.WebMercator;
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(Location location)
|
public override Point GetRelativeScale(Location location)
|
||||||
|
|
|
||||||
|
|
@ -21,27 +21,21 @@ namespace MapControl
|
||||||
public int Zone { get; private set; }
|
public int Zone { get; private set; }
|
||||||
public bool IsNorth { get; private set; }
|
public bool IsNorth { get; private set; }
|
||||||
|
|
||||||
protected Wgs84UtmProjection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wgs84UtmProjection(int zone, bool north)
|
public Wgs84UtmProjection(int zone, bool north)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, north);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetZone(int zone, bool north, string crsId = null)
|
protected void SetZone(int zone, bool north)
|
||||||
{
|
{
|
||||||
if (zone < FirstZone || zone > LastZone)
|
if (zone < FirstZone || zone > LastZone)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Invalid WGS84 UTM zone {zone}.", nameof(zone));
|
throw new ArgumentException($"Invalid WGS84 UTM zone {zone}.", nameof(zone));
|
||||||
}
|
}
|
||||||
|
|
||||||
var epsgCode = zone - FirstZone + (north ? FirstZoneNorthEpsgCode : FirstZoneSouthEpsgCode);
|
|
||||||
|
|
||||||
Zone = zone;
|
Zone = zone;
|
||||||
IsNorth = north;
|
IsNorth = north;
|
||||||
CrsId = crsId ?? $"EPSG:{epsgCode}";
|
CrsId = $"EPSG:{(north ? 32600 : 32700) + zone}";
|
||||||
EquatorialRadius = Wgs84EquatorialRadius;
|
EquatorialRadius = Wgs84EquatorialRadius;
|
||||||
Flattening = Wgs84Flattening;
|
Flattening = Wgs84Flattening;
|
||||||
ScaleFactor = DefaultScaleFactor;
|
ScaleFactor = DefaultScaleFactor;
|
||||||
|
|
@ -58,38 +52,43 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:42001";
|
public const string DefaultCrsId = "AUTO2:42001";
|
||||||
|
|
||||||
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
|
private readonly string autoCrsId;
|
||||||
{
|
|
||||||
UseZoneCrsId = useZoneCrsId;
|
|
||||||
UpdateZone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool UseZoneCrsId { get; }
|
public Wgs84AutoUtmProjection(string crsId = DefaultCrsId)
|
||||||
|
: base(31, true)
|
||||||
|
{
|
||||||
|
autoCrsId = crsId;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(autoCrsId))
|
||||||
|
{
|
||||||
|
CrsId = autoCrsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override Location Center
|
public override Location Center
|
||||||
{
|
{
|
||||||
get => base.Center;
|
get => base.Center;
|
||||||
set
|
protected internal set
|
||||||
{
|
{
|
||||||
if (!Equals(base.Center, value))
|
if (!Equals(base.Center, value))
|
||||||
{
|
{
|
||||||
base.Center = value;
|
base.Center = value;
|
||||||
UpdateZone();
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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, UseZoneCrsId ? null : DefaultCrsId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,12 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WorldMercatorProjection : MapProjection
|
public class WorldMercatorProjection : MapProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 3395;
|
public const int EpsgCode = 3395;
|
||||||
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
|
||||||
|
|
||||||
public WorldMercatorProjection()
|
public WorldMercatorProjection(string crsId = "EPSG:3395")
|
||||||
{
|
{
|
||||||
Type = MapProjectionType.NormalCylindrical;
|
Type = MapProjectionType.NormalCylindrical;
|
||||||
CrsId = DefaultCrsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(Location location)
|
public override Point GetRelativeScale(Location location)
|
||||||
|
|
|
||||||
|
|
@ -8,75 +8,64 @@ namespace MapControl.Projections
|
||||||
{
|
{
|
||||||
public class GeoApiProjectionFactory : MapProjectionFactory
|
public class GeoApiProjectionFactory : MapProjectionFactory
|
||||||
{
|
{
|
||||||
|
public static GeoApiProjectionFactory GetInstance()
|
||||||
|
{
|
||||||
|
if (!(Instance is GeoApiProjectionFactory factory))
|
||||||
|
{
|
||||||
|
factory = new GeoApiProjectionFactory();
|
||||||
|
Instance = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
public Dictionary<int, string> CoordinateSystemWkts { get; } = new Dictionary<int, string>();
|
public Dictionary<int, string> CoordinateSystemWkts { get; } = new Dictionary<int, string>();
|
||||||
|
|
||||||
public override MapProjection GetProjection(int epsgCode)
|
public override MapProjection GetProjection(int epsgCode)
|
||||||
{
|
{
|
||||||
MapProjection projection = null;
|
switch (epsgCode)
|
||||||
|
|
||||||
if (CoordinateSystemWkts.TryGetValue(epsgCode, out string wkt))
|
|
||||||
{
|
{
|
||||||
projection = new GeoApiProjection(wkt);
|
case WorldMercatorProjection.EpsgCode:
|
||||||
|
return new WorldMercatorProjection();
|
||||||
|
|
||||||
|
case WebMercatorProjection.EpsgCode:
|
||||||
|
return new WebMercatorProjection();
|
||||||
|
|
||||||
|
case int c when c >= Ed50UtmProjection.FirstZoneEpsgCode && c <= Ed50UtmProjection.LastZoneEpsgCode:
|
||||||
|
return new Ed50UtmProjection(epsgCode % 100);
|
||||||
|
|
||||||
|
case var c when c >= Etrs89UtmProjection.FirstZoneEpsgCode && c <= Etrs89UtmProjection.LastZoneEpsgCode:
|
||||||
|
return new Etrs89UtmProjection(epsgCode % 100);
|
||||||
|
|
||||||
|
case var c when c >= Nad27UtmProjection.FirstZoneEpsgCode && c <= Nad27UtmProjection.LastZoneEpsgCode:
|
||||||
|
return new Nad27UtmProjection(epsgCode % 100);
|
||||||
|
|
||||||
|
case var c when c >= Nad83UtmProjection.FirstZoneEpsgCode && c <= Nad83UtmProjection.LastZoneEpsgCode:
|
||||||
|
return new Nad83UtmProjection(epsgCode % 100);
|
||||||
|
|
||||||
|
case var c when c >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && c <= Wgs84UtmProjection.LastZoneNorthEpsgCode:
|
||||||
|
return new Wgs84UtmProjection(epsgCode % 100, true);
|
||||||
|
|
||||||
|
case var c when c >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && c <= Wgs84UtmProjection.LastZoneSouthEpsgCode:
|
||||||
|
return new Wgs84UtmProjection(epsgCode % 100, false);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CoordinateSystemWkts.TryGetValue(epsgCode, out string wkt)
|
||||||
|
? new GeoApiProjection(wkt)
|
||||||
|
: base.GetProjection(epsgCode);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (epsgCode)
|
|
||||||
{
|
|
||||||
case WorldMercatorProjection.DefaultEpsgCode:
|
|
||||||
projection = new WorldMercatorProjection();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WebMercatorProjection.DefaultEpsgCode:
|
|
||||||
projection = new WebMercatorProjection();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case int c when c >= Ed50UtmProjection.FirstZoneEpsgCode && c <= Ed50UtmProjection.LastZoneEpsgCode:
|
|
||||||
projection = new Ed50UtmProjection(epsgCode % 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case var c when c >= Etrs89UtmProjection.FirstZoneEpsgCode && c <= Etrs89UtmProjection.LastZoneEpsgCode:
|
|
||||||
projection = new Etrs89UtmProjection(epsgCode % 100);
|
|
||||||
break;
|
|
||||||
|
|
||||||
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 var c when c >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && c <= Wgs84UtmProjection.LastZoneSouthEpsgCode:
|
|
||||||
projection = new Wgs84UtmProjection(epsgCode % 100, false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return projection ?? base.GetProjection(epsgCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MapProjection GetProjection(string crsId)
|
public override MapProjection GetProjection(string crsId)
|
||||||
{
|
{
|
||||||
MapProjection projection = null;
|
|
||||||
|
|
||||||
switch (crsId)
|
switch (crsId)
|
||||||
{
|
{
|
||||||
case Wgs84AutoUtmProjection.DefaultCrsId:
|
case Wgs84AutoUtmProjection.DefaultCrsId:
|
||||||
projection = new Wgs84AutoUtmProjection();
|
return new Wgs84AutoUtmProjection();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
return base.GetProjection(crsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return projection ?? base.GetProjection(crsId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace MapControl.Projections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WebMercatorProjection : GeoApiProjection
|
public class WebMercatorProjection : GeoApiProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 3857;
|
public const int EpsgCode = 3857;
|
||||||
|
|
||||||
public WebMercatorProjection()
|
public WebMercatorProjection()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@ namespace MapControl.Projections
|
||||||
public int Zone { get; private set; }
|
public int Zone { get; private set; }
|
||||||
public bool IsNorth { get; private set; }
|
public bool IsNorth { get; private set; }
|
||||||
|
|
||||||
protected Wgs84UtmProjection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wgs84UtmProjection(int zone, bool north)
|
public Wgs84UtmProjection(int zone, bool north)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, north);
|
||||||
|
|
@ -51,40 +47,41 @@ namespace MapControl.Projections
|
||||||
{
|
{
|
||||||
public const string DefaultCrsId = "AUTO2:42001";
|
public const string DefaultCrsId = "AUTO2:42001";
|
||||||
|
|
||||||
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
|
private readonly string autoCrsId;
|
||||||
{
|
|
||||||
UseZoneCrsId = useZoneCrsId;
|
|
||||||
UpdateZone();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool UseZoneCrsId { get; }
|
public Wgs84AutoUtmProjection(string crsId = DefaultCrsId)
|
||||||
|
: base(31, true)
|
||||||
|
{
|
||||||
|
autoCrsId = crsId;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(autoCrsId))
|
||||||
|
{
|
||||||
|
CrsId = autoCrsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override Location Center
|
public override Location Center
|
||||||
{
|
{
|
||||||
get => base.Center;
|
get => base.Center;
|
||||||
set
|
protected set
|
||||||
{
|
{
|
||||||
if (!Equals(base.Center, value))
|
if (!Equals(base.Center, value))
|
||||||
{
|
{
|
||||||
base.Center = value;
|
base.Center = value;
|
||||||
UpdateZone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateZone()
|
var lon = Location.NormalizeLongitude(value.Longitude);
|
||||||
{
|
var zone = (int)Math.Floor(lon / 6d) + 31;
|
||||||
var lon = Location.NormalizeLongitude(Center.Longitude);
|
var north = value.Latitude >= 0d;
|
||||||
var zone = (int)Math.Floor(lon / 6d) + 31;
|
|
||||||
var north = Center.Latitude >= 0d;
|
|
||||||
|
|
||||||
if (Zone != zone || IsNorth != north || string.IsNullOrEmpty(CrsId))
|
if (Zone != zone || IsNorth != north)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, north);
|
||||||
|
|
||||||
if (!UseZoneCrsId)
|
if (!string.IsNullOrEmpty(autoCrsId))
|
||||||
{
|
{
|
||||||
CrsId = DefaultCrsId;
|
CrsId = autoCrsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace MapControl.Projections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WorldMercatorProjection : GeoApiProjection
|
public class WorldMercatorProjection : GeoApiProjection
|
||||||
{
|
{
|
||||||
public const int DefaultEpsgCode = 3395;
|
public const int EpsgCode = 3395;
|
||||||
|
|
||||||
public WorldMercatorProjection()
|
public WorldMercatorProjection()
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +43,7 @@ namespace MapControl.Projections
|
||||||
+ "AUTHORITY[\"EPSG\",\"9001\"]],"
|
+ "AUTHORITY[\"EPSG\",\"9001\"]],"
|
||||||
+ "AXIS[\"Easting\",EAST],"
|
+ "AXIS[\"Easting\",EAST],"
|
||||||
+ "AXIS[\"Northing\",NORTH],"
|
+ "AXIS[\"Northing\",NORTH],"
|
||||||
+ "AUTHORITY[\"EPSG\",\"3395\"]]";
|
+ $"AUTHORITY[\"EPSG\",\"{EpsgCode}\"]]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(Location location)
|
public override Point GetRelativeScale(Location location)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue