mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-03-01 19:13:48 +01:00
Added enum Hemisphere
This commit is contained in:
parent
4166bd34d1
commit
1f75e9feea
|
|
@ -32,6 +32,10 @@ namespace MapControl
|
||||||
projection = new UpsSouthProjection();
|
projection = new UpsSouthProjection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "AUTO-UTM":
|
||||||
|
projection = new Wgs84AutoUtmProjection(null); // client-side auto zone
|
||||||
|
break;
|
||||||
|
|
||||||
case Wgs84AutoUtmProjection.DefaultCrsId:
|
case Wgs84AutoUtmProjection.DefaultCrsId:
|
||||||
projection = new Wgs84AutoUtmProjection();
|
projection = new Wgs84AutoUtmProjection();
|
||||||
break;
|
break;
|
||||||
|
|
@ -76,8 +80,8 @@ namespace MapControl
|
||||||
var code when code >= Etrs89UtmProjection.FirstZoneEpsgCode && code <= Etrs89UtmProjection.LastZoneEpsgCode => new Etrs89UtmProjection(epsgCode % 100),
|
var code when code >= Etrs89UtmProjection.FirstZoneEpsgCode && code <= Etrs89UtmProjection.LastZoneEpsgCode => new Etrs89UtmProjection(epsgCode % 100),
|
||||||
var code when code >= Nad27UtmProjection.FirstZoneEpsgCode && code <= Nad27UtmProjection.LastZoneEpsgCode => new Nad27UtmProjection(epsgCode % 100),
|
var code when code >= Nad27UtmProjection.FirstZoneEpsgCode && code <= Nad27UtmProjection.LastZoneEpsgCode => new Nad27UtmProjection(epsgCode % 100),
|
||||||
var code when code >= Nad83UtmProjection.FirstZoneEpsgCode && code <= Nad83UtmProjection.LastZoneEpsgCode => new Nad83UtmProjection(epsgCode % 100),
|
var code when code >= Nad83UtmProjection.FirstZoneEpsgCode && code <= Nad83UtmProjection.LastZoneEpsgCode => new Nad83UtmProjection(epsgCode % 100),
|
||||||
var code when code >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && code <= Wgs84UtmProjection.LastZoneNorthEpsgCode => new Wgs84UtmProjection(epsgCode % 100, true),
|
var code when code >= Wgs84UtmProjection.FirstZoneNorthEpsgCode && code <= Wgs84UtmProjection.LastZoneNorthEpsgCode => new Wgs84UtmProjection(epsgCode % 100, Hemisphere.North),
|
||||||
var code when code >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && code <= Wgs84UtmProjection.LastZoneSouthEpsgCode => new Wgs84UtmProjection(epsgCode % 100, false),
|
var code when code >= Wgs84UtmProjection.FirstZoneSouthEpsgCode && code <= Wgs84UtmProjection.LastZoneSouthEpsgCode => new Wgs84UtmProjection(epsgCode % 100, Hemisphere.South),
|
||||||
_ => null
|
_ => null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@ namespace MapControl
|
||||||
public double ScaleFactor { get; set; } = 0.994;
|
public double ScaleFactor { get; set; } = 0.994;
|
||||||
public double FalseEasting { get; set; } = 2e6;
|
public double FalseEasting { get; set; } = 2e6;
|
||||||
public double FalseNorthing { get; set; } = 2e6;
|
public double FalseNorthing { get; set; } = 2e6;
|
||||||
public bool IsNorth { get; set; }
|
public Hemisphere Hemisphere { get; set; }
|
||||||
|
|
||||||
public override Point RelativeScale(double latitude, double longitude)
|
public override Point RelativeScale(double latitude, double longitude)
|
||||||
{
|
{
|
||||||
latitude *= Math.PI / 180d;
|
latitude *= Math.PI / 180d;
|
||||||
|
|
||||||
if (!IsNorth)
|
if (Hemisphere == Hemisphere.South)
|
||||||
{
|
{
|
||||||
latitude = -latitude;
|
latitude = -latitude;
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ namespace MapControl
|
||||||
latitude *= Math.PI / 180d;
|
latitude *= Math.PI / 180d;
|
||||||
longitude *= Math.PI / 180d;
|
longitude *= Math.PI / 180d;
|
||||||
|
|
||||||
if (!IsNorth)
|
if (Hemisphere == Hemisphere.South)
|
||||||
{
|
{
|
||||||
latitude = -latitude;
|
latitude = -latitude;
|
||||||
longitude = -longitude;
|
longitude = -longitude;
|
||||||
|
|
@ -71,7 +71,7 @@ namespace MapControl
|
||||||
var x = r * Math.Sin(longitude); // p.161 (21-30)
|
var x = r * Math.Sin(longitude); // p.161 (21-30)
|
||||||
var y = -r * Math.Cos(longitude); // p.161 (21-31)
|
var y = -r * Math.Cos(longitude); // p.161 (21-31)
|
||||||
|
|
||||||
if (!IsNorth)
|
if (Hemisphere == Hemisphere.South)
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
y = -y;
|
y = -y;
|
||||||
|
|
@ -85,7 +85,7 @@ namespace MapControl
|
||||||
x -= FalseEasting;
|
x -= FalseEasting;
|
||||||
y -= FalseNorthing;
|
y -= FalseNorthing;
|
||||||
|
|
||||||
if (!IsNorth)
|
if (Hemisphere == Hemisphere.South)
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
y = -y;
|
y = -y;
|
||||||
|
|
@ -99,7 +99,7 @@ namespace MapControl
|
||||||
var lat = WorldMercatorProjection.ApproximateLatitude(e, t); // p.162 (3-5)
|
var lat = WorldMercatorProjection.ApproximateLatitude(e, t); // p.162 (3-5)
|
||||||
var lon = Math.Atan2(x, -y); // p.162 (20-16)
|
var lon = Math.Atan2(x, -y); // p.162 (20-16)
|
||||||
|
|
||||||
if (!IsNorth)
|
if (Hemisphere == Hemisphere.South)
|
||||||
{
|
{
|
||||||
lat = -lat;
|
lat = -lat;
|
||||||
lon = -lon;
|
lon = -lon;
|
||||||
|
|
@ -125,7 +125,7 @@ namespace MapControl
|
||||||
public UpsNorthProjection(string crsId)
|
public UpsNorthProjection(string crsId)
|
||||||
{
|
{
|
||||||
CrsId = crsId;
|
CrsId = crsId;
|
||||||
IsNorth = true;
|
Hemisphere = Hemisphere.North;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ namespace MapControl
|
||||||
public UpsSouthProjection(string crsId)
|
public UpsSouthProjection(string crsId)
|
||||||
{
|
{
|
||||||
CrsId = crsId;
|
CrsId = crsId;
|
||||||
IsNorth = false;
|
Hemisphere = Hemisphere.South;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WGS84 Universal Transverse Mercator Projection with
|
/// WGS84 Universal Transverse Mercator Projection with automatic zone selection from
|
||||||
/// automatic zone selection from projection center.
|
/// the projection center. If the CRS Id passed to the constructor is null or empty,
|
||||||
|
/// appropriate CRS Ids EPSG:32601 to EPSG:32660 and EPSG:32701 to EPSG:32760 are used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
|
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
|
||||||
{
|
{
|
||||||
|
|
@ -18,11 +19,8 @@ namespace MapControl
|
||||||
// XAML needs parameterless constructor
|
// XAML needs parameterless constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the crsId parameter is null or empty, the projection will use EPSG:32***.
|
|
||||||
/// </summary>
|
|
||||||
public Wgs84AutoUtmProjection(string crsId)
|
public Wgs84AutoUtmProjection(string crsId)
|
||||||
: base(31, true)
|
: base(31, Hemisphere.North)
|
||||||
{
|
{
|
||||||
autoCrsId = crsId;
|
autoCrsId = crsId;
|
||||||
|
|
||||||
|
|
@ -43,11 +41,11 @@ namespace MapControl
|
||||||
|
|
||||||
var lon = Location.NormalizeLongitude(value.Longitude);
|
var lon = Location.NormalizeLongitude(value.Longitude);
|
||||||
var zone = (int)Math.Floor(lon / 6d) + 31;
|
var zone = (int)Math.Floor(lon / 6d) + 31;
|
||||||
var north = value.Latitude >= 0d;
|
var hemisphere = value.Latitude >= 0d ? Hemisphere.North : Hemisphere.South;
|
||||||
|
|
||||||
if (Zone != zone || IsNorth != north)
|
if (Zone != zone || Hemisphere != hemisphere)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, hemisphere);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(autoCrsId))
|
if (!string.IsNullOrEmpty(autoCrsId))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
|
public enum Hemisphere
|
||||||
|
{
|
||||||
|
North,
|
||||||
|
South
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WGS84 Universal Transverse Mercator Projection.
|
/// WGS84 Universal Transverse Mercator Projection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -15,11 +21,11 @@ namespace MapControl
|
||||||
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
||||||
|
|
||||||
public int Zone { get; private set; }
|
public int Zone { get; private set; }
|
||||||
public bool IsNorth { get; private set; }
|
public Hemisphere Hemisphere { get; private set; }
|
||||||
|
|
||||||
public Wgs84UtmProjection(int zone, bool north)
|
public Wgs84UtmProjection(int zone, Hemisphere hemisphere)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, hemisphere);
|
||||||
|
|
||||||
EquatorialRadius = Wgs84EquatorialRadius;
|
EquatorialRadius = Wgs84EquatorialRadius;
|
||||||
Flattening = Wgs84Flattening;
|
Flattening = Wgs84Flattening;
|
||||||
|
|
@ -27,7 +33,7 @@ namespace MapControl
|
||||||
FalseEasting = 5e5;
|
FalseEasting = 5e5;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetZone(int zone, bool north)
|
protected void SetZone(int zone, Hemisphere hemisphere)
|
||||||
{
|
{
|
||||||
if (zone < FirstZone || zone > LastZone)
|
if (zone < FirstZone || zone > LastZone)
|
||||||
{
|
{
|
||||||
|
|
@ -35,10 +41,10 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone = zone;
|
Zone = zone;
|
||||||
IsNorth = north;
|
Hemisphere = hemisphere;
|
||||||
CrsId = $"EPSG:{(north ? 32600 : 32700) + zone}";
|
CrsId = $"EPSG:{(hemisphere == Hemisphere.North ? 32600 : 32700) + zone}";
|
||||||
CentralMeridian = zone * 6d - 183d;
|
CentralMeridian = zone * 6d - 183d;
|
||||||
FalseNorthing = north ? 0d : 1e7;
|
FalseNorthing = hemisphere == Hemisphere.North ? 0d : 1e7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
namespace MapControl.Projections
|
namespace MapControl.Projections
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WGS84 Universal Transverse Mercator Projection with
|
/// WGS84 Universal Transverse Mercator Projection with automatic zone selection from
|
||||||
/// automatic zone selection from projection center.
|
/// the projection center. If the CRS Id passed to the constructor is null or empty,
|
||||||
|
/// appropriate CRS Ids EPSG:32601 to EPSG:32660 and EPSG:32701 to EPSG:32760 are used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
|
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
|
||||||
{
|
{
|
||||||
|
|
@ -16,11 +17,8 @@ namespace MapControl.Projections
|
||||||
// XAML needs parameterless constructor
|
// XAML needs parameterless constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When the crsId parameter is null or empty, the projection will use EPSG:32***.
|
|
||||||
/// </summary>
|
|
||||||
public Wgs84AutoUtmProjection(string crsId)
|
public Wgs84AutoUtmProjection(string crsId)
|
||||||
: base(31, true)
|
: base(31, Hemisphere.North)
|
||||||
{
|
{
|
||||||
autoCrsId = crsId;
|
autoCrsId = crsId;
|
||||||
|
|
||||||
|
|
@ -41,11 +39,11 @@ namespace MapControl.Projections
|
||||||
|
|
||||||
var lon = Location.NormalizeLongitude(value.Longitude);
|
var lon = Location.NormalizeLongitude(value.Longitude);
|
||||||
var zone = (int)Math.Floor(lon / 6d) + 31;
|
var zone = (int)Math.Floor(lon / 6d) + 31;
|
||||||
var north = value.Latitude >= 0d;
|
var hemisphere = value.Latitude >= 0d ? Hemisphere.North : Hemisphere.South;
|
||||||
|
|
||||||
if (Zone != zone || IsNorth != north)
|
if (Zone != zone || Hemisphere != hemisphere)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, hemisphere);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(autoCrsId))
|
if (!string.IsNullOrEmpty(autoCrsId))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,14 @@ namespace MapControl.Projections
|
||||||
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
public const int LastZoneSouthEpsgCode = 32700 + LastZone;
|
||||||
|
|
||||||
public int Zone { get; private set; }
|
public int Zone { get; private set; }
|
||||||
public bool IsNorth { get; private set; }
|
public Hemisphere Hemisphere { get; private set; }
|
||||||
|
|
||||||
public Wgs84UtmProjection(int zone, bool north)
|
public Wgs84UtmProjection(int zone, Hemisphere hemisphere)
|
||||||
{
|
{
|
||||||
SetZone(zone, north);
|
SetZone(zone, hemisphere);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetZone(int zone, bool north)
|
protected void SetZone(int zone, Hemisphere hemisphere)
|
||||||
{
|
{
|
||||||
if (zone < FirstZone || zone > LastZone)
|
if (zone < FirstZone || zone > LastZone)
|
||||||
{
|
{
|
||||||
|
|
@ -31,8 +31,8 @@ namespace MapControl.Projections
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone = zone;
|
Zone = zone;
|
||||||
IsNorth = north;
|
Hemisphere = hemisphere;
|
||||||
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, IsNorth);
|
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, hemisphere == Hemisphere.North);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue