Skip to content

Commit 4f5918a

Browse files
authored
Merge pull request #143 from Tronald/develop
MGRS Parser Bug Fix
2 parents 2e94ca3 + fc3c8de commit 4f5918a

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

CoordinateSharp/CoordinateSharp.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ For more information, please contact Signature Group, LLC at this address: sales
4747
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1;</TargetFrameworks>
4848
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4949
<GenerateDocumentationFile>true</GenerateDocumentationFile>
50-
<Version>2.6.1.1</Version>
50+
<Version>2.6.2.1</Version>
5151
<Authors>Signature Group, LLC</Authors>
5252
<Company />
5353
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
5454
<PackageLicenseUrl></PackageLicenseUrl>
5555
<Copyright>Copyright 2020</Copyright>
5656
<Description>A simple library designed to assist with geographic coordinate conversions, formatting and location based solar and lunar information.</Description>
57-
<PackageReleaseNotes>Adds a strong named key to the assembly for strong named application compatability.</PackageReleaseNotes>
57+
<PackageReleaseNotes>Fixes parser bug occurring with less precise UTM/MGRS coordinate strings.</PackageReleaseNotes>
5858
<PackageTags>CoordinateSharp Latitude Longitude Coordinates Geography Sun Moon Solar Lunar Time MGRS UTM Julian ECEF Sunset Sunrise Set Moonset Moonrise</PackageTags>
5959
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
6060
<PackageLicenseFile>License.txt</PackageLicenseFile> <PackageIconUrl></PackageIconUrl>
6161
<PackageId>CoordinateSharp</PackageId>
6262
<Title>CoordinateSharp</Title>
63-
<AssemblyVersion>2.6.1.1</AssemblyVersion>
63+
<AssemblyVersion>2.6.2.1</AssemblyVersion>
6464
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
6565
<SignAssembly>true</SignAssembly>
6666
<PackageIcon>CoordinateSharpPNG.png</PackageIcon>

CoordinateSharp/Parsers/Coordinate Formats/MGRS.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Organizations or use cases that fall under the following conditions may receive
4646
using System.Text.RegularExpressions;
4747
using System.Linq;
4848
using System.Globalization;
49+
using System.Diagnostics;
4950

5051
namespace CoordinateSharp
5152
{
@@ -82,7 +83,7 @@ private static bool TryMGRS(string s, out string[] mgrs)
8283
string easting = eastingNorthing.Substring(0, (int)(eastingNorthing.Length / 2));
8384
string northing = eastingNorthing.Substring((int)(eastingNorthing.Length / 2), (int)(eastingNorthing.Length / 2));
8485

85-
mgrs = new string[] { longZone, latZone, identifier, easting, northing };
86+
mgrs = new string[] { longZone, latZone, identifier, easting.PadRight(5, '0'), northing.PadRight(5, '0') };
8687
return true;
8788
}
8889

@@ -116,7 +117,9 @@ private static bool TryMGRS(string s, out string[] mgrs)
116117
if (!double.TryParse(sA[3], NumberStyles.Any, CultureInfo.InvariantCulture, out northing))
117118
{ return false; }
118119

119-
mgrs = new string[] { zone.ToString(), zoneL, diagraph, easting.ToString(), northing.ToString() };
120+
121+
122+
mgrs = new string[] { zone.ToString(), zoneL, diagraph, sA[2].PadRight(5,'0'), sA[3].PadRight(5, '0') };
120123
return true;
121124
}
122125
return false;
@@ -159,7 +162,8 @@ private static bool TryMGRS_Polar(string s, out string[] mgrs)
159162
string easting = eastingNorthing.Substring(0, (int)(eastingNorthing.Length / 2));
160163
string northing = eastingNorthing.Substring((int)(eastingNorthing.Length / 2), (int)(eastingNorthing.Length / 2));
161164

162-
mgrs = new string[] { longZone, latZone, identifier, easting, northing };
165+
mgrs = new string[] { longZone, latZone, identifier, easting.PadRight(5, '0'), northing.PadRight(5, '0') };
166+
163167
return true;
164168
}
165169

@@ -193,7 +197,8 @@ private static bool TryMGRS_Polar(string s, out string[] mgrs)
193197
if (!double.TryParse(sA[3], NumberStyles.Any, CultureInfo.InvariantCulture, out northing))
194198
{ return false; }
195199

196-
mgrs = new string[] { zone.ToString(), zoneL, diagraph, easting.ToString(), northing.ToString() };
200+
mgrs = new string[] { zone.ToString(), zoneL, diagraph, sA[2].PadRight(5, '0'), sA[3].PadRight(5, '0') };
201+
197202
return true;
198203
}
199204
return false;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<PublishUrlHistory>publish\</PublishUrlHistory>
5+
<InstallUrlHistory />
6+
<SupportUrlHistory />
7+
<UpdateUrlHistory />
8+
<BootstrapperUrlHistory />
9+
<ErrorReportUrlHistory />
10+
<FallbackCulture>en-US</FallbackCulture>
11+
<VerifyUploadedFiles>false</VerifyUploadedFiles>
12+
</PropertyGroup>
13+
</Project>

CoordinateSharp_TestProj/Coordinate_Parser_Tests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ private static void Coordinate_Parses_Test()
8383
{
8484
Pass.Write(lastType.Split(',')[0], pass);
8585
}
86-
86+
//MGRS LESS PRECISE PARSE
87+
Console.WriteLine();
88+
pass = true;
89+
var precise = Coordinate.Parse("16REU6070");
90+
if(precise.MGRS.ToString() != "16R EU 60000 70000") { pass = false; }
91+
precise = Coordinate.Parse("ZBE6611");
92+
if (precise.MGRS.ToString() != "Z BE 65999 11000") { pass = false; Debug.WriteLine(precise.MGRS); }
93+
Pass.Write("\\MGRS Less Precise Parse", pass);
8794
//Attempt Forces Param
8895
pass = true;
8996
try

0 commit comments

Comments
 (0)