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