diff --git a/.gitignore b/.gitignore
index 3299512e..8b7aea83 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,6 @@ bld/
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
+
+# ReSharper solution cache
+_ReSharper.Caches/
diff --git a/Benchmarks .NET Framework/Benchmarks .NET Framework.csproj b/Benchmarks .NET Framework/Benchmarks .NET Framework.csproj
index 484551c6..28f65306 100644
--- a/Benchmarks .NET Framework/Benchmarks .NET Framework.csproj
+++ b/Benchmarks .NET Framework/Benchmarks .NET Framework.csproj
@@ -43,10 +43,6 @@
-
-
-
-
@@ -58,5 +54,8 @@
CoordinateSharp
+
+
+
\ No newline at end of file
diff --git a/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj b/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj
index 3f4da57c..fbaafe1c 100644
--- a/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj
+++ b/CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj
@@ -47,21 +47,21 @@ For more information, please contact Signature Group, LLC at this address: sales
net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70
true
true
- 1.1.5.0
+ 1.1.6.0
Signature Group, LLC
https://github.com/Tronald/CoordinateSharp
- Copyright 2022
+ Copyright 2023
CoordinateSharp magnetic data extensions.
- Adds .NET 7.0 targets
+ Maps to latest CoordinateSharp version
CoordinateSharp Latitude Longitude Coordinates Geography Magnetic Declination
License.txt
CoordinateSharp.Magnetic
CoordinateSharp.Magnetic
- 1.1.5.0
+ 1.1.6.0
true
true
CoordinateSharpPNG.png
diff --git a/CoordinateSharp.sln b/CoordinateSharp.sln
index 0ae1f6a8..d49cde8d 100644
--- a/CoordinateSharp.sln
+++ b/CoordinateSharp.sln
@@ -1,15 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29613.14
+# Visual Studio Version 17
+VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoordinateSharp", "CoordinateSharp\CoordinateSharp.csproj", "{82B32704-3306-49FD-A7FA-DB48B67B7B64}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoordinateSharp_Playground", "CoordinateSharp_Playground\CoordinateSharp_Playground.csproj", "{F81EBED4-1B80-4987-A499-F669F345E7BB}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoordinateSharp.Playground", "CoordinateSharp_Playground\CoordinateSharp.Playground.csproj", "{F81EBED4-1B80-4987-A499-F669F345E7BB}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoordinateSharp_UnitTests", "CoordinateSharp_UnitTests\CoordinateSharp.UnitTests.csproj", "{081621EE-78D3-4F86-8669-A42081B87A60}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoordinateSharp.UnitTests", "CoordinateSharp_UnitTests\CoordinateSharp.UnitTests.csproj", "{081621EE-78D3-4F86-8669-A42081B87A60}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "Benchmarks\Benchmarks.csproj", "{848975D1-C7FA-4860-BF1B-60501630279F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks .NET CORE", "Benchmarks .NET CORE\Benchmarks .NET CORE.csproj", "{848975D1-C7FA-4860-BF1B-60501630279F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks .NET Framework", "Benchmarks .NET Framework\Benchmarks .NET Framework.csproj", "{984AD04B-D8A8-427D-9BA9-6CD74A9DE148}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoordinateSharp.Magnetic", "CoordinateSharp.Magnetic\CoordinateSharp.Magnetic.csproj", "{91F911B5-9438-4651-8A26-4B8A5496A4B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +37,14 @@ Global
{848975D1-C7FA-4860-BF1B-60501630279F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{848975D1-C7FA-4860-BF1B-60501630279F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{848975D1-C7FA-4860-BF1B-60501630279F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {984AD04B-D8A8-427D-9BA9-6CD74A9DE148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {984AD04B-D8A8-427D-9BA9-6CD74A9DE148}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {984AD04B-D8A8-427D-9BA9-6CD74A9DE148}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {984AD04B-D8A8-427D-9BA9-6CD74A9DE148}.Release|Any CPU.Build.0 = Release|Any CPU
+ {91F911B5-9438-4651-8A26-4B8A5496A4B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {91F911B5-9438-4651-8A26-4B8A5496A4B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {91F911B5-9438-4651-8A26-4B8A5496A4B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {91F911B5-9438-4651-8A26-4B8A5496A4B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/CoordinateSharp/Cartesians/ECEF.Methods.cs b/CoordinateSharp/Cartesians/ECEF.Methods.cs
index 1b6a4c5c..8fdf8653 100644
--- a/CoordinateSharp/Cartesians/ECEF.Methods.cs
+++ b/CoordinateSharp/Cartesians/ECEF.Methods.cs
@@ -70,8 +70,8 @@ public partial class ECEF
///
public ECEF(Coordinate coordinate)
{
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
Ellipsoid();
geodetic_height = new Distance(0);
double[] ecef = LatLong_To_ECEF(coordinate.Latitude.DecimalDegree, coordinate.Longitude.DecimalDegree, geodetic_height.Kilometers);
@@ -106,8 +106,8 @@ public ECEF(Coordinate coordinate)
///
public ECEF(Coordinate coordinate, Distance height)
{
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
Ellipsoid();
geodetic_height = height;
double[] ecef = LatLong_To_ECEF(coordinate.Latitude.DecimalDegree, coordinate.Longitude.DecimalDegree, geodetic_height.Kilometers);
@@ -135,8 +135,8 @@ public ECEF(Coordinate coordinate, Distance height)
///
public ECEF(double xc, double yc, double zc)
{
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
Ellipsoid();
geodetic_height = new Distance(0);
x = xc;
@@ -150,8 +150,8 @@ public ECEF(double xc, double yc, double zc)
/// Geodetic coordinate
internal void ToECEF(Coordinate coordinate)
{
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
Ellipsoid();
double[] ecef = LatLong_To_ECEF(coordinate.Latitude.DecimalDegree, coordinate.Longitude.DecimalDegree, geodetic_height.Kilometers);
x = ecef[0];
diff --git a/CoordinateSharp/Celestial/Lunar/Lunar.HelperClasses.cs b/CoordinateSharp/Celestial/Lunar/Lunar.HelperClasses.cs
index c7c54221..7ba1d333 100644
--- a/CoordinateSharp/Celestial/Lunar/Lunar.HelperClasses.cs
+++ b/CoordinateSharp/Celestial/Lunar/Lunar.HelperClasses.cs
@@ -248,23 +248,104 @@ internal void ConvertTo_LocalTime(double offset)
///
[Serializable]
public class AstrologicalSigns
- {
- internal string moonName;
- internal string moonSign;
- internal string zodiacSign;
+ {
+ internal MoonName emoonName = CoordinateSharp.MoonName.None;
+ internal AstrologicalSignType emoonSign = CoordinateSharp.AstrologicalSignType.None;
+ internal AstrologicalSignType ezodiacSign = CoordinateSharp.AstrologicalSignType.None;
///
- /// Astrological Zodiac Sign.
+ /// Astrological Moon Name String.
///
- public string MoonName { get { return moonName; } }
+ public string MoonName
+ {
+ get
+ {
+ switch(emoonName)
+ {
+ case CoordinateSharp.MoonName.Wolf: return "Wolf Moon";
+ case CoordinateSharp.MoonName.Snow: return "Snow Moon";
+ case CoordinateSharp.MoonName.Worm: return "Worm Moon";
+ case CoordinateSharp.MoonName.Pink: return "Pink Moon";
+ case CoordinateSharp.MoonName.Flower: return "Flower Moon";
+ case CoordinateSharp.MoonName.Strawberry: return "Strawberry Moon";
+ case CoordinateSharp.MoonName.Buck: return "Buck Moon";
+ case CoordinateSharp.MoonName.Sturgeon: return "Sturgeon Moon";
+ case CoordinateSharp.MoonName.Corn: return "Corn Moon";
+ case CoordinateSharp.MoonName.Hunters: return "Hunters Moon";
+ case CoordinateSharp.MoonName.Beaver: return "Beaver Moon";
+ case CoordinateSharp.MoonName.Blue: return "Blue Moon";
+ case CoordinateSharp.MoonName.Cold: return "Cold Moon";
+ default: return null;
+ }
+ }
+ }
+ ///
+ /// Astrological Moon Sign String.
+ ///
+ public string MoonSign
+ {
+ get
+ {
+ switch (emoonSign)
+ {
+ case CoordinateSharp.AstrologicalSignType.Aries: return "Aries";
+ case CoordinateSharp.AstrologicalSignType.Taurus: return "Taurus";
+ case CoordinateSharp.AstrologicalSignType.Gemini: return "Gemini";
+ case CoordinateSharp.AstrologicalSignType.Cancer: return "Cancer";
+ case CoordinateSharp.AstrologicalSignType.Leo: return "Leo";
+ case CoordinateSharp.AstrologicalSignType.Virgo: return "Virgo";
+ case CoordinateSharp.AstrologicalSignType.Libra: return "Libra";
+ case CoordinateSharp.AstrologicalSignType.Scorpio: return "Scorpio";
+ case CoordinateSharp.AstrologicalSignType.Sagittarius: return "Sagittarius";
+ case CoordinateSharp.AstrologicalSignType.Capricorn: return "Capricorn";
+ case CoordinateSharp.AstrologicalSignType.Aquarius: return "Aquarius";
+ case CoordinateSharp.AstrologicalSignType.Pisces: return "Pisces";
+
+ default: return null;
+ }
+ }
+ }
+
+ ///
+ /// Astrological Zodiac Sign String.
+ ///
+ public string ZodiacSign
+ {
+ get
+ {
+ switch (ezodiacSign)
+ {
+ case CoordinateSharp.AstrologicalSignType.Aries: return "Aries";
+ case CoordinateSharp.AstrologicalSignType.Taurus: return "Taurus";
+ case CoordinateSharp.AstrologicalSignType.Gemini: return "Gemini";
+ case CoordinateSharp.AstrologicalSignType.Cancer: return "Cancer";
+ case CoordinateSharp.AstrologicalSignType.Leo: return "Leo";
+ case CoordinateSharp.AstrologicalSignType.Virgo: return "Virgo";
+ case CoordinateSharp.AstrologicalSignType.Libra: return "Libra";
+ case CoordinateSharp.AstrologicalSignType.Scorpio: return "Scorpio";
+ case CoordinateSharp.AstrologicalSignType.Sagittarius: return "Sagittarius";
+ case CoordinateSharp.AstrologicalSignType.Capricorn: return "Capricorn";
+ case CoordinateSharp.AstrologicalSignType.Aquarius: return "Aquarius";
+ case CoordinateSharp.AstrologicalSignType.Pisces: return "Pisces";
+
+ default: return null;
+ }
+ }
+ }
+
+ ///
+ /// Astrological Moon Name.
+ ///
+ public MoonName EMoonName { get { return emoonName; } }
///
/// Astrological Moon Sign.
///
- public string MoonSign { get { return moonSign; } }
+ public AstrologicalSignType EMoonSign { get { return emoonSign; } }
+
///
/// Astrological Zodiac Sign.
///
- public string ZodiacSign { get { return zodiacSign; } }
+ public AstrologicalSignType EZodiacSign { get { return ezodiacSign; } }
}
///
/// Class containing detailed lunar eclipse information.
diff --git a/CoordinateSharp/Celestial/Lunar/MoonCalculations.cs b/CoordinateSharp/Celestial/Lunar/MoonCalculations.cs
index b1c843df..34749531 100644
--- a/CoordinateSharp/Celestial/Lunar/MoonCalculations.cs
+++ b/CoordinateSharp/Celestial/Lunar/MoonCalculations.cs
@@ -321,7 +321,7 @@ public static void GetMoonIllumination(DateTime date, Celestial c, double lat, d
c.moonIllum = mi;
- string moonName = "";
+ MoonName moonName = MoonName.None;
int moonDate = 0;
//GET PHASE NAME
@@ -424,10 +424,10 @@ public static void GetMoonIllumination(DateTime date, Celestial c, double lat, d
{
if (el.Extensions.Zodiac)
{
- c.AstrologicalSigns.moonName = moonName;
+ c.AstrologicalSigns.emoonName = moonName;
}
}
- else { if (el.Extensions.Zodiac) { c.AstrologicalSigns.moonName = ""; } }
+ else { if (el.Extensions.Zodiac) { c.AstrologicalSigns.emoonName = MoonName.None; } }
}
if (el.Extensions.Lunar_Eclipse) { CalculateLunarEclipse(date, lat, lng, c); }
@@ -466,37 +466,37 @@ public static void CalculateLunarEclipse(DateTime date, double lat, double longi
}
}
- private static string GetMoonName(int month, string name)
+ private static MoonName GetMoonName(int month, MoonName name)
{
- if (name != "") { return "Blue Moon"; }
+ if (name != MoonName.None) { return MoonName.Blue; }
switch (month)
- {
+ {
case 1:
- return "Wolf Moon";
+ return MoonName.Wolf;
case 2:
- return "Snow Moon";
+ return MoonName.Snow;
case 3:
- return "Worm Moon";
+ return MoonName.Worm;
case 4:
- return "Pink Moon";
- case 5:
- return "Flower Moon";
- case 6:
- return "Strawberry Moon";
- case 7:
- return "Buck Moon";
+ return MoonName.Pink;
+ case 5:
+ return MoonName.Flower;
+ case 6:
+ return MoonName.Strawberry;
+ case 7:
+ return MoonName.Buck;
case 8:
- return "Sturgeon Moon";
+ return MoonName.Sturgeon;
case 9:
- return "Corn Moon";
+ return MoonName.Corn;
case 10:
- return "Hunters Moon";
+ return MoonName.Hunters;
case 11:
- return "Beaver Moon";
+ return MoonName.Beaver;
case 12:
- return "Cold Moon";
+ return MoonName.Cold;
default:
- return "";
+ return MoonName.None;
}
}
@@ -543,21 +543,21 @@ public static void GetMoonSign(DateTime date, Celestial c)
sign += 1;
- switch (sign.ToString())
+ switch (sign)
{
- case "1": c.AstrologicalSigns.moonSign = "Aries"; break;
- case "2": c.AstrologicalSigns.moonSign = "Taurus"; break;
- case "3": c.AstrologicalSigns.moonSign = "Gemini"; break;
- case "4": c.AstrologicalSigns.moonSign = "Cancer"; break;
- case "5": c.AstrologicalSigns.moonSign = "Leo"; break;
- case "6": c.AstrologicalSigns.moonSign = "Virgo"; break;
- case "7": c.AstrologicalSigns.moonSign = "Libra"; break;
- case "8": c.AstrologicalSigns.moonSign = "Scorpio"; break;
- case "9": c.AstrologicalSigns.moonSign = "Sagitarius"; break;
- case "10": c.AstrologicalSigns.moonSign = "Capricorn"; break;
- case "11": c.AstrologicalSigns.moonSign = "Aquarius"; break;
- case "12": c.AstrologicalSigns.moonSign = "Pisces"; break;
- default: c.AstrologicalSigns.moonSign = "Pisces"; break;
+ case 1: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Aries; break;
+ case 2: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Taurus; break;
+ case 3: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Gemini; break;
+ case 4: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Cancer; break;
+ case 5: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Leo; break;
+ case 6: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Virgo; break;
+ case 7: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Libra; break;
+ case 8: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Scorpio; break;
+ case 9: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Sagittarius; break;
+ case 10: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Capricorn; break;
+ case 11: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Aquarius; break;
+ case 12: c.AstrologicalSigns.emoonSign = AstrologicalSignType.Pisces; break;
+ default: c.AstrologicalSigns.emoonSign = AstrologicalSignType.None; break;
}
}
diff --git a/CoordinateSharp/Celestial/Solar/SunCalculations.cs b/CoordinateSharp/Celestial/Solar/SunCalculations.cs
index 95d6bcde..40e29e2b 100644
--- a/CoordinateSharp/Celestial/Solar/SunCalculations.cs
+++ b/CoordinateSharp/Celestial/Solar/SunCalculations.cs
@@ -241,67 +241,66 @@ public static void CalculateZodiacSign(DateTime date, Celestial c)
//Capricorn (December 22-January 19)
if (date >= new DateTime(date.Year, 1, 1) && date <= new DateTime(date.Year, 1, 19, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Capricorn";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Capricorn;
return;
}
if (date >= new DateTime(date.Year, 1, 20) && date <= new DateTime(date.Year, 2, 18, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Aquarius";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Aquarius;
return;
}
if (date >= new DateTime(date.Year, 2, 19) && date <= new DateTime(date.Year, 3, 20, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Pisces";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Pisces;
return;
}
if (date >= new DateTime(date.Year, 3, 21) && date <= new DateTime(date.Year, 4, 19, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Aries";
- return;
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Aries;
}
if (date >= new DateTime(date.Year, 4, 20) && date <= new DateTime(date.Year, 5, 20, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Taurus";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Taurus;
return;
}
if (date >= new DateTime(date.Year, 5, 21) && date <= new DateTime(date.Year, 6, 20,23,59,59))
{
- c.AstrologicalSigns.zodiacSign = "Gemini";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Gemini;
return;
}
if (date >= new DateTime(date.Year, 6, 21) && date <= new DateTime(date.Year, 7, 22, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Cancer";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Cancer;
return;
}
if (date >= new DateTime(date.Year, 7, 23) && date <= new DateTime(date.Year, 8, 22, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Leo";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Leo;
return;
}
if (date >= new DateTime(date.Year, 8, 23) && date <= new DateTime(date.Year, 9, 22, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Virgo";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Virgo;
return;
}
if (date >= new DateTime(date.Year, 9, 23) && date <= new DateTime(date.Year, 10, 22, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Libra";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Libra;
return;
}
if (date >= new DateTime(date.Year, 9, 23) && date <= new DateTime(date.Year, 11, 21, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Scorpio";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Scorpio;
return;
}
if (date >= new DateTime(date.Year, 11, 21) && date <= new DateTime(date.Year, 12, 21, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Sagittarius";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Sagittarius;
return;
}
if (date >= new DateTime(date.Year, 12, 22) && date <= new DateTime(date.Year, 12, 31, 23, 59, 59))
{
- c.AstrologicalSigns.zodiacSign = "Capricorn";
+ c.AstrologicalSigns.ezodiacSign = AstrologicalSignType.Capricorn;
return;
}
}
diff --git a/CoordinateSharp/Coordinate/Coordinate.Methods.cs b/CoordinateSharp/Coordinate/Coordinate.Methods.cs
index f0beeed3..1ab010fc 100644
--- a/CoordinateSharp/Coordinate/Coordinate.Methods.cs
+++ b/CoordinateSharp/Coordinate/Coordinate.Methods.cs
@@ -258,11 +258,11 @@ private void Coordinate_Builder(double lat, double longi, DateTime date, EagerLo
{
georef = new GEOREF(lat, longi);
}
-
+
//Set Ellipsoid
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
}
/*DATA LOADERS*/
diff --git a/CoordinateSharp/Coordinate/Coordinate.Parse.cs b/CoordinateSharp/Coordinate/Coordinate.Parse.cs
index acd9554a..4ac4e69c 100644
--- a/CoordinateSharp/Coordinate/Coordinate.Parse.cs
+++ b/CoordinateSharp/Coordinate/Coordinate.Parse.cs
@@ -474,7 +474,7 @@ public static Coordinate Parse(string value, DateTime geoDate, CartesianType car
public static bool TryParse(string value, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings
@@ -504,7 +504,7 @@ public static bool TryParse(string value, out Coordinate coordinate)
public static bool TryParse(string value, DateTime geoDate, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad default settings
@@ -623,7 +623,7 @@ public static bool TryParse(string value, DateTime geoDate, CartesianType cartes
public static bool TryParse(string value, EagerLoad eagerLoad, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), eagerLoad); //Reset with specified eager load options.
@@ -657,7 +657,7 @@ public static bool TryParse(string value, EagerLoad eagerLoad, out Coordinate co
public static bool TryParse(string value, DateTime geoDate, EagerLoad eagerLoad, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, GlobalSettings.Default_Parsable_Formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate, eagerLoad); //Reset with specified eager load options.
@@ -782,7 +782,7 @@ public static bool TryParse(string value, DateTime geoDate, CartesianType cartes
public static bool TryParse(string value, Allowed_Parse_Format formats, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings
@@ -814,7 +814,7 @@ public static bool TryParse(string value, Allowed_Parse_Format formats, out Coor
public static bool TryParse(string value, DateTime geoDate, Allowed_Parse_Format formats, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate); //Reset with EagerLoad default settings
@@ -941,7 +941,7 @@ public static bool TryParse(string value, DateTime geoDate, CartesianType cartes
public static bool TryParse(string value, EagerLoad eagerLoad, Allowed_Parse_Format formats, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), eagerLoad); //Reset with specified eager load options.
@@ -977,7 +977,7 @@ public static bool TryParse(string value, EagerLoad eagerLoad, Allowed_Parse_For
public static bool TryParse(string value, DateTime geoDate, EagerLoad eagerLoad, Allowed_Parse_Format formats, out Coordinate coordinate)
{
coordinate = null;
- if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartersian_Type, formats, out coordinate))
+ if (FormatFinder.TryParse(value, GlobalSettings.Default_Cartesian_Type, formats, out coordinate))
{
Parse_Format_Type pft = coordinate.Parse_Format;
coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate, eagerLoad); //Reset with specified eager load options.
diff --git a/CoordinateSharp/CoordinateSharp.csproj b/CoordinateSharp/CoordinateSharp.csproj
index 75fc4cfc..19d33c7a 100644
--- a/CoordinateSharp/CoordinateSharp.csproj
+++ b/CoordinateSharp/CoordinateSharp.csproj
@@ -47,32 +47,29 @@ For more information, please contact Signature Group, LLC at this address: sales
net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70
true
true
- 2.15.2.1
+ 2.16.1.1
Signature Group, LLC
https://github.com/Tronald/CoordinateSharp
- Copyright 2022
+ Copyright 2023
A simple library designed to assist with geographic coordinate conversions, formatting and location based solar and lunar information.
- -Adds GEOREF conversions (for use in legacy systems). Benchmark changes minimal, but may slightly impact performance in certain performance sensitive use cases. Eager Loading settings may need to be adjusted for users that prefer Lazy Loading.
--Adds .NET 7.0 targets.
--Add ability to restrict parsable formats.
--Fixes parse bug impacting ECEF format parsed coordinates with Eager Loading turned off.
--Add global default parse format settings.
--Documentation fixes.
+ -Adds ability to specify centimeter string precision for UTM/MGRS.
+-Adds ability to specify global default Equatorial Radius and Inverse Flattening values, allowing Coordinates to default to formats other than WGS84.
+-Adds enumerator options to AstrologicalSign class.
Conversion; Latitude; Longitude; Coordinates; Geography; Sun; Moon; Solar; Lunar; Time; MGRS; UTM; EPSG:3857; ECEF; GEOREF; Web Mercator;
License.txt
CoordinateSharp
CoordinateSharp
- 2.15.2.1
+ 2.16.1.1
true
true
CoordinateSharpPNG.png
CoordinateSharp Strong Name.snk
false
- 2.15.2.1
+ 2.16.1.1
https://github.com/Tronald/CoordinateSharp
README.md
snupkg
diff --git a/CoordinateSharp/Enumerators/Enumerators.cs b/CoordinateSharp/Enumerators/Enumerators.cs
index fc1a922d..18f5fa24 100644
--- a/CoordinateSharp/Enumerators/Enumerators.cs
+++ b/CoordinateSharp/Enumerators/Enumerators.cs
@@ -531,5 +531,126 @@ public enum PhaseEnum
///
WaningCrescent
}
-
+ ///
+ /// Moon name enumerator
+ ///
+ [Serializable]
+ public enum MoonName
+ {
+ ///
+ /// None Specified
+ ///
+ None,
+ ///
+ /// Wolf Moon
+ ///
+ Wolf,
+ ///
+ /// Snow Moon
+ ///
+ Snow,
+ ///
+ /// Worm Moon
+ ///
+ Worm,
+ ///
+ /// Pink Moon
+ ///
+ Pink,
+ ///
+ /// Flower Moon
+ ///
+ Flower,
+ ///
+ /// Strawberry Moon
+ ///
+ Strawberry,
+ ///
+ /// Buck Moon
+ ///
+ Buck,
+ ///
+ /// Sturgeon Moon
+ ///
+ Sturgeon,
+ ///
+ /// Corn Moon
+ ///
+ Corn,
+ ///
+ /// Hunters Moon
+ ///
+ Hunters,
+ ///
+ /// Beaver Moon
+ ///
+ Beaver,
+ ///
+ /// Cold Moon
+ ///
+ Cold,
+ ///
+ /// Blue Moon
+ ///
+ Blue,
+ }
+ ///
+ /// Moon sign enumerator
+ ///
+ [Serializable]
+ public enum AstrologicalSignType
+ {
+ ///
+ /// None Specified
+ ///
+ None,
+ ///
+ /// Aries
+ ///
+ Aries,
+ ///
+ /// Taurus
+ ///
+ Taurus,
+ ///
+ /// Gemini
+ ///
+ Gemini,
+ ///
+ /// Cancer
+ ///
+ Cancer,
+ ///
+ /// Leo
+ ///
+ Leo,
+ ///
+ /// Virgo
+ ///
+ Virgo,
+ ///
+ /// Libra
+ ///
+ Libra,
+ ///
+ /// Scorpio
+ ///
+ Scorpio,
+ ///
+ /// Sagittarius
+ ///
+ Sagittarius,
+ ///
+ /// Capricorn
+ ///
+ Capricorn,
+ ///
+ /// Aquarius
+ ///
+ Aquarius,
+ ///
+ /// Pisces
+ ///
+ Pisces,
+ }
}
diff --git a/CoordinateSharp/Globals/DataValues.cs b/CoordinateSharp/Globals/DataValues.cs
index 24d1289d..1a6ed7db 100644
--- a/CoordinateSharp/Globals/DataValues.cs
+++ b/CoordinateSharp/Globals/DataValues.cs
@@ -12,8 +12,8 @@ internal class DataValues
//WGS84
internal static readonly double WebMercatorNorthingLimit = 20037508.342789; //20048966.1;
- internal static readonly double DefaultSemiMajorAxis = 6378137.0; //WGS84
+ internal static readonly double DefaultSemiMajorAxis = 6378137.0; //WGS84 (Do Not Change without changing WebMercator to static value)
- internal static readonly double DefaultInverseFlattening = 298.257223563; //WGS84
+ internal static readonly double DefaultInverseFlattening = 298.257223563; //WGS84 (Do Not Change without changing WebMercator to static value)
}
}
diff --git a/CoordinateSharp/Globals/Extensions.cs b/CoordinateSharp/Globals/Extensions.cs
index f159b2c2..616aaf1d 100644
--- a/CoordinateSharp/Globals/Extensions.cs
+++ b/CoordinateSharp/Globals/Extensions.cs
@@ -133,5 +133,25 @@ public static double ToSeconds(this double d)
{
return Format.ToSeconds(d);
}
+ ///
+ /// Rounds double to specified precision
+ ///
+ /// double
+ /// double
+ /// double
+ /// Negative Number
+ public static double Round(this double input, int precision)
+ {
+ // in .NET implementations the two Math.Round overload may have a different implementation,
+ // which for example may have some performance differences
+ // hence we have this method to distinguish between them based on requested decimalDigits
+
+ if (precision < 0)
+ {
+ throw new ArgumentException(@"Argument 'precision' must be a non-negative number", nameof(precision));
+ }
+
+ return precision > 0 ? Math.Round(input, precision) : Math.Round(input);
+ }
}
}
diff --git a/CoordinateSharp/Globals/Settings.cs b/CoordinateSharp/Globals/Settings.cs
index 0b32a4ec..82e206e5 100644
--- a/CoordinateSharp/Globals/Settings.cs
+++ b/CoordinateSharp/Globals/Settings.cs
@@ -77,6 +77,34 @@ public static class GlobalSettings
///
/// Application wide, default Cartesian parsed format.
///
- public static CartesianType Default_Cartersian_Type { get; set; } = CartesianType.Cartesian;
+ public static CartesianType Default_Cartesian_Type { get; set; } = CartesianType.Cartesian;
+
+ ///
+ /// Application wide, default Equatorial Radius (Semi Major Axis).
+ ///
+ public static double Default_EquatorialRadius { get; set; } = DataValues.DefaultSemiMajorAxis;
+ ///
+ /// Application wide, default Inverse Flattening.
+ ///
+ public static double Default_InverseFlattening { get; set; } = DataValues.DefaultInverseFlattening;
+
+ ///
+ /// Set the default Equatorial Radius and Inverse Flattening based on a specified ellipsoid.
+ ///
+ /// Earth_Ellipsoid_Spec
+ public static void Set_DefaultDatum(Earth_Ellipsoid_Spec spec)
+ {
+ Set_DefaultDatum(Earth_Ellipsoid.Get_Ellipsoid(spec));
+ }
+
+ ///
+ /// Set the default Equatorial Radius and Inverse Flattening based on a specified ellipsoid.
+ ///
+ /// Earth_Ellipsoid
+ public static void Set_DefaultDatum(Earth_Ellipsoid ee)
+ {
+ Default_EquatorialRadius = ee.Equatorial_Radius;
+ Default_InverseFlattening = ee.Inverse_Flattening;
+ }
}
}
diff --git a/CoordinateSharp/UTM_MGRS/MGRS.Methods.cs b/CoordinateSharp/UTM_MGRS/MGRS.Methods.cs
index ac3f9db6..8cd0491b 100644
--- a/CoordinateSharp/UTM_MGRS/MGRS.Methods.cs
+++ b/CoordinateSharp/UTM_MGRS/MGRS.Methods.cs
@@ -1,9 +1,9 @@
/*
-CoordinateSharp is a .NET standard library that is intended to ease geographic coordinate
+CoordinateSharp is a .NET standard library that is intended to ease geographic coordinate
format conversions and location based celestial calculations.
https://github.com/Tronald/CoordinateSharp
-Many celestial formulas in this library are based on Jean Meeus's
+Many celestial formulas in this library are based on Jean Meeus's
Astronomical Algorithms (2nd Edition). Comments that reference only a chapter
are referring to this work.
@@ -12,25 +12,25 @@ are referring to this work.
CoordinateSharp is split licensed and may be licensed under the GNU Affero General Public License version 3 or a commercial use license as stated.
Copyright (C) 2022, Signature Group, LLC
-
-This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3
-as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a):
-FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Signature Group, LLC. Signature Group, LLC DISCLAIMS THE WARRANTY OF
+
+This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3
+as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a):
+FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Signature Group, LLC. Signature Group, LLC DISCLAIMS THE WARRANTY OF
NON INFRINGEMENT OF THIRD PARTY RIGHTS.
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU
-Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU
+Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, 02110-1301 USA, or download the license from the following URL:
https://www.gnu.org/licenses/agpl-3.0.html
-The interactive user interfaces in modified source and object code versions of this program must display Appropriate Legal Notices,
+The interactive user interfaces in modified source and object code versions of this program must display Appropriate Legal Notices,
as required under Section 5 of the GNU Affero General Public License.
-You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is mandatory
-as soon as you develop commercial activities involving the CoordinateSharp software without disclosing the source code of your own applications.
-These activities include: offering paid services to customers as an ASP, on the fly location based calculations in a web application,
+You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is mandatory
+as soon as you develop commercial activities involving the CoordinateSharp software without disclosing the source code of your own applications.
+These activities include: offering paid services to customers as an ASP, on the fly location based calculations in a web application,
or shipping CoordinateSharp with a closed source product.
Organizations or use cases that fall under the following conditions may receive a free commercial use license upon request on a case by case basis.
@@ -46,12 +46,12 @@ or shipping CoordinateSharp with a closed source product.
using System.Linq;
using System.Diagnostics;
using System.Text.RegularExpressions;
-
+using CoordinateSharp.Formatters;
namespace CoordinateSharp
{
public partial class MilitaryGridReferenceSystem
- {
+ {
///
/// Creates an MilitaryGridReferenceSystem (MGRS) object with a default WGS84 datum(ellipsoid).
@@ -68,7 +68,7 @@ public partial class MilitaryGridReferenceSystem
///
public MilitaryGridReferenceSystem(string latz, int longz, string d, double e, double n)
{
- Construct_MGRS(latz, longz, d, e, n, DataValues.DefaultSemiMajorAxis, DataValues.DefaultInverseFlattening);
+ Construct_MGRS(latz, longz, d, e, n, GlobalSettings.Default_EquatorialRadius, GlobalSettings.Default_InverseFlattening);
}
///
/// Creates an MilitaryGridReferenceSystem (MGRS) object with a custom datum(ellipsoid).
@@ -118,7 +118,7 @@ public MilitaryGridReferenceSystem(string gridZone, string d, double e, double n
string latz = gridZone.Replace(resultString, "");
- Construct_MGRS(latz, longz, d, e, n, DataValues.DefaultSemiMajorAxis, DataValues.DefaultInverseFlattening);
+ Construct_MGRS(latz, longz, d, e, n, GlobalSettings.Default_EquatorialRadius, GlobalSettings.Default_InverseFlattening);
}
///
/// Creates an MilitaryGridReferenceSystem (MGRS) object with a default WGS84 datum(ellipsoid).
@@ -135,7 +135,7 @@ public MilitaryGridReferenceSystem(string gridZone, string d, double e, double n
///
///
public MilitaryGridReferenceSystem(string gridZone, string d, double e, double n, double rad, double flt)
- {
+ {
string resultString = Regex.Match(gridZone, @"\d+").Value;
int longz;
if (!int.TryParse(resultString, out longz))
@@ -148,18 +148,18 @@ public MilitaryGridReferenceSystem(string gridZone, string d, double e, double n
else { systemType = MGRS_Type.MGRS_Polar; resultString = "0"; }
}
- string latz = gridZone.Replace(resultString, "");
-
+ string latz = gridZone.Replace(resultString, "");
+
Construct_MGRS(latz, longz, d, e, n, flt, rad);
}
///
/// Construct MGRS
- ///
+ ///
private void Construct_MGRS(string latz, int longz, string d, double e, double n, double rad, double flt)
{
Regex rg = new Regex("[aAbByYzZ]");
- Match m = rg.Match(latz);
+ Match m = rg.Match(latz);
if (m.Success)
{
@@ -196,7 +196,7 @@ private bool Verify_Lat_Zone(string l)
}
return true;
}
-
+
internal MilitaryGridReferenceSystem(UniversalTransverseMercator utm)
{
ToMGRS(utm);
@@ -210,7 +210,7 @@ internal void ToMGRS(UniversalTransverseMercator utm)
string digraph2;
Digraphs digraphs;
-
+
if (m.Success)
{
systemType = MGRS_Type.MGRS_Polar;
@@ -226,7 +226,7 @@ internal void ToMGRS(UniversalTransverseMercator utm)
digraph1 = digraphs.getDigraph1(utm.LongZone, utm.Easting);
digraph2 = digraphs.getDigraph2(utm.LongZone, utm.Northing);
}
-
+
digraph = digraph1 + digraph2;
latZone = utm.LatZone;
@@ -243,9 +243,9 @@ internal void ToMGRS(UniversalTransverseMercator utm)
e = "00000" + ((int)utm.Easting).ToString();
}
e = e.Substring(e.Length - 5);
-
+
easting = Convert.ToDouble(e) + cE;
-
+
string n = ((int)utm.Northing).ToString();
if (n.Length < 5)
{
@@ -253,12 +253,12 @@ internal void ToMGRS(UniversalTransverseMercator utm)
}
n = n.Substring(n.Length - 5);
-
+
northing = Convert.ToDouble(n) +cN;
equatorialRadius = utm.equatorial_radius;
inverseFlattening = utm.inverse_flattening;
-
+
}
///
@@ -278,7 +278,7 @@ public static Coordinate MGRStoLatLong(MilitaryGridReferenceSystem mgrs)
{
return MGRStoLatLong(mgrs, GlobalSettings.Default_EagerLoad);
}
-
+
///
/// Creates a Coordinate object from an MGRS/NATO UTM Coordinate
///
@@ -388,7 +388,7 @@ public static Coordinate MGRStoLatLong(MilitaryGridReferenceSystem mgrs, EagerLo
return c;
}
-
+
private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs, EagerLoad el)
{
//WORKING
@@ -403,9 +403,9 @@ private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs,
string digraphLettersE;
- if (!isNorth)
+ if (!isNorth)
{
- digraphLettersE = "KLPQRSTUXYZABCFGH";
+ digraphLettersE = "KLPQRSTUXYZABCFGH";
}
else { digraphLettersE = "RSTUXYZABCFGHJ"; }
@@ -422,14 +422,14 @@ private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs,
}
var eidx = digraphLettersE.IndexOf(eltr);
-
+
//Offsets are set due to less Easting Identifiers.
//North has 4 less than S
double offset = 9;
if (isNorth) { offset = 13; }
if (mgrs.latZone == "B" && eidx < offset && mgrs.easting!=0) { eidx += 18; }
-
+
double subbase = eidx + offset;
@@ -453,7 +453,7 @@ private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs,
var highLetter = Math.Round(100 + 1.11 * latBandHigh);
string latBandLetters = null;
- int l = Convert.ToInt32(lowLetter);
+ int l = Convert.ToInt32(lowLetter);
int h = Convert.ToInt32(highLetter+7);
if (mgrs.LongZone / 2.0 == Math.Floor(mgrs.LongZone / 2.0))
@@ -470,13 +470,13 @@ private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs,
if (!isNorth) { nOffset = 10; }
else { latBandLetters = digraphLettersN; }
int index = latBandLetters.IndexOf(nltr);
-
+
if (index == -1 && nltr=='A') { index -=1; } //ALPHA PATCH
//int subset = 0;
//if ((latz == "Y" || latz == "Z") && (nOffset+index)>25 && (ebase> 2100000 || ebase<2000000) && ebase!= 2000000) { subset = -14; }
var nbase = 100000 * (index+nOffset);
-
+
var x = ebase + mgrs.Easting;
var y = nbase + mgrs.Northing;
@@ -502,7 +502,7 @@ private static Coordinate MGRS_Polar_ToLatLong(MilitaryGridReferenceSystem mgrs,
return c;
}
-
+
///
/// Creates a Signed Degree double[] object from an MGRS/NATO UTM Coordinate
///
@@ -612,17 +612,17 @@ public static double[] MGRStoSignedDegree(MilitaryGridReferenceSystem mgrs)
///
/// MGRS Grid Box
///
- /// The following example will create an MGRS_GridBox that will allow us to determine
+ /// The following example will create an MGRS_GridBox that will allow us to determine
/// The MGRS Point at the bottom left of the current 100km grid square and convert it to Lat/Long.
///
/// MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("N", 21, "SA", 66037, 61982);
/// var box = mgrs.Get_Box_Boundaries();
- ///
+ ///
/// //Check if created MGRS coordinate is valid
/// if(!box.IsBoxValid){return;} //MGRS Coordinate GZD and Identifier are not standard. Box cannot be determined.
- ///
+ ///
/// Console.WriteLine("BL: " + gb.Bottom_Left_MGRS_Point); //21N SA 66022 00000
- /// Console.WriteLine("BL: " + gb.Bottom_Left_Coordinate_Point); //N 0º 0' 0" W 59º 59' 59.982"
+ /// Console.WriteLine("BL: " + gb.Bottom_Left_Coordinate_Point); //N 0º 0' 0" W 59º 59' 59.982"
///
///
public MGRS_GridBox Get_Box_Boundaries()
@@ -638,18 +638,18 @@ public MGRS_GridBox Get_Box_Boundaries()
/// EagerLoad
/// MGRS_GridBox
///
- /// The following example will create an MGRS_GridBox that will allow us to determine
+ /// The following example will create an MGRS_GridBox that will allow us to determine
/// The MGRS Point at the bottom left of the current 100km grid square and convert it to Lat/Long.
///
/// MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("N", 21, "SA", 66037, 61982);
/// EagerLoad el = new EagerLoad(EagerLoadType.UTM_MGRS); //Only eager load UTM MGRS data for efficiency
/// var box = mgrs.Get_Box_Boundaries();
- ///
+ ///
/// //Check if created MGRS coordinate is valid
/// if(!box.IsBoxValid){return;} //MGRS Coordinate GZD and Identifier are not standard. Box cannot be determined.
- ///
+ ///
/// Console.WriteLine("BL: " + gb.Bottom_Left_MGRS_Point); //21N SA 66022 00000
- /// Console.WriteLine("BL: " + gb.Bottom_Left_Coordinate_Point); //N 0º 0' 0" W 59º 59' 59.982"
+ /// Console.WriteLine("BL: " + gb.Bottom_Left_Coordinate_Point); //N 0º 0' 0" W 59º 59' 59.982"
///
///
public MGRS_GridBox Get_Box_Boundaries(EagerLoad el)
@@ -674,9 +674,10 @@ public override string ToString()
}
///
- /// Centimeter formatted MGRS string
+ /// Centimeter formatted MGRS string.
///
/// MGRS Formatted Coordinate String
+ [Obsolete("Use the ToRoundedString() method with your preferred precision. Use 5 as precision to keep the behavior of this method.")]
public string ToCentimeterString()
{
if (systemType == MGRS_Type.MGRS)
@@ -695,15 +696,28 @@ public string ToCentimeterString()
/// MGRS Formatted Coordinate String
public string ToRoundedString()
{
+ return ToRoundedString(0);
+ }
+
+ ///
+ /// Rounded MGRS string using a precision of the given number of decimal digits
+ ///
+ /// The number of the decimal digits to use
+ /// MGRS Formatted Coordinate String
+ public string ToRoundedString(int precision)
+ {
+ var formatString = "00000" + (precision > 0 ? "." + new string('#', precision) : string.Empty);
+ var eastingString = easting.Round(precision).ToString(formatString);
+ var northingString = northing.Round(precision).ToString(formatString);
+
if (systemType == MGRS_Type.MGRS)
{
- return longZone.ToString() + LatZone + " " + digraph + " " + Math.Round(easting).ToString("00000") + " " + Math.Round(northing).ToString("00000");
+ return longZone + LatZone + " " + digraph + " " + eastingString + " " + northingString;
}
else
{
- return LatZone + " " + digraph + " " + Math.Round(easting).ToString("00000") + " " + Math.Round(northing).ToString("00000");
+ return LatZone + " " + digraph + " " + eastingString + " " + northingString;
}
}
-
}
}
diff --git a/CoordinateSharp/UTM_MGRS/UTM.Methods.cs b/CoordinateSharp/UTM_MGRS/UTM.Methods.cs
index e6dfb2b2..3c3eac40 100644
--- a/CoordinateSharp/UTM_MGRS/UTM.Methods.cs
+++ b/CoordinateSharp/UTM_MGRS/UTM.Methods.cs
@@ -1,9 +1,9 @@
/*
-CoordinateSharp is a .NET standard library that is intended to ease geographic coordinate
+CoordinateSharp is a .NET standard library that is intended to ease geographic coordinate
format conversions and location based celestial calculations.
https://github.com/Tronald/CoordinateSharp
-Many celestial formulas in this library are based on Jean Meeus's
+Many celestial formulas in this library are based on Jean Meeus's
Astronomical Algorithms (2nd Edition). Comments that reference only a chapter
are referring to this work.
@@ -12,25 +12,25 @@ are referring to this work.
CoordinateSharp is split licensed and may be licensed under the GNU Affero General Public License version 3 or a commercial use license as stated.
Copyright (C) 2022, Signature Group, LLC
-
-This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3
-as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a):
-FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Signature Group, LLC. Signature Group, LLC DISCLAIMS THE WARRANTY OF
+
+This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3
+as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a):
+FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY Signature Group, LLC. Signature Group, LLC DISCLAIMS THE WARRANTY OF
NON INFRINGEMENT OF THIRD PARTY RIGHTS.
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU
-Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU
+Affero General Public License along with this program; if not, see http://www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, 02110-1301 USA, or download the license from the following URL:
https://www.gnu.org/licenses/agpl-3.0.html
-The interactive user interfaces in modified source and object code versions of this program must display Appropriate Legal Notices,
+The interactive user interfaces in modified source and object code versions of this program must display Appropriate Legal Notices,
as required under Section 5 of the GNU Affero General Public License.
-You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is mandatory
-as soon as you develop commercial activities involving the CoordinateSharp software without disclosing the source code of your own applications.
-These activities include: offering paid services to customers as an ASP, on the fly location based calculations in a web application,
+You can be released from the requirements of the license by purchasing a commercial license. Buying such a license is mandatory
+as soon as you develop commercial activities involving the CoordinateSharp software without disclosing the source code of your own applications.
+These activities include: offering paid services to customers as an ASP, on the fly location based calculations in a web application,
or shipping CoordinateSharp with a closed source product.
Organizations or use cases that fall under the following conditions may receive a free commercial use license upon request on a case by case basis.
@@ -46,10 +46,11 @@ or shipping CoordinateSharp with a closed source product.
using System.Linq;
using System.Diagnostics;
using System.Text.RegularExpressions;
+using CoordinateSharp.Formatters;
namespace CoordinateSharp
{
- public partial class UniversalTransverseMercator
+ public partial class UniversalTransverseMercator
{
///
/// Creates a UniversalTransverMercator (UTM) object with a default WGS84 datum(ellipsoid).
@@ -65,7 +66,7 @@ public partial class UniversalTransverseMercator
///
public UniversalTransverseMercator(string latz, int longz, double est, double nrt)
{
- Construct_UTM(latz, longz, est, nrt, DataValues.DefaultSemiMajorAxis, DataValues.DefaultInverseFlattening, false);
+ Construct_UTM(latz, longz, est, nrt, GlobalSettings.Default_EquatorialRadius, GlobalSettings.Default_InverseFlattening, false);
}
///
/// Creates a UniversalTransverMercator (UTM) object with a custom datum(ellipsoid).
@@ -107,20 +108,20 @@ public UniversalTransverseMercator(string gridZone, double est, double nrt)
Regex rg = new Regex("[aAbByYzZ]");
Match m = rg.Match(gridZone);
if (m.Success) { latz = gridZone; }
- else { throw new FormatException("The UTM Grid Zone Designator format is invalid."); }
+ else { throw new FormatException("The UTM Grid Zone Designator format is invalid."); }
}
else //UTM
{
string resultString = Regex.Match(gridZone, @"\d+").Value;
-
+
if (!int.TryParse(resultString, out longz))
{
throw new FormatException("The UTM Grid Zone Designator format is invalid.");
}
- latz = gridZone.Replace(resultString, "");
+ latz = gridZone.Replace(resultString, "");
}
-
- Construct_UTM(latz, longz, est, nrt, DataValues.DefaultSemiMajorAxis, DataValues.DefaultInverseFlattening, false);
+
+ Construct_UTM(latz, longz, est, nrt, GlobalSettings.Default_EquatorialRadius, GlobalSettings.Default_InverseFlattening, false);
}
///
/// Creates a UniversalTransverMercator (UTM) object with a custom WGS84 datum(ellipsoid).
@@ -147,17 +148,17 @@ public UniversalTransverseMercator(string gridZone, double est, double nrt, doub
Match m = rg.Match(gridZone);
if (m.Success) { latz = gridZone; }
else { throw new FormatException("The UTM Grid Zone Designator format is invalid."); }
-
+
}
else //UTM
{
string resultString = Regex.Match(gridZone, @"\d+").Value;
-
+
if (!int.TryParse(resultString, out longz))
{
throw new FormatException("The UTM Grid Zone Designator format is invalid.");
}
- latz = gridZone.Replace(resultString, "");
+ latz = gridZone.Replace(resultString, "");
}
Construct_UTM(latz, longz, est, nrt, radius, flatten, false);
@@ -165,8 +166,8 @@ public UniversalTransverseMercator(string gridZone, double est, double nrt, doub
internal UniversalTransverseMercator(string latz, int longz, double est, double nrt, bool suppressWarnings)
{
- Construct_UTM(latz, longz, est, nrt, DataValues.DefaultSemiMajorAxis, DataValues.DefaultInverseFlattening, suppressWarnings);
- }
+ Construct_UTM(latz, longz, est, nrt, GlobalSettings.Default_EquatorialRadius, GlobalSettings.Default_InverseFlattening, suppressWarnings);
+ }
///
/// Creates a UniversalTransverMercator (UTM) object
@@ -175,7 +176,7 @@ private void Construct_UTM(string latz, int longz, double est, double nrt, doubl
{
Regex rg = new Regex("[aAbByYzZ]");
Match m = rg.Match(latz);
-
+
if (m.Success)
{
systemType = UTM_Type.UPS;
@@ -193,7 +194,7 @@ private void Construct_UTM(string latz, int longz, double est, double nrt, doubl
if (systemType == UTM_Type.UTM && (nrt < 0 || nrt > 10000000)){ Warn(suppressWarnings, "Northing out of range", "Northing must be between 0-10,000,000."); }
if (systemType == UTM_Type.UPS && (nrt < 887000 || nrt > 3113000)) { Warn(suppressWarnings, "Northing out of range", "Northing must be between 0-10,000,000."); }
-
+
latZone = latz;
@@ -204,7 +205,7 @@ private void Construct_UTM(string latz, int longz, double est, double nrt, doubl
equatorial_radius = radius;
inverse_flattening = flaten;
}
-
+
///
/// Constructs a UTM object based off DD Lat/Long
///
@@ -212,9 +213,9 @@ private void Construct_UTM(string latz, int longz, double est, double nrt, doubl
/// DD Longitide
/// Parent Coordinate Object
internal UniversalTransverseMercator(double lat, double longi, Coordinate c)
- {
- equatorial_radius = DataValues.DefaultSemiMajorAxis;
- inverse_flattening = DataValues.DefaultInverseFlattening;
+ {
+ equatorial_radius = GlobalSettings.Default_EquatorialRadius;
+ inverse_flattening = GlobalSettings.Default_InverseFlattening;
ToUTM(lat, longi, this);
coordinate = c;
@@ -275,7 +276,7 @@ internal UniversalTransverseMercator(string latz, int longz, double e, double n,
northing = n;
coordinate = c;
-
+
}
///
@@ -291,7 +292,7 @@ private bool Verify_Lat_Zone(string l)
}
return true;
}
-
+
///
/// Assigns UTM values based of Lat/Long
///
@@ -313,10 +314,10 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
//Within UTM BOUNDS
string letter;
-
+
int zone;
if (szone == null)
- {
+ {
zone = (int)Math.Floor(longi / 6 + 31);
}
else { zone = szone.Value; }
@@ -364,7 +365,7 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
double a = utm.equatorial_radius;
double f = 1.0 / utm.inverse_flattening;
double b = a * (1 - f); // polar radius
-
+
double e = Math.Sqrt(1 - Math.Pow(b, 2) / Math.Pow(a, 2));
// double e0 = e / Math.Sqrt(1 - Math.Pow(e, 1));
@@ -372,7 +373,7 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
double k0 = 0.9996;
double phi = lat * drad; // convert latitude to radians
-
+
double utmz;
if (szone == null)
{
@@ -384,7 +385,7 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
// this gives us zone A-B for below 80S
double esq = (1 - (b / a) * (b / a));
double e0sq = e * e / (1 - Math.Pow(e, 2));
-
+
double N = a / Math.Sqrt(1 - Math.Pow(e * Math.Sin(phi), 2));
double T = Math.Pow(Math.Tan(phi), 2);
@@ -406,9 +407,9 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
x += 500000; // standard easting
// Northing
-
+
double y = k0 * (M - M0 + N * Math.Tan(phi) * (A * A * (1 / 2.0 + A * A * ((5 - T + 9 * C + 4 * C * C) / 24.0 + A * A * (61 - 58 * T + T * T + 600 * C - 330 * e0sq) / 720.0)))); // first from the equator
-
+
if (y < 0)
{
y = 10000000 + y; // add in false northing if south of the equator
@@ -418,15 +419,15 @@ internal void ToUTM(double lat, double longi, UniversalTransverseMercator utm, i
if (zone == 61) { zone = 1; }
double easting = x;
- double northing = y;
-
+ double northing = y;
+
utm.latZone = letter;
utm.longZone = zone;
utm.easting = easting;
utm.northing = northing;
utm.systemType = systemType;
}
-
+
///
/// Default formatted UTM string
///
@@ -441,6 +442,7 @@ public override string ToString()
/// Centimeter formatted UTM string (to the 5th decimal)
///
/// UTM Formatted Coordinate String
+ [Obsolete("Use the ToRoundedString() method with your preferred precision. Use 5 as precision to keep the behavior of this method.")]
public string ToCentimeterString()
{
if (systemType == UTM_Type.UPS) { return LatZone + " " + easting.ToString("0.#####") + "mE " + northing.ToString("0.#####") + "mN"; }
@@ -453,15 +455,28 @@ public string ToCentimeterString()
/// UTM Formatted Coordinate String
public string ToRoundedString()
{
- if (systemType == UTM_Type.UPS) { return LatZone + " " + Math.Round(easting) + "mE " + Math.Round(northing) + "mN"; }
- return longZone.ToString() + LatZone + " " + Math.Round(easting) + "mE " + Math.Round(northing) + "mN";
+ return ToRoundedString(0);
+ }
+
+ ///
+ /// Rounded UTM string using a precision of the given number of decimal digits
+ ///
+ /// The number of the decimal digits to use
+ /// UTM Formatted Coordinate String
+ public string ToRoundedString(int precision)
+ {
+ var eastingString = easting.Round(precision).ToString();
+ var northingString = northing.Round(precision).ToString();
+
+ if (systemType == UTM_Type.UPS) { return LatZone + " " + eastingString + "mE " + northingString + "mN"; }
+ return longZone + LatZone + " " + eastingString + "mE " + northingString + "mN";
}
private static Coordinate UTMtoLatLong(double x, double y, double zone, double equatorialRadius, double flattening, EagerLoad el)
{
//x easting
//y northing
-
+
//http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html
double phif, Nf, Nfpow, nuf2, ep2, tf, tf2, tf4, cf;
double x1frac, x2frac, x3frac, x4frac, x5frac, x6frac, x7frac, x8frac;
@@ -469,7 +484,7 @@ private static Coordinate UTMtoLatLong(double x, double y, double zone, double e
double sm_a = equatorialRadius;
double sm_b = equatorialRadius * (1 - (1.0 / flattening)); //Polar Radius
-
+
/* Get the value of phif, the footpoint latitude. */
phif = FootpointLatitude(y,equatorialRadius,flattening);
@@ -657,7 +672,7 @@ private static double[] UTMtoSigned(double x, double y, double zone, double equa
if (dLong > 180) { dLong = 180; }
if (dLong < -180) { dLong = -180; }
-
+
return new double[] { dLat, dLong };
}
@@ -681,7 +696,7 @@ private static double FootpointLatitude(double y, double equatorialRadius, doubl
/* Ellipsoid model constants (actual values here are for WGS84) */
double sm_a = equatorialRadius;
double sm_b = equatorialRadius * (1 - (1.0 / flattening));
-
+
/* Precalculate n (Eq. 10.18) */
n = (sm_a - sm_b) / (sm_a + sm_b);
@@ -741,7 +756,7 @@ public static Coordinate ConvertUTMtoLatLong(UniversalTransverseMercator utm)
/// EagerLoad
/// Coordinate
///
- /// The following example creates (converts to) a geodetic Coordinate object based on a UTM object.
+ /// The following example creates (converts to) a geodetic Coordinate object based on a UTM object.
/// Performance is maximized by turning off EagerLoading.
///
/// EagerLoad el = new EagerLoad(false);
@@ -756,12 +771,12 @@ public static Coordinate ConvertUTMtoLatLong(UniversalTransverseMercator utm, Ea
bool southhemi = false;
Regex upsCheck = new Regex("[AaBbYyZz]");
if(upsCheck.IsMatch(utm.latZone))
- {
- return UPS.UPS_To_Geodetic(utm, eagerLoad);
+ {
+ return UPS.UPS_To_Geodetic(utm, eagerLoad);
}
Regex regex = new Regex("[CcDdEeFfGgHhJjKkLlMm]");
- if (regex.IsMatch(utm.latZone)) { southhemi = true; }
+ if (regex.IsMatch(utm.latZone)) { southhemi = true; }
double cmeridian;
@@ -781,7 +796,7 @@ public static Coordinate ConvertUTMtoLatLong(UniversalTransverseMercator utm, Ea
cmeridian = UTMCentralMeridian(utm.LongZone);
Coordinate c = UTMtoLatLong(x, y, cmeridian, utm.equatorial_radius, utm.inverse_flattening, eagerLoad);
-
+
return c;
}
@@ -836,7 +851,7 @@ public static double[] ConvertUTMtoSignedDegree(UniversalTransverseMercator utm)
double[] signed = UTMtoSigned(x, y, cmeridian, utm.equatorial_radius, utm.inverse_flattening);
-
+
return signed;
@@ -855,10 +870,10 @@ private void Warn(bool supress, string warning, string message)
{
if (!supress) { Debug.WriteLine(warning, message); }
}
+
private void Warn(bool supress, string message)
{
if (!supress) { Debug.WriteLine(message); }
}
-
- }
+ }
}
diff --git a/CoordinateSharp/WebMercator/WebMercator.Methods.cs b/CoordinateSharp/WebMercator/WebMercator.Methods.cs
index ac9d4724..945504ae 100644
--- a/CoordinateSharp/WebMercator/WebMercator.Methods.cs
+++ b/CoordinateSharp/WebMercator/WebMercator.Methods.cs
@@ -121,7 +121,7 @@ internal void ToWebMercator(double lat, double lng, WebMercator wmc)
double FE = wmc.false_easting;
double FN = wmc.false_northing;
- double a = DataValues.DefaultSemiMajorAxis;
+ double a = DataValues.DefaultSemiMajorAxis; //Must use WGS 84
double E = FE + a * (lngRad - 0);
double N = FN + a * Math.Log(Math.Tan(Math.PI / 4 + latRad / 2));
@@ -178,7 +178,7 @@ private static double[] WebMercatortoSigned(double x, double y)
double FE = 0;
double FN = 0;
- double a = DataValues.DefaultSemiMajorAxis;
+ double a = DataValues.DefaultSemiMajorAxis; //Must use WGS 84
double lngNO = 0;
double D = -(N - FN) / a;
diff --git a/CoordinateSharp_UnitTests/Coordinate_Conversion_Tests.cs b/CoordinateSharp_UnitTests/Coordinate_Conversion_Tests.cs
index 45cd3acf..8084a983 100644
--- a/CoordinateSharp_UnitTests/Coordinate_Conversion_Tests.cs
+++ b/CoordinateSharp_UnitTests/Coordinate_Conversion_Tests.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.IO;
namespace CoordinateSharp_UnitTests
@@ -60,7 +61,7 @@ public void Decimal_Degree_Format_Conversion()
CoordinateFormatOptions format = new CoordinateFormatOptions() { Format = CoordinateFormatType.Decimal_Degree };
- Assert_Geodetic_Conversion(expecteds, format);
+ Assert_Geodetic_Conversion(expecteds, format);
}
///
@@ -110,7 +111,7 @@ public void UTM_Conversion()
string s3 = "28W 491315mE 7236329mN";
string s4 = "A 1519951mE 1078227mN";
- string[] expecteds = new string[] { s1, s2, s3, s4 };
+ string[] expecteds = new string[] { s1, s2, s3, s4 };
int x = 0;
List coordinates = new List() { tc1, tc2, tc3, tc4 };
@@ -194,7 +195,7 @@ public void ECEF_Conversion()
x++;
}
}
-
+
///
/// Test Web Mercator formatted coordinate conversions
///
@@ -214,10 +215,10 @@ public void WebMercator_Conversion()
foreach (string expected in expecteds)
{
EagerLoad el = new EagerLoad(false);
-
+
Coordinate c = new Coordinate(coordinates[x][0], coordinates[x][1], eg);
Assert.AreEqual(expected, c.WebMercator.ToString());
-
+
Coordinate c2 = WebMercator.ConvertWebMercatortoLatLong(c.WebMercator);
Assert.AreEqual(c2.ToString(), c.ToString());
@@ -229,7 +230,7 @@ public void WebMercator_Conversion()
double northing = c.WebMercator.Northing;
Coordinate c4 = WebMercator.ConvertWebMercatortoLatLong(easting,northing);
- Assert.AreEqual(c4.ToString(), c.ToString());
+ Assert.AreEqual(c4.ToString(), c.ToString());
Coordinate c5 = WebMercator.ConvertWebMercatortoLatLong(easting, northing, el);
Assert.AreEqual(c5.ToString(), c.ToString());
@@ -303,7 +304,7 @@ public void GEOREF_Conversion()
[TestMethod]
public void Geodetic_To_ECEF_Height_Conversion()
{
- //ECEF WITH HEIGHT CHECK
+ //ECEF WITH HEIGHT CHECK
double latE = -80.6586;
double longE = -152.49;
@@ -313,15 +314,15 @@ public void Geodetic_To_ECEF_Height_Conversion()
cE.ECEF.Set_GeoDetic_Height(cE, h);
Assert.AreEqual(0, cE.ECEF.X - -921.443, .001, "X - GeoDetic Height Conversions Outside Limits");
Assert.AreEqual(0, cE.ECEF.Y - -479.878, .001, "Y - Setting GeoDetic Height Conversions Outside Limits");
- Assert.AreEqual(0, cE.ECEF.Z - -6273.377, .001, "Z - Setting GeoDetic Height Conversions Outside Limits");
+ Assert.AreEqual(0, cE.ECEF.Z - -6273.377, .001, "Z - Setting GeoDetic Height Conversions Outside Limits");
}
///
- /// Test ECEF height correctly converts with geodetic
+ /// Test ECEF height correctly converts with geodetic
///
[TestMethod]
public void ECEF_To_Geodetic_Height_Conversion()
{
- //ECEF WITH HEIGHT CHECK
+ //ECEF WITH HEIGHT CHECK
double latE = -80.6586;
double longE = -152.49;
@@ -329,24 +330,24 @@ public void ECEF_To_Geodetic_Height_Conversion()
Coordinate cE = new Coordinate(latE, longE);
cE.ECEF.Set_GeoDetic_Height(cE, h);
-
+
ECEF ecefE = new ECEF(cE.ECEF.X, cE.ECEF.Y, cE.ECEF.Z);
Coordinate rcE = ECEF.ECEFToLatLong(ecefE);
-
+
Assert.AreEqual(0, rcE.Latitude.ToDouble() - cE.Latitude.ToDouble(), .00001, "Latitude 1 Conversion Outside Limits");
Assert.AreEqual(0, rcE.Longitude.ToDouble() - cE.Longitude.ToDouble(), .00001, "Longitude 1 Conversion Outside Limits");
Assert.AreEqual(0, rcE.ECEF.GeoDetic_Height.Meters - cE.ECEF.GeoDetic_Height.Meters, .00001, "Height 1 Conversion Outside Limits");
-
+
ecefE = new ECEF(cE, cE.ECEF.GeoDetic_Height);
rcE = ECEF.ECEFToLatLong(ecefE);
Assert.AreEqual(0, rcE.Latitude.ToDouble() - cE.Latitude.ToDouble(), .00001, "Latitude 2 Conversion Outside Limits");
Assert.AreEqual(0, rcE.Longitude.ToDouble() - cE.Longitude.ToDouble(), .00001, "Longitude 2 Conversion Outside Limits");
- Assert.AreEqual(0, rcE.ECEF.GeoDetic_Height.Meters - cE.ECEF.GeoDetic_Height.Meters, .00001, "Height 2 Conversion Outside Limits");
+ Assert.AreEqual(0, rcE.ECEF.GeoDetic_Height.Meters - cE.ECEF.GeoDetic_Height.Meters, .00001, "Height 2 Conversion Outside Limits");
}
-
+
///
/// Tests to ensure UTM gridzone locks during conversions if specified.
///
@@ -365,10 +366,10 @@ public void UTM_Grid_Zone_Conversion_Lock()
public void MGRS_Grid_Zone_Conversion_Lock()
{
- Coordinate coord1 = new Coordinate(51.5074, 1);
+ Coordinate coord1 = new Coordinate(51.5074, 1);
Assert.AreEqual(31, coord1.MGRS.LongZone,"Grid zone value not expected");
coord1.Lock_UTM_MGRS_Zone(30);
- Assert.AreEqual(30, coord1.MGRS.LongZone, "Grid zone did not lock to new value.");
+ Assert.AreEqual(30, coord1.MGRS.LongZone, "Grid zone did not lock to new value.");
}
///
@@ -412,14 +413,14 @@ public void MGRS_Grid_Zone_Locked_Conversion_Limits()
public void UTM_Grid_Zone_Conversion_Unlock()
{
Coordinate coord1 = new Coordinate(51.5074, 1);
-
+
coord1.Lock_UTM_MGRS_Zone(30); //Lock first coord to zone 30
//2 degree change tested at 1.1 Meter precision
- Coordinate coordVal = Coordinate.Parse(coord1.UTM.ToString());
+ Coordinate coordVal = Coordinate.Parse(coord1.UTM.ToString());
coord1.Unlock_UTM_MGRS_Zone();
- Assert.AreEqual(31, coord1.UTM.LongZone);
+ Assert.AreEqual(31, coord1.UTM.LongZone);
}
///
/// Tests to ensure MGRS grid zone unlocks during conversions if specified.
@@ -428,7 +429,7 @@ public void UTM_Grid_Zone_Conversion_Unlock()
public void MGRS_Grid_Zone_Conversion_Unlock()
{
- Coordinate coord1 = new Coordinate(51.5074, 1);
+ Coordinate coord1 = new Coordinate(51.5074, 1);
coord1.Lock_UTM_MGRS_Zone(30); //Lock first coord to zone 30
@@ -445,10 +446,10 @@ public void MGRS_Grid_Zone_Conversion_Unlock()
public void UTM_MGRS_Grid_Zone_Lock_Conversion_Limits()
{
- Coordinate coord1 = new Coordinate(51.5074, 1);
+ Coordinate coord1 = new Coordinate(51.5074, 1);
Assert.ThrowsException(()=>coord1.Lock_UTM_MGRS_Zone(0));
- Assert.ThrowsException(()=>coord1.Lock_UTM_MGRS_Zone(61));
+ Assert.ThrowsException(()=>coord1.Lock_UTM_MGRS_Zone(61));
}
///
@@ -491,8 +492,29 @@ public void MGRS_Rounded_Check()
{
Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
Assert.AreEqual("23T ML 45382 34246", c.MGRS.ToRoundedString());
-
}
+
+ ///
+ /// Ensures UTM Rounded string with given precision validates precision.
+ ///
+ [TestMethod]
+ [ExpectedException(typeof(ArgumentException))]
+ public void MGRS_Rounded_With_Precision_Input_Validation_Check()
+ {
+ Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
+ var result = c.MGRS.ToRoundedString(-2);
+ }
+
+ ///
+ /// Ensures correct MGRS Rounded string.
+ ///
+ [TestMethod]
+ public void MGRS_Rounded_With_Precision_Check()
+ {
+ Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
+ Assert.AreEqual("23T ML 45381.62 34245.54", c.MGRS.ToRoundedString(2));
+ }
+
///
/// Ensures correct MGRS Centimeter string.
///
@@ -510,7 +532,7 @@ public void MGRS_Centimeter_Check()
public void UTM_Centimeter_Check()
{
Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
- Assert.AreEqual("23T 445381.61737mE 5034245.53566mN", c.UTM.ToCentimeterString());
+ Assert.AreEqual("23T 445381.61737mE 5034245.53566mN", c.UTM.ToCentimeterString());
}
///
@@ -523,14 +545,33 @@ public void UTM_Rounded_Check()
Assert.AreEqual("23T 445382mE 5034246mN", c.UTM.ToRoundedString());
}
-
+ ///
+ /// Ensures UTM Rounded string with given precision validates precision.
+ ///
+ [TestMethod]
+ [ExpectedException(typeof(ArgumentException))]
+ public void UTM_Rounded_With_Precision_Input_Validation_Check()
+ {
+ Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
+ var result = c.UTM.ToRoundedString(-2);
+ }
+
+ ///
+ /// Ensures correct UTM Rounded string with given precision.
+ ///
+ [TestMethod]
+ public void UTM_Rounded_With_Precision_Check()
+ {
+ Coordinate c = new Coordinate(45.4596, -45.6986, new EagerLoad(EagerLoadType.UTM_MGRS));
+ Assert.AreEqual("23T 445381.62mE 5034245.54mN", c.UTM.ToRoundedString(2));
+ }
///
/// Test geodetic to UPS conversions
///
[TestMethod]
public void Geodetic_To_UPS_Conversions()
- {
+ {
EagerLoad el = new EagerLoad(EagerLoadType.UTM_MGRS);
foreach (var currentLine in polar_coordinates)
@@ -539,7 +580,7 @@ public void Geodetic_To_UPS_Conversions()
double lat = Convert.ToDouble(parts[5]);
double lng = Convert.ToDouble(parts[6]);
-
+
string zone = parts[1];
int easting = Convert.ToInt32(parts[2]);
@@ -555,7 +596,7 @@ public void Geodetic_To_UPS_Conversions()
Assert.AreEqual(0, c.UTM.Easting - easting, 1, "Easting value outside limits");
Assert.AreEqual(0, c.UTM.Northing - northing, 1, "Northing value outside limits");
}
-
+
}
///
@@ -604,31 +645,31 @@ public void UPS_To_Geodetic_Conversions()
double lat = Convert.ToDouble(parts[5]);
double lng = Convert.ToDouble(parts[6]);
-
+
Coordinate c = new Coordinate(lat, lng, el);
//skip 80-84 due to Earthpoint using different UTM zone returns. Both methods are accurate and test against EarthPoint, but will cause test to fail.
if (lat >= 80 && lat <= 84) { continue; }
if (Math.Abs(lat) >= 89.99999) { continue; } //Dont test as long doesn't exist at pole.
-
+
//CONVERT BACK TEST
double precision = .0000001; //1.1 CM Convert Back Precision
Coordinate bc = UniversalTransverseMercator.ConvertUTMtoLatLong(c.UTM, new EagerLoad(false));
-
+
double l = c.Latitude.ToDouble();
double bL = bc.Latitude.ToDouble();
//IGNORE 360 values as that equals 0 degrees
Assert.IsFalse(Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360, "Latitude value not expected.");
-
-
+
+
l = c.Longitude.ToDouble();
bL = bc.Longitude.ToDouble();
//IGNORE 360 values as that equals 0 degrees
Assert.IsFalse(Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360, "Longitude value not expected.");
}
-
+
}
///
@@ -645,7 +686,7 @@ public void MGRS_Polar_To_Geodetic_Conversions()
double lat = Convert.ToDouble(parts[5]);
double lng = Convert.ToDouble(parts[6]);
-
+
Coordinate c = new Coordinate(lat, lng, el);
//skip 80-84 due to Earthpoint using different UTM zone returns. Both methods are accurate and test against EarthPoint, but will cause test to fail.
@@ -656,7 +697,7 @@ public void MGRS_Polar_To_Geodetic_Conversions()
//CONVERT BACK TEST
double precision = .0000001; //1.1 CM Convert Back Precision
-
+
precision = .0003;
if (Math.Abs(c.Latitude.ToDouble()) > 89) { precision = .002; }
else if (Math.Abs(c.Latitude.ToDouble()) > 88) { precision = .0006; }
@@ -764,7 +805,7 @@ public void MGRS_Ellipsoid_Conversions()
Assert.AreEqual(c.MGRS.Northing, 05228, 1, "MGRS Northing does not match WGS84 expected");
}
-
+
///
/// Asserts conversions
///
@@ -774,7 +815,7 @@ private void Assert_Geodetic_Conversion(string[] expecteds, CoordinateFormatOpti
{
int x = 0;
List coordinates = new List() { tc1, tc2, tc3, tc4 };
-
+
foreach (string expected in expecteds)
{
diff --git a/CoordinateSharp_UnitTests/Coordinate_Initialization_Tests.cs b/CoordinateSharp_UnitTests/Coordinate_Initialization_Tests.cs
index acbe4a14..5a04950f 100644
--- a/CoordinateSharp_UnitTests/Coordinate_Initialization_Tests.cs
+++ b/CoordinateSharp_UnitTests/Coordinate_Initialization_Tests.cs
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using CoordinateSharp;
+using NuGet.Frameworks;
namespace CoordinateSharp_UnitTests
{
@@ -380,16 +381,29 @@ public void Global_Settings_Initialization_Check()
{
GlobalSettings.Default_CoordinateFormatOptions = new CoordinateFormatOptions() { Format = CoordinateFormatType.Decimal };
GlobalSettings.Default_EagerLoad = new EagerLoad(false);
+ GlobalSettings.Default_Cartesian_Type = CartesianType.ECEF;
+ GlobalSettings.Default_Parsable_Formats = Allowed_Parse_Format.Lat_Long | Allowed_Parse_Format.MGRS;
+ GlobalSettings.Set_DefaultDatum(Earth_Ellipsoid_Spec.Airy_1830);
+
+ Earth_Ellipsoid ee = Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.WGS84_1984);
Coordinate c = new Coordinate(25, 25);
//Ensure setting took
Assert.AreEqual("25 25", c.ToString());
Assert.AreEqual(null, c.CelestialInfo);
-
+ Assert.AreNotEqual(ee.Equatorial_Radius, c.Equatorial_Radius);
+ Assert.AreNotEqual(ee.Inverse_Flattening, c.Inverse_Flattening);
+ Assert.ThrowsException(()=> { Coordinate.Parse("10T 573104mE 5249221mN"); });
+
//Reset to continue tests
GlobalSettings.Default_CoordinateFormatOptions = new CoordinateFormatOptions() { Format = CoordinateFormatType.Degree_Minutes_Seconds };
GlobalSettings.Default_EagerLoad = new EagerLoad(true);
+ GlobalSettings.Default_Parsable_Formats = Allowed_Parse_Format.Lat_Long | Allowed_Parse_Format.MGRS | Allowed_Parse_Format.UTM |
+ Allowed_Parse_Format.Cartesian_ECEF | Allowed_Parse_Format.Cartesian_Spherical |
+ Allowed_Parse_Format.WebMercator | Allowed_Parse_Format.GEOREF;
+ GlobalSettings.Set_DefaultDatum(Earth_Ellipsoid_Spec.WGS84_1984);
+ GlobalSettings.Default_Cartesian_Type = CartesianType.Cartesian; //If not reverted other test will fail.
}
///
diff --git a/CoordinateSharp_UnitTests/EagerLoading_Extensions.cs b/CoordinateSharp_UnitTests/EagerLoading_Extensions.cs
index 5a855e4d..87579d21 100644
--- a/CoordinateSharp_UnitTests/EagerLoading_Extensions.cs
+++ b/CoordinateSharp_UnitTests/EagerLoading_Extensions.cs
@@ -16,12 +16,12 @@ public void EagerLoading_Ext_Intializes_On()
{
EagerLoad e = new EagerLoad();
e.Extensions = new EagerLoad_Extensions();
- Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 2), e);
+ Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 22), e);
//Check extension properties to ensure proper loading
Assert.AreNotEqual(null, c.CelestialInfo.SunSet);//Solar Cycle
Assert.AreNotEqual(null, c.CelestialInfo.MoonSet);//Lunar Cycle
- Assert.AreNotEqual(null, c.CelestialInfo.AstrologicalSigns.MoonName);//Zodiac
+ Assert.AreNotEqual(AstrologicalSignType.None, c.CelestialInfo.AstrologicalSigns.MoonName);//Zodiac
Assert.AreNotEqual(null, c.CelestialInfo.LunarEclipse.LastEclipse.Type);//Lunar Cycle
Assert.AreNotEqual(null, c.CelestialInfo.SolarEclipse.LastEclipse.Type);//Solar Cycle
Assert.AreNotEqual(null, c.CelestialInfo.Solstices.Summer);//Lunar Cycle
@@ -170,12 +170,14 @@ public void Zodiac_Extension_On()
{
EagerLoad e = new EagerLoad(true);
e.Extensions = new EagerLoad_Extensions(false);
- Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 2), e);
+ Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 21), e);
e.Extensions.Zodiac = true;
c.Latitude.DecimalDegree++; //Trigger proper changes to confirm objects remain unloaded
c.Longitude.DecimalDegree++; //Trigger proper changes to confirm objects remain unloaded
+ c.GeoDate = new DateTime(2008, 1, 22); //Trigger date to ensure moon sign correct.
Assert.AreNotEqual(null, c.CelestialInfo.AstrologicalSigns.MoonName);//Zodiac
+ Assert.AreNotEqual(AstrologicalSignType.None, c.CelestialInfo.AstrologicalSigns.MoonName);//Zodiac
Assert.AreEqual(null, c.CelestialInfo.SunSet);//Solar Cycle
Assert.AreEqual(null, c.CelestialInfo.MoonSet);//Lunar Cycle