EPSG Codes & CRS IDs

This commit is contained in:
ClemensFischer 2024-07-12 13:57:27 +02:00
parent b74e5aaf7a
commit ce6f190bf1
18 changed files with 151 additions and 195 deletions

View file

@ -21,27 +21,21 @@ namespace MapControl
public int Zone { get; private set; }
public bool IsNorth { get; private set; }
protected Wgs84UtmProjection()
{
}
public Wgs84UtmProjection(int zone, bool 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)
{
throw new ArgumentException($"Invalid WGS84 UTM zone {zone}.", nameof(zone));
}
var epsgCode = zone - FirstZone + (north ? FirstZoneNorthEpsgCode : FirstZoneSouthEpsgCode);
Zone = zone;
IsNorth = north;
CrsId = crsId ?? $"EPSG:{epsgCode}";
CrsId = $"EPSG:{(north ? 32600 : 32700) + zone}";
EquatorialRadius = Wgs84EquatorialRadius;
Flattening = Wgs84Flattening;
ScaleFactor = DefaultScaleFactor;
@ -58,38 +52,43 @@ namespace MapControl
{
public const string DefaultCrsId = "AUTO2:42001";
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
{
UseZoneCrsId = useZoneCrsId;
UpdateZone();
}
private readonly string autoCrsId;
public bool UseZoneCrsId { get; }
public Wgs84AutoUtmProjection(string crsId = DefaultCrsId)
: base(31, true)
{
autoCrsId = crsId;
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
public override Location Center
{
get => base.Center;
set
protected internal set
{
if (!Equals(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);
}
}
}
}