Beispiel #1
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 #2
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 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 #5
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 #6
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
                          } }
                    });
                }
            }
        }