Beispiel #1
0
        public void MGRS_Initializes_Without_Exceptions()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264);

            mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264, 6378160.000, 298.25);
            mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264);
            mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264, 6378160.000, 298.25);
            //ADD MGRS POLAR
        }
        public void GZJ_Box_Left_Pointed_Ascending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("14J", "JT", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("14J", "JT", 97888, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"14J JT 97888 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("14J", "JT", 99999, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"14J JT 99999 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("14J", "JT", 95687, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"14J JT 95687 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("14J", "JT", 99999, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"14J JT 99999 99999\"     {gb.Top_Right_MGRS_Point}");
        }
Beispiel #3
0
        private void MGRS_Parse_Checks(string val)
        {
            //Ensures parse success only. Values are compared in normal parser
            var    vals        = val.Split('#');
            string coordString = vals[0];

            MilitaryGridReferenceSystem.Parse(coordString);
            MilitaryGridReferenceSystem.Parse(coordString, Earth_Ellipsoid_Spec.WGS72_1972);
            MilitaryGridReferenceSystem.Parse(coordString, 6378137, 298.257222101);
        }
        public void GZJ_Box_Right_Pointed_Ascending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("13J", "HN", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13J", "HN", 0, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"13J HN 00000 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13J", "HN", 02112, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"13J HN 02112 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13J", "HN", 00000, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"13J HN 00000 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13J", "HN", 04313, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"13J HN 04313 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void GZJ_Box_Right_Descending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("18L", "ZN", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("18L", "ZN", 0, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"18L ZN 00000 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("18L", "ZN", 27020, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"18L ZN 27020 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("18L", "ZN", 00000, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"18L ZN 00000 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("18L", "ZN", 28046, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"18L ZN 28046 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void GZJ_Box_Left_Descending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("19L", "AH", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("19L", "AH", 72980, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"19L AH 72980 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("19L", "AH", 99999, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"19L AH 99999 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("19L", "AH", 71954, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"19L AH 71954 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("19L", "AH", 99999, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"19L AH 99999 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void GZJ_Box_Left_Ascending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("5Q", "JC", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("5Q", "JC", 85819, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"5Q JC 85819 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("5Q", "JC", 99999, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"5Q JC 99999 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("5Q", "JC", 87639, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"5Q JC 87639 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("5Q", "JC", 99999, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"5Q JC 99999 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void GZJ_Box_Right_Ascending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("4Q", "HH", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("4Q", "HH", 0, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"4Q HH 00000 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("4Q", "HH", 14181, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"4Q HH 14181 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("4Q", "HH", 00000, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"4Q HH 00000 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("4Q", "HH", 12361, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"4Q HH 12361 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void Normal_Box_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("13S", "EA", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13S", "EA", 0, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"13S EA 00000 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13S", "EA", 99999, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"13S EA 99999 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13S", "EA", 00000, 99999), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"13S EA 00000 99999\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("13S", "EA", 99999, 99999), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"13S EA 99999 99999\"     {gb.Top_Right_MGRS_Point}");
        }
        public void GZJ_Box_Right_Pointed_Low_Ascending_Accuracy_Test()
        {
            MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("9U", "YV", 0, 0);
            var gb = mgrs.Get_Box_Boundaries();

            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("9U", "YV", 0, 0), gb.Bottom_Left_MGRS_Point), $"Bottom Left Corner Exceeds Delta: \"9U YV 00000 00000\"     {gb.Bottom_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("9U", "YV", 00320, 00000), gb.Bottom_Right_MGRS_Point), $"Bottom Right Corner Exceeds Delta: \"9U YV 00320 00000\"     {gb.Bottom_Right_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("9U", "YV", 00000, 07598), gb.Top_Left_MGRS_Point), $"Top Left Corner Exceeds Delta: \"9U YV 00000 07598\"     {gb.Top_Left_MGRS_Point}");
            Assert.IsTrue(MGRS_Comparer(new MilitaryGridReferenceSystem("9U", "YV", 00000, 07598), gb.Top_Right_MGRS_Point), $"Top Right Corner Exceeds Delta: \"9U YV 00000 07598\"     {gb.Top_Right_MGRS_Point}");
        }
Beispiel #11
0
        private void MGRS_TryParse_Checks(string val)
        {
            //Ensures parse success only. Values are compared in normal parser
            var    vals        = val.Split('#');
            string coordString = vals[0];
            MilitaryGridReferenceSystem mgrs;

            Assert.IsTrue(MilitaryGridReferenceSystem.TryParse(coordString, out mgrs), $"{coordString} MGRS cannot be parsed at TryParse 1.");
            Assert.IsTrue(MilitaryGridReferenceSystem.TryParse(coordString, Earth_Ellipsoid_Spec.WGS72_1972, out mgrs), $"{coordString} MGRS cannot be parsed at TryParse 2.");
            Assert.IsTrue(MilitaryGridReferenceSystem.TryParse(coordString, 6378137, 298.257222101, out mgrs), $"{coordString} MGRS cannot be parsed at TryParse 3.");
        }
        private static void MGRS_Init_Error_Checks()
        {
            bool pass = true;

            try
            {
                //Outputs 19T CE 51307 93264
                MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264);
                mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264, 6378160.000, 298.25);
                mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264);
                mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264, 6378160.000, 298.25);
            }
            catch { pass = false; }
            Pass.Write("MilitaryGridReferenceSytem Initialization Error Checks", pass);
        }
Beispiel #13
0
        public void MGRS_Polar_To_Geodetic_Conversions()
        {
            EagerLoad el = new EagerLoad(EagerLoadType.UTM_MGRS);

            foreach (var currentLine in polar_coordinates)
            {
                string[] parts = currentLine.Split(',');

                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


                precision = .0003;
                if (Math.Abs(c.Latitude.ToDouble()) > 89)
                {
                    precision = .002;
                }
                else if (Math.Abs(c.Latitude.ToDouble()) > 88)
                {
                    precision = .0006;
                }

                Coordinate bc = MilitaryGridReferenceSystem.MGRStoLatLong(c.MGRS, new EagerLoad(false));
                double     l  = c.Latitude.ToDouble();
                double     bL = bc.Latitude.ToDouble();
                Assert.IsFalse(Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360, "Longitude value not expected.");

                l  = c.Longitude.ToDouble();
                bL = bc.Longitude.ToDouble();
                Assert.IsFalse(Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360, "Longitude value not expected.");
            }
        }
Beispiel #14
0
        public void MGRS_Ellipsoid_Conversions()
        {
            MilitaryGridReferenceSystem mgrs = MilitaryGridReferenceSystem.Parse("16U EA 00872 05009", Earth_Ellipsoid_Spec.Clarke_1866);
            Coordinate c = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs, new EagerLoad(EagerLoadType.UTM_MGRS));

            //Check ellipsoid values carry
            Earth_Ellipsoid ee = Earth_Ellipsoid.Get_Ellipsoid(Earth_Ellipsoid_Spec.Clarke_1866);

            Assert.AreEqual(ee.Equatorial_Radius, c.Equatorial_Radius, "Equatorial Radius do not match");
            Assert.AreEqual(ee.Inverse_Flattening, c.Inverse_Flattening, "Inverse Flattening values do not match");

            Assert.AreEqual(mgrs.LongZone, c.MGRS.LongZone, "MGRS Long Zones do not match");
            Assert.AreEqual(mgrs.Digraph, c.MGRS.Digraph, "MGRS Designators do not match");
            Assert.AreEqual(mgrs.Easting, c.MGRS.Easting, 1, "MGRS Easting does not match");
            Assert.AreEqual(mgrs.Northing, c.MGRS.Northing, 1, "MGRS Northing does not match");

            c.Set_Datum(Earth_Ellipsoid_Spec.WGS84_1984);

            Assert.AreEqual(c.MGRS.Easting, 00872, 1, "MGRS Easting does not match WGS84 expected");
            Assert.AreEqual(c.MGRS.Northing, 05228, 1, "MGRS Northing does not match WGS84 expected");
        }
 private bool MGRS_Comparer(MilitaryGridReferenceSystem expected, MilitaryGridReferenceSystem actual)
 {
     if (expected.LatZone != actual.LatZone)
     {
         return(false);
     }
     if (expected.LongZone != actual.LongZone)
     {
         return(false);
     }
     if (expected.Digraph != actual.Digraph)
     {
         return(false);
     }
     if (Math.Abs(expected.Easting - actual.Easting) > 2)
     {
         return(false);
     }
     if (Math.Abs(expected.Northing - actual.Northing) > 2)
     {
         return(false);
     }
     return(true);
 }
Beispiel #16
0
        private static void Load_Call_Tests(Coordinate c)
        {
            //Check Load_Calls
            bool pass = true;

            c.LoadCelestialInfo();
            if (c.CelestialInfo == null)
            {
                pass = false;
            }
            c.LoadUTM_MGRS_Info();
            if (c.UTM == null)
            {
                pass = false;
            }
            if (c.MGRS == null)
            {
                pass = false;
            }
            c.LoadCartesianInfo();
            if (c.Cartesian == null)
            {
                pass = false;
            }
            c.LoadECEFInfo();
            if (c.ECEF == null)
            {
                pass = false;
            }
            Pass.Write("Load Calls (Celestial, UTM, MGRS, Cartesian, ECEF)", pass);
            if (pass)
            {
                Celestial cel = c.CelestialInfo;
                MilitaryGridReferenceSystem mgrs = c.MGRS;
                UniversalTransverseMercator utm  = c.UTM;
                Cartesian cart = c.Cartesian;
                ECEF      ecef = c.ECEF;

                c.Latitude.DecimalDegree  = -45;
                c.Longitude.DecimalDegree = -75;

                //Properties should not change.
                if (!ReflectiveEquals(c.CelestialInfo, cel))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.MGRS, mgrs))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.UTM, utm))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.Cartesian, cart))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.ECEF, ecef))
                {
                    pass = false;
                }
                //Properties should remain equal as no load calls were made
                Pass.Write("Property State Hold (Celestial, UTM, MGRS, Cartesian, ECEF)", pass);

                //Properties should change
                pass = true;
                c.LoadCelestialInfo();
                c.LoadCartesianInfo();
                c.LoadUTM_MGRS_Info();
                c.LoadECEFInfo();
                if (ReflectiveEquals(c.CelestialInfo, cel))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.MGRS, mgrs))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.UTM, utm))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.Cartesian, cart))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.ECEF, ecef))
                {
                    pass = false;
                }
                //Properties should not be equal as chages have been made
                Pass.Write("Property State Change (Celestial, UTM, MGRS, Cartesian, ECEF)", pass);
            }
            else
            {
                //Passes auto fail has properties didn't load when called.

                Pass.Write("Property State Hold (Celestial, UTM, MGRS, Cartesian, ECEF)", false);
                Pass.Write("Property State Change (Celestial, UTM, MGRS, Cartesian, ECEF)", false);
            }
        }
        private static void Run_Conversion_Passes(List <List <string> > Conversions)
        {
            //List of coordinates to test conversions against.
            List <double[]> coords = new List <double[]>();

            coords.Add(new double[] { 39.5768, 72.4859 });
            coords.Add(new double[] { -15.5768, 100.4859 });
            coords.Add(new double[] { 65.25, -15.1859 });
            coords.Add(new double[] { -80.659, -152.49 });
            for (int x = 0; x < Conversions.Count; x++)
            {
                List <string> coordList = Conversions[x];
                double        lat       = coords[x][0];
                double        lng       = coords[x][1];
                //0 = Decimal / Signed
                //1 = Decimal Degree
                //2 = Degree Decimal Minute
                //3 = Degree Minutes Seconds
                //4 = UTM
                //5 = MGRS
                //6 = Cartesian
                //7 = ECEF
                Coordinate c    = new Coordinate(lat, lng);
                bool       pass = true;
                Coordinate rc   = new Coordinate();
                for (int y = 0; y < 8; y++)
                {
                    switch (y)
                    {
                    case 0:
                        c.FormatOptions.Format = CoordinateFormatType.Decimal;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        break;

                    case 1:
                        c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        break;

                    case 2:
                        c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        rc           = new Coordinate();
                        rc.Latitude  = new CoordinatePart(c.Latitude.Degrees, c.Latitude.DecimalMinute, c.Latitude.Position);
                        rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.DecimalMinute, c.Longitude.Position);
                        if (rc.Latitude.ToDouble() != c.Latitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (rc.Longitude.ToDouble() != c.Longitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 3:
                        c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        rc           = new Coordinate();
                        rc.Latitude  = new CoordinatePart(c.Latitude.Degrees, c.Latitude.Minutes, c.Latitude.Seconds, c.Latitude.Position);
                        rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.Minutes, c.Longitude.Seconds, c.Longitude.Position);
                        if (rc.Latitude.ToDouble() != c.Latitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (rc.Longitude.ToDouble() != c.Longitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 4:
                        if (c.UTM.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        UniversalTransverseMercator utm = new UniversalTransverseMercator(c.UTM.LatZone, c.UTM.LongZone, c.UTM.Easting, c.UTM.Northing);
                        rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm);

                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }

                        //SIGNED DEGREE METHOD
                        double[] sd = UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm);
                        if (Math.Abs(sd[0] - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(sd[1] - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }


                        //OVERLOAD METHOD
                        utm = new UniversalTransverseMercator(c.UTM.LongZone + c.UTM.LatZone.ToString(), c.UTM.Easting, c.UTM.Northing);
                        rc  = UniversalTransverseMercator.ConvertUTMtoLatLong(utm);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }



                        break;

                    case 5:
                        if (c.MGRS.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem(c.MGRS.LatZone, c.MGRS.LongZone, c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing);
                        rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }

                        //SIGNED DEGREE METHOD
                        double[] sdM = MilitaryGridReferenceSystem.MGRStoSignedDegree(mgrs);
                        if (Math.Abs(sdM[0] - c.Latitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(sdM[1] - c.Longitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }


                        //OVERLOAD METHOD
                        mgrs = new MilitaryGridReferenceSystem(c.MGRS.LongZone + c.MGRS.LatZone.ToString(), c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing);
                        rc   = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }

                        break;

                    case 6:
                        if (c.Cartesian.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        Cartesian cart = new Cartesian(c.Cartesian.X, c.Cartesian.Y, c.Cartesian.Z);
                        rc = Cartesian.CartesianToLatLong(cart);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 7:
                        string ec = c.ECEF.ToString().Replace(" km", "").Replace(",", "");
                        if (ec != coordList[y])
                        {
                            pass = false;
                        }
                        ECEF ecef = new ECEF(c.ECEF.X, c.ECEF.Y, c.ECEF.Z);
                        rc = ECEF.ECEFToLatLong(ecef);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        if (Math.Abs(rc.ECEF.GeoDetic_Height.Meters - c.ECEF.GeoDetic_Height.Meters) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    default:
                        break;
                    }
                }
                Pass.Write("Conversion Pass " + ((int)(x + 1)).ToString() + ": ", pass);
            }
        }
        private static void Check_UPS_MGRS_Polar()
        {
            bool      pass = true;
            EagerLoad el   = new EagerLoad(EagerLoadType.UTM_MGRS);

            Console.WriteLine();
            Console.WriteLine("...Checking Polar Regions (this may take a minute)");
            Console.WriteLine();

            using (StreamReader sr = new StreamReader("CoordinateData\\UPS.csv"))
            {
                string currentLine;
                // currentLine will be null when the StreamReader reaches the end of file
                while ((currentLine = sr.ReadLine()) != null)
                {
                    string[] parts = currentLine.Split(',');

                    double lat = Convert.ToDouble(parts[5]);
                    double lng = Convert.ToDouble(parts[6]);

                    string utm      = parts[0];
                    string mgrs     = parts[4];
                    string zone     = parts[1];
                    int    easting  = Convert.ToInt32(parts[2]);
                    int    northing = Convert.ToInt32(parts[3]);

                    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.
                    if (string.Format("{0}{1}", c.UTM.LongZone, c.UTM.LatZone) != zone)
                    {
                        pass = false; break;
                    }
                    if (Math.Abs(c.UTM.Easting - easting) > 1)
                    {
                        pass = false; break;
                    }
                    if (Math.Abs(c.UTM.Northing - northing) > 1)
                    {
                        pass = false; break;
                    }
                    string nMgrs = c.MGRS.ToString().Replace(" ", "");
                    if (nMgrs != mgrs)
                    {
                        pass = false; break;
                    }
                    if (Math.Abs(c.UTM.Easting - easting) > 1)
                    {
                        pass = false; break;
                    }
                    if (Math.Abs(c.UTM.Northing - northing) > 1)
                    {
                        pass = false; break;
                    }

                    //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
                    if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360)
                    {
                        pass = false; break;
                    }
                    l  = c.Longitude.ToDouble();
                    bL = bc.Longitude.ToDouble();
                    if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360)
                    {
                        pass = false; break;
                    }

                    precision = .0003;
                    if (Math.Abs(c.Latitude.ToDouble()) > 89)
                    {
                        precision = .002;
                    }
                    else if (Math.Abs(c.Latitude.ToDouble()) > 88)
                    {
                        precision = .0006;
                    }

                    bc = MilitaryGridReferenceSystem.MGRStoLatLong(c.MGRS, new EagerLoad(false));
                    l  = c.Latitude.ToDouble();
                    bL = bc.Latitude.ToDouble();
                    if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360)
                    {
                        pass = false; break;
                    }
                    l  = c.Longitude.ToDouble();
                    bL = bc.Longitude.ToDouble();
                    if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360)
                    {
                        pass = false; break;
                    }
                }
            }


            Pass.Write("UPS MGRS Polar Conversions: ", pass);
        }
Beispiel #19
0
        static void EagerLoading_Tests()
        {
            EagerLoad  e = new EagerLoad(false);
            Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 2), e);
            //Check to make sure items don't initialize
            bool pass = true;

            if (c.CelestialInfo != null)
            {
                pass = false;
            }
            if (c.UTM != null)
            {
                pass = false;
            }
            if (c.MGRS != null)
            {
                pass = false;
            }
            if (c.Cartesian != null)
            {
                pass = false;
            }
            Write_Pass("Null Properties (Celestial, UTM, MGRS, Cartesian)", pass);

            //Check Load_Calls
            pass = true;
            c.LoadCelestialInfo();
            if (c.CelestialInfo == null)
            {
                pass = false;
            }
            c.LoadUTM_MGRS_Info();
            if (c.UTM == null)
            {
                pass = false;
            }
            if (c.MGRS == null)
            {
                pass = false;
            }
            c.LoadCartesianInfo();
            if (c.Cartesian == null)
            {
                pass = false;
            }
            Write_Pass("Load Calls (Celestial, UTM, MGRS, Cartesian)", pass);

            if (pass)
            {
                Celestial cel = c.CelestialInfo;
                MilitaryGridReferenceSystem mgrs = c.MGRS;
                UniversalTransverseMercator utm  = c.UTM;
                Cartesian cart = c.Cartesian;

                c.Latitude.DecimalDegree  = -45;
                c.Longitude.DecimalDegree = -75;

                //Properties should not change.
                if (!ReflectiveEquals(c.CelestialInfo, cel))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.MGRS, mgrs))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.UTM, utm))
                {
                    pass = false;
                }
                if (!ReflectiveEquals(c.Cartesian, cart))
                {
                    pass = false;
                }
                //Properties should remain equal as no load calls were made
                Write_Pass("Property State Hold (Celestial, UTM, MGRS, Cartesian)", pass);

                //Properties should change
                pass = true;
                c.LoadCelestialInfo();
                c.LoadCartesianInfo();
                c.LoadUTM_MGRS_Info();
                if (ReflectiveEquals(c.CelestialInfo, cel))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.MGRS, mgrs))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.UTM, utm))
                {
                    pass = false;
                }
                if (ReflectiveEquals(c.Cartesian, cart))
                {
                    pass = false;
                }
                //Properties should not be equal as chages have been made
                Write_Pass("Property State Change (Celestial, UTM, MGRS, Cartesian)", pass);
            }
            else
            {
                //Passes auto fail has properties didn't load when called.

                Write_Pass("Property State Hold (Celestial, UTM, MGRS, Cartesian)", false);
                Write_Pass("Property State Change (Celestial, UTM, MGRS, Cartesian)", false);
            }

            //EagerLoaded Flags Test
            EagerLoadType et = EagerLoadType.Cartesian | EagerLoadType.Celestial | EagerLoadType.Cartesian;
            EagerLoad     eg = new EagerLoad(et);

            pass = true;
            if (eg.Cartesian == false || eg.Celestial == false || eg.UTM_MGRS == false)
            {
                pass = false;
            }
            if (EagerLoad.Create(et).Cartesian == false || EagerLoad.Create(et).Celestial == false || EagerLoad.Create(et).UTM_MGRS == false)
            {
                pass = false;
            }
            Write_Pass("Flags Test", pass);
        }
Beispiel #20
0
        static void Coordinate_Initialization_Tests()
        {
            //Check for errors with initialization as most calculations occur on load
            bool pass = true;

            try
            {
                Coordinate c = new Coordinate();
                c = new Coordinate(25, 25);
                c = new Coordinate(25, 25, new DateTime(2018, 8, 5, 10, 10, 0));

                EagerLoad eg = new EagerLoad();
                eg.Cartesian = false;
                eg.Celestial = false;
                eg.UTM_MGRS  = false;

                c = new Coordinate(eg);
                c = new Coordinate(25, 25, eg);
                c = new Coordinate(25, 25, new DateTime(2018, 8, 5, 10, 10, 0), eg);
            }
            catch { pass = false; }
            Write_Pass("Coordinate Initialization Error Checks", pass);

            try
            {
                pass = true;
                Coordinate     c  = new Coordinate();
                CoordinatePart cp = new CoordinatePart(CoordinateType.Lat, c);
                cp = new CoordinatePart(CoordinateType.Long, c);
                cp = new CoordinatePart(25, CoordinateType.Lat, c);
                cp = new CoordinatePart(25, CoordinateType.Long, c);
                cp = new CoordinatePart(25, 25, CoordinatesPosition.N, c);
                cp = new CoordinatePart(25, 25, CoordinatesPosition.E, c);
                cp = new CoordinatePart(25, 25, CoordinatesPosition.S, c);
                cp = new CoordinatePart(25, 25, CoordinatesPosition.W, c);
                cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.N, c);
                cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.E, c);
                cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.S, c);
                cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.W, c);
            }
            catch { pass = false; }
            Write_Pass("CoordinatePart Initialization Error Checks", pass);
            try
            {
                pass = true;
                UniversalTransverseMercator utm = new UniversalTransverseMercator("Q", 14, 581943.5, 2111989.8);
                utm = new UniversalTransverseMercator("Q", 14, 581943.5, 2111989.8, 6378160.000, 298.25);
            }
            catch { pass = false; }
            Write_Pass("UniversalTransverseMercator Initialization Error Checks", pass);
            try
            {
                pass = true;
                //Outputs 19T CE 51307 93264
                MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264);
                mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264, 6378160.000, 298.25);
            }
            catch { pass = false; }
            Write_Pass("UniversalTransverseMercator Initialization Error Checks", pass);
            try
            {
                pass = true;
                Coordinate c    = new Coordinate();
                Cartesian  cart = new Cartesian(c);
                cart = new Cartesian(345, -123, 2839);
            }
            catch { pass = false; }
            Write_Pass("Cartesian Initialization Error Checks", pass);
            Console.WriteLine();

            //Init Range Checks
            try
            {
                pass = true;
                EagerLoad eg = new EagerLoad();

                Coordinate c = new Coordinate(90, 180);
                c = new Coordinate(-90, -180);
                c = new Coordinate(90, 180, new DateTime());
                c = new Coordinate(-90, -180, new DateTime());
                c = new Coordinate(90, 180, eg);
                c = new Coordinate(-90, -180, eg);
                c = new Coordinate(90, 180, new DateTime(), eg);
                c = new Coordinate(-90, -180, new DateTime(), eg);

                //Should fail as arguments are out of range.
                try { c = new Coordinate(91, 180); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(90, 181); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-91, -180); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-90, -181); pass = false; }
                catch { }

                //Should fail as arguments are out of range.
                try { c = new Coordinate(91, 180, new DateTime()); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(90, 181, new DateTime()); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-91, -180, new DateTime()); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-90, -181, new DateTime()); pass = false; }
                catch {  }

                //Should fail as arguments are out of range.
                try { c = new Coordinate(91, 180, new DateTime(), eg); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(90, 181, new DateTime(), eg); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-91, -180, new DateTime(), eg); pass = false; }
                catch { }
                //Should fail as arguments are out of range.
                try { c = new Coordinate(-90, -181, new DateTime(), eg); pass = false; }
                catch { }
            }
            catch { pass = false; }
            Write_Pass("Cordinate Initialization Range Checks", pass);

            pass = true;
            try
            {
                Coordinate     c  = new Coordinate();
                CoordinatePart cp = new CoordinatePart(90, CoordinateType.Lat, c);
                cp = new CoordinatePart(-90, CoordinateType.Lat, c);
                cp = new CoordinatePart(89, 59, CoordinatesPosition.N, c);
                cp = new CoordinatePart(89, 59, CoordinatesPosition.S, c);
                cp = new CoordinatePart(89, 59, 59, CoordinatesPosition.N, c);
                cp = new CoordinatePart(89, 59, 59, CoordinatesPosition.S, c);
                cp = new CoordinatePart(180, CoordinateType.Long, c);
                cp = new CoordinatePart(-180, CoordinateType.Long, c);
                cp = new CoordinatePart(179, 59, CoordinatesPosition.E, c);
                cp = new CoordinatePart(179, 59, CoordinatesPosition.W, c);
                cp = new CoordinatePart(179, 59, 59, CoordinatesPosition.E, c);
                cp = new CoordinatePart(179, 59, 59, CoordinatesPosition.W, c);

                //Should fail
                try { cp = new CoordinatePart(91, CoordinateType.Lat, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-91, CoordinateType.Lat, c); pass = false; } catch { }
                try { cp = new CoordinatePart(181, CoordinateType.Long, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-181, CoordinateType.Long, c); pass = false; } catch { }

                try { cp = new CoordinatePart(91, 0, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 1, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 60, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(91, 0, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 1, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 60, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-90, 1, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, -1, CoordinatesPosition.N, c); pass = false; } catch { }

                try { cp = new CoordinatePart(91, 0, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 1, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 60, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(91, 0, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 1, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 60, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-90, 1, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, -1, CoordinatesPosition.S, c); pass = false; } catch { }

                try { cp = new CoordinatePart(91, 0, 0, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-90, 0, 0, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, -1, 0, CoordinatesPosition.N, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 1, -1, CoordinatesPosition.N, c); pass = false; } catch { }

                try { cp = new CoordinatePart(91, 0, 0, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-90, 0, 0, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, -1, 0, CoordinatesPosition.S, c); pass = false; } catch { }
                try { cp = new CoordinatePart(89, 1, -1, CoordinatesPosition.S, c); pass = false; } catch { }


                try { cp = new CoordinatePart(181, 0, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 1, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 60, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(181, 0, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 1, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 60, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-180, 1, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, -1, CoordinatesPosition.E, c); pass = false; } catch { }

                try { cp = new CoordinatePart(181, 0, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 1, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 60, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(181, 0, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 1, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 60, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-180, 1, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, -1, CoordinatesPosition.W, c); pass = false; } catch { }

                try { cp = new CoordinatePart(181, 0, 0, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-180, 0, 0, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, -1, 0, CoordinatesPosition.E, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 1, -1, CoordinatesPosition.E, c); pass = false; } catch { }

                try { cp = new CoordinatePart(181, 0, 0, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(-180, 0, 0, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, -1, 0, CoordinatesPosition.W, c); pass = false; } catch { }
                try { cp = new CoordinatePart(179, 1, -1, CoordinatesPosition.W, c); pass = false; } catch { }
            }
            catch
            {
                pass = false;
            }
            Write_Pass("CordinatePart Initialization Range Checks", pass);
        }
Beispiel #21
0
        static void Coordinate_Convsersions_Tests()
        {
            Console.WriteLine();
            //GATHER CONVERSIONS
            //Conversion lists must end in //** to signify end of list
            List <List <string> > Conversions = new List <List <string> >();

            string[]      coordStrings = File.ReadAllLines("Conversions.txt");
            List <string> cList        = new List <string>();

            foreach (string c in coordStrings)
            {
                if (c == "//**")
                {
                    Conversions.Add(cList);
                    cList = new List <string>();
                }
                else
                {
                    cList.Add(c);
                }
            }
            //Conversion coords to test
            List <double[]> coords = new List <double[]>();

            coords.Add(new double[] { 39.5768, 72.4859 });
            coords.Add(new double[] { -15.5768, 100.4859 });
            coords.Add(new double[] { 65.25, -15.1859 });
            coords.Add(new double[] { -80.6586, -152.49 });

            for (int x = 0; x < Conversions.Count; x++)
            {
                List <string> coordList = Conversions[x];
                double        lat       = coords[x][0];
                double        lng       = coords[x][1];
                //0 = Decimal / Signed
                //1 = Decimal Degree
                //2 = Degree Decimal Minute
                //3 = Degree Minutes Seconds
                //4 = UTM
                //5 = MGRS
                //6 = Cartesian
                Coordinate c    = new Coordinate(lat, lng);
                bool       pass = true;
                Coordinate rc   = new Coordinate();
                for (int y = 0; y < 7; y++)
                {
                    switch (y)
                    {
                    case 0:
                        c.FormatOptions.Format = CoordinateFormatType.Decimal;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        break;

                    case 1:
                        c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        break;

                    case 2:
                        c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        rc           = new Coordinate();
                        rc.Latitude  = new CoordinatePart(c.Latitude.Degrees, c.Latitude.DecimalMinute, c.Latitude.Position, rc);
                        rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.DecimalMinute, c.Longitude.Position, rc);
                        if (rc.Latitude.ToDouble() != c.Latitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (rc.Longitude.ToDouble() != c.Longitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 3:
                        c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds;
                        if (c.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        rc           = new Coordinate();
                        rc.Latitude  = new CoordinatePart(c.Latitude.Degrees, c.Latitude.Minutes, c.Latitude.Seconds, c.Latitude.Position, rc);
                        rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.Minutes, c.Longitude.Seconds, c.Longitude.Position, rc);
                        if (rc.Latitude.ToDouble() != c.Latitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (rc.Longitude.ToDouble() != c.Longitude.ToDouble())
                        {
                            pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 4:
                        if (c.UTM.ToString() != coordList[y] && c.UTM.WithinCoordinateSystemBounds)
                        {
                            pass = false;
                        }
                        UniversalTransverseMercator utm = new UniversalTransverseMercator(c.UTM.LatZone, c.UTM.LongZone, c.UTM.Easting, c.UTM.Northing);
                        rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001 && c.UTM.WithinCoordinateSystemBounds)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001 && c.UTM.WithinCoordinateSystemBounds)
                        {
                            pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    case 5:
                        if (c.MGRS.ToString() != coordList[y] && c.MGRS.WithinCoordinateSystemBounds)
                        {
                            pass = false;
                        }
                        MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem(c.MGRS.LatZone, c.MGRS.LongZone, c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing);
                        rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001 && c.MGRS.WithinCoordinateSystemBounds)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001 && c.MGRS.WithinCoordinateSystemBounds)
                        {
                            pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }

                        break;

                    case 6:
                        if (c.Cartesian.ToString() != coordList[y])
                        {
                            pass = false;
                        }
                        Cartesian cart = new Cartesian(c.Cartesian.X, c.Cartesian.Y, c.Cartesian.Z);
                        rc = Cartesian.CartesianToLatLong(cart);
                        if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble());
                        }
                        if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001)
                        {
                            pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble());
                        }
                        break;

                    default:
                        break;
                    }
                }

                Write_Pass("Conversion Pass " + ((int)(x + 1)).ToString() + ": ", pass);
            }

            //UTM MGRS BOUNDARY CHECK
            bool       p  = true;
            Coordinate cr = new Coordinate(-79.99, 0);

            if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds)
            {
                p = false;
            }
            cr.Latitude.DecimalDegree = -80;
            if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds)
            {
                p = false;
            }
            cr.Latitude.DecimalDegree = 83.99;
            if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds)
            {
                p = false;
            }
            cr.Latitude.DecimalDegree = 84;
            if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds)
            {
                p = false;
            }
            Write_Pass("UTM MGRS BOUNDARY CHECK", p);
        }
Beispiel #22
0
        private void GenerateGrid()
        {
            this.External.Grid = new Dictionary <String, List <Dictionary <String, List <Double> > > > {
                { "Major", new List <Dictionary <String, List <Double> > >() },
                { "Minor", new List <Dictionary <String, List <Double> > >() }
            };
            if (this.External.Startloclat == 0 || this.External.Startloclon == 0 || this.gridradius == 0)
            {
                return;
            }
            MilitaryGridReferenceSystem start = new Coordinate(this.External.Startloclat, this.External.Startloclon).MGRS;

            Double left   = start.Easting - this.gridradius - (start.Easting - this.gridradius) % 100;
            Double bottom = start.Northing - this.gridradius - (start.Northing - this.gridradius) % 100;
            Double right  = start.Easting + this.gridradius + (100 - (start.Easting + this.gridradius) % 100);
            Double top    = start.Northing + this.gridradius + (100 - (start.Northing + this.gridradius) % 100);

            for (Double i = left; i <= right; i += 50)
            {
                Coordinate TopLeft    = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, i, top));
                Coordinate BottomLeft = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, i, bottom));
                if (i % 100 == 0)
                {
                    this.External.Grid["Major"].Add(new Dictionary <String, List <Double> > {
                        { "from", new List <Double> {
                              TopLeft.Latitude.DecimalDegree,
                              TopLeft.Longitude.DecimalDegree
                          } },
                        { "to", new List <Double> {
                              BottomLeft.Latitude.DecimalDegree,
                              BottomLeft.Longitude.DecimalDegree
                          } }
                    });
                }
                else
                {
                    this.External.Grid["Minor"].Add(new Dictionary <String, List <Double> > {
                        { "from", new List <Double> {
                              TopLeft.Latitude.DecimalDegree,
                              TopLeft.Longitude.DecimalDegree
                          } },
                        { "to", new List <Double> {
                              BottomLeft.Latitude.DecimalDegree,
                              BottomLeft.Longitude.DecimalDegree
                          } }
                    });
                }
            }
            for (Double i = bottom; i <= top; i += 50)
            {
                Coordinate BottomLeft  = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, left, i));
                Coordinate BottomRight = MilitaryGridReferenceSystem.MGRStoLatLong(new MilitaryGridReferenceSystem(start.LatZone, start.LongZone, start.Digraph, right, i));
                if (i % 100 == 0)
                {
                    this.External.Grid["Major"].Add(new Dictionary <String, List <Double> > {
                        { "from", new List <Double> {
                              BottomLeft.Latitude.DecimalDegree,
                              BottomLeft.Longitude.DecimalDegree
                          } },
                        { "to", new List <Double> {
                              BottomRight.Latitude.DecimalDegree,
                              BottomRight.Longitude.DecimalDegree
                          } }
                    });
                }
                else
                {
                    this.External.Grid["Minor"].Add(new Dictionary <String, List <Double> > {
                        { "from", new List <Double> {
                              BottomLeft.Latitude.DecimalDegree,
                              BottomLeft.Longitude.DecimalDegree
                          } },
                        { "to", new List <Double> {
                              BottomRight.Latitude.DecimalDegree,
                              BottomRight.Longitude.DecimalDegree
                          } }
                    });
                }
            }
        }