Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the two-dimensional path from
        ///    Lincoln Memorial in Washington, D.C --> 38.8892N, 77.04978W
        ///         to
        ///    Eiffel Tower in Paris --> 48.85889N, 2.29583E
        ///         using
        ///    WGS84 reference ellipsoid
        /// </summary>
        static void TwoDimensionalInverseCalculation()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Lincoln Memorial coordinates
            GlobalCoordinates lincolnMemorial;

            lincolnMemorial = new GlobalCoordinates(
                new Angle(38.88922), new Angle(-77.04978)
                );

            // set Eiffel Tower coordinates
            GlobalCoordinates eiffelTower;

            eiffelTower = new GlobalCoordinates(
                new Angle(48.85889), new Angle(2.29583)
                );

            // calculate the geodetic curve
            GeodeticCurve geoCurve          = geoCalc.CalculateGeodeticCurve(reference, lincolnMemorial, eiffelTower);
            double        ellipseKilometers = geoCurve.EllipsoidalDistance / 1000.0;
            double        ellipseMiles      = ellipseKilometers * 0.621371192;

            Console.WriteLine("2-D path from Lincoln Memorial to Eiffel Tower using WGS84");
            Console.WriteLine("   Ellipsoidal Distance: {0:0.00} kilometers ({1:0.00} miles)", ellipseKilometers, ellipseMiles);
            Console.WriteLine("   Azimuth:              {0:0.00} degrees", geoCurve.Azimuth.Degrees);
            Console.WriteLine("   Reverse Azimuth:      {0:0.00} degrees", geoCurve.ReverseAzimuth.Degrees);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the destination if we start at:
        ///    Lincoln Memorial in Washington, D.C --> 38.8892N, 77.04978W
        ///         and travel at
        ///    51.7679 degrees for 6179.016136 kilometers
        ///
        ///    WGS84 reference ellipsoid
        /// </summary>
        static void TwoDimensionalDirectCalculation()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Lincoln Memorial coordinates
            GlobalCoordinates lincolnMemorial;

            lincolnMemorial = new GlobalCoordinates(
                new Angle(38.88922), new Angle(-77.04978)
                );

            // set the direction and distance
            Angle  startBearing = new Angle(51.7679);
            double distance     = 6179016.13586;

            // find the destination
            Angle             endBearing;
            GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(reference, lincolnMemorial, startBearing, distance, out endBearing);

            Console.WriteLine("Travel from Lincoln Memorial at 51.767921 deg for 6179.016 km");
            Console.Write("   Destination: {0:0.0000}{1}", dest.Latitude.Degrees, (dest.Latitude > 0) ? "N" : "S");
            Console.WriteLine(", {0:0.0000}{1}", dest.Longitude.Degrees, (dest.Longitude > 0) ? "E" : "W");
            Console.WriteLine("   End Bearing: {0:0.00} degrees", endBearing.Degrees);
        }
Ejemplo n.º 3
0
        public void TestAntiPodal2()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set position 1
            GlobalCoordinates p1;

            p1 = new GlobalCoordinates(11, 80);

            // set position 2
            GlobalCoordinates p2;

            p2 = new GlobalCoordinates(-10, -100);

            // calculate the geodetic measurement
            GeodeticCurve geoCurve;

            geoCurve = geoCalc.CalculateGeodeticCurve(reference, p1, p2);

            Assert.AreEqual(19893320.272061437, geoCurve.EllipsoidalDistance, 0.001);
            Assert.AreEqual(360.0, geoCurve.Azimuth.Degrees, 0.0000001);
            Assert.AreEqual(0.0, geoCurve.ReverseAzimuth.Degrees, 0.0000001);
        }
        public void TestPoleCrossing()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Lincoln Memorial coordinates
            GlobalCoordinates lincolnMemorial = new GlobalCoordinates(Angle.FromDegrees(38.88922), Angle.FromDegrees(-77.04978));

            // set a bearing of 1.0deg (almost straight up) and a distance
            Angle  startBearing = Angle.FromDegrees(1);
            double distance     = 6179016.13586;

            // set the expected destination
            GlobalCoordinates expected = new GlobalCoordinates(Angle.FromDegrees(85.60006433), Angle.FromDegrees(92.17243943));

            // calculate the ending global coordinates
            Angle             endBearing;
            GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(reference, lincolnMemorial, startBearing, distance, out endBearing);

            Assert.AreEqual(expected.Latitude.Degrees, dest.Latitude.Degrees, StandardTolerance);
            Assert.AreEqual(expected.Longitude.Degrees, dest.Longitude.Degrees, StandardTolerance);
        }
Ejemplo n.º 5
0
        public void TestCalculateGeodeticCurve()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Lincoln Memorial coordinates
            GlobalCoordinates lincolnMemorial;

            lincolnMemorial = new GlobalCoordinates(38.88922, -77.04978);

            // set Eiffel Tower coordinates
            GlobalCoordinates eiffelTower;

            eiffelTower = new GlobalCoordinates(48.85889, 2.29583);

            // calculate the geodetic curve
            GeodeticCurve geoCurve = geoCalc.CalculateGeodeticCurve(reference, lincolnMemorial, eiffelTower);

            Assert.AreEqual(6179016.136, geoCurve.EllipsoidalDistance, 0.001);
            Assert.AreEqual(51.76792142, geoCurve.Azimuth.Degrees, 0.0000001);
            Assert.AreEqual(291.75529334, geoCurve.ReverseAzimuth.Degrees, 0.0000001);
        }
        public double Distance(String lat1, String lon1, String lat2, String lon2)
        {
            //The geodesy library calculates distance between two geo coordinates based on
            //Vincenty's Formula. This library class contains parameters to calculate the distance.
            //The Ellipsoid value is based on the geographic location. Australia follows GRS80
            //Ellipsoid based on its demography.
            //The class was created by Gavaghan http://www.gavaghan.org/blog/free-source-code/geodesy-library-vincentys-formula/

            Ellipsoid reference = Ellipsoid.GRS80;

            //Create new object for geodetic calculator.
            GeodeticCalculator geoCalc = new GeodeticCalculator(reference);

            //Set the coordinates for point A
            GlobalCoordinates pointA;

            pointA = new GlobalCoordinates(
                new Angle(Convert.ToDouble(lat1)), new Angle(Convert.ToDouble(lon1))
                );

            //Set the coordinates for point B
            GlobalCoordinates pointB;

            pointB = new GlobalCoordinates(
                new Angle(Convert.ToDouble(lat2)), new Angle(Convert.ToDouble(lon2))
                );

            //Calculate the curved distance between the two coordinates
            GeodeticCurve geoCurve      = geoCalc.CalculateGeodeticCurve(pointA, pointB);
            double        ellipseMeters = geoCurve.EllipsoidalDistance;

            return(ellipseMeters); // return the distance in meters
        }
Ejemplo n.º 7
0
        public void TestInverseWithDirect()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Lincoln Memorial coordinates
            GlobalCoordinates lincolnMemorial;

            lincolnMemorial = new GlobalCoordinates(new Angle(38.88922), new Angle(-77.04978));

            // set Eiffel Tower coordinates
            GlobalCoordinates eiffelTower;

            eiffelTower = new GlobalCoordinates(48.85889, 2.29583);

            // calculate the geodetic curve
            GeodeticCurve geoCurve = geoCalc.CalculateGeodeticCurve(reference, lincolnMemorial, eiffelTower);

            // now, plug the result into to direct solution
            GlobalCoordinates dest;
            Angle             endBearing = new Angle();

            dest = geoCalc.CalculateEndingGlobalCoordinates(reference, lincolnMemorial, geoCurve.Azimuth, geoCurve.EllipsoidalDistance, out endBearing);

            Assert.AreEqual(eiffelTower.Latitude.Degrees, dest.Latitude.Degrees, 0.0000001);
            Assert.AreEqual(eiffelTower.Longitude.Degrees, dest.Longitude.Degrees, 0.0000001);
        }
Ejemplo n.º 8
0
        public void TestAntiPodal1()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set position 1
            GlobalCoordinates p1;

            p1 = new GlobalCoordinates(10, 80.6);

            // set position 2
            GlobalCoordinates p2;

            p2 = new GlobalCoordinates(-10, -100);

            // calculate the geodetic measurement
            GeodeticCurve geoCurve;

            geoCurve = geoCalc.CalculateGeodeticCurve(reference, p1, p2);

            Assert.AreEqual(19970718.422432076, geoCurve.EllipsoidalDistance, 0.001);
            Assert.AreEqual(90.0004877491174, geoCurve.Azimuth.Degrees, 0.0000001);
            Assert.AreEqual(270.0004877491174, geoCurve.ReverseAzimuth.Degrees, 0.0000001);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Calculate the three-dimensional path from
        ///    Pike's Peak in Colorado --> 38.840511N, 105.0445896W, 4301 meters
        ///        to
        ///    Alcatraz Island --> 37.826389N, 122.4225W, sea level
        ///        using
        ///    WGS84 reference ellipsoid
        /// </summary>
        private static void ThreeDimensionalInverseCalculation()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Pike's Peak position
            GlobalPosition pikesPeak = new GlobalPosition(new GlobalCoordinates(Angle.FromDegrees(38.840511), Angle.FromDegrees(-105.0445896)), 4301);

            // set Alcatraz Island coordinates
            GlobalPosition alcatrazIsland = new GlobalPosition(new GlobalCoordinates(Angle.FromDegrees(37.826389), Angle.FromDegrees(-122.4225)), 0);

            // calculate the geodetic measurement
            GeodeticMeasurement geoMeasurement;
            double p2pKilometers;
            double p2pMiles;
            double elevChangeMeters;
            double elevChangeFeet;

            geoMeasurement   = geoCalc.CalculateGeodeticMeasurement(reference, pikesPeak, alcatrazIsland);
            p2pKilometers    = geoMeasurement.PointToPointDistanceMeters / 1000;
            p2pMiles         = p2pKilometers * 0.621371192;
            elevChangeMeters = geoMeasurement.ElevationChangeMeters;
            elevChangeFeet   = elevChangeMeters * 3.2808399;

            Console.WriteLine("3-D path from Pike's Peak to Alcatraz Island using WGS84");
            Console.WriteLine("   Point-to-Point Distance: {0:0.00} kilometers ({1:0.00} miles)", p2pKilometers, p2pMiles);
            Console.WriteLine("   Elevation change:        {0:0.0} meters ({1:0.0} feet)", elevChangeMeters, elevChangeFeet);
            Console.WriteLine("   Azimuth:                 {0:0.00} degrees", geoMeasurement.Azimuth.Degrees);
            Console.WriteLine("   Reverse Azimuth:         {0:0.00} degrees", geoMeasurement.ReverseAzimuth.Degrees);
        }
Ejemplo n.º 10
0
        public void TestCalculateGeodeticMeasurement()
        {
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();

            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            // set Pike's Peak position
            GlobalPosition pikesPeak;

            pikesPeak = new GlobalPosition(new GlobalCoordinates(new Angle(38.840511), new Angle(-105.0445896)), 4301.0);

            // set Alcatraz Island coordinates
            GlobalPosition alcatrazIsland;

            alcatrazIsland = new GlobalPosition(new GlobalCoordinates(new Angle(37.826389), new Angle(-122.4225)), 0.0);

            // calculate the geodetic measurement
            GeodeticMeasurement geoMeasurement;

            geoMeasurement = geoCalc.CalculateGeodeticMeasurement(reference, pikesPeak, alcatrazIsland);

            Assert.AreEqual(-4301.0, geoMeasurement.ElevationChange, 0.001);
            Assert.AreEqual(1521788.826, geoMeasurement.PointToPointDistance, 0.001);
            Assert.AreEqual(1521782.748, geoMeasurement.EllipsoidalDistance, 0.001);
            Assert.AreEqual(271.21039153, geoMeasurement.Azimuth.Degrees, 0.0000001);
            Assert.AreEqual(80.38029386, geoMeasurement.ReverseAzimuth.Degrees, 0.0000001);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Get the list of neighbor meshes in a specified "distance". Distance 1 means
        /// direct neighbors, 2 means neighbors that are 2 meshes away etc.
        /// </summary>
        /// <param name="meshNumber">The mesh number</param>
        /// <param name="distance">The distance (0-3 currently supported)</param>
        /// <returns>The list of mesh numbers of the neighbors</returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public List <long> Neighborhood(long meshNumber, int distance)
        {
            const int maxDistance = 3;

            if (distance < 0 || distance > maxDistance)
            {
                throw new ArgumentOutOfRangeException(Properties.Resources.INVALID_DISTANCE);
            }

            if (distance == 0)
            {
                return(new List <long> {
                    meshNumber
                });
            }

            var center = Projection.FromEuclidian(CenterOf(meshNumber));
            var calc   = new GeodeticCalculator(Projection.ReferenceGlobe);
            var result = new List <long>();

            for (var y = -distance; y <= distance; y++)
            {
                var bearing = Math.Sign(y) < 0 ? 180.0 : 0.0;

                var vertical = y != 0 ?
                               calc.CalculateEndingGlobalCoordinates(center, bearing, Math.Abs(y) * MeshSize)
                    : center;

                for (var x = -distance; x <= distance; x++)
                {
                    if (x != 0 || y != 0)
                    {
                        var add = false;
                        if (Math.Abs(y) == distance)
                        {
                            add = true;
                        }
                        else
                        {
                            if (Math.Abs(x) == distance)
                            {
                                add = true;
                            }
                        }
                        if (add)
                        {
                            bearing = Math.Sign(x) < 0 ? 270.0 : 90.0;
                            var horizontal = x != 0 ?
                                             calc.CalculateEndingGlobalCoordinates(vertical, bearing, Math.Abs(x) * MeshSize)
                                : vertical;

                            result.Add(MeshNumber(horizontal));
                        }
                    }
                }
            }
            return(result);
        }
        public double MeasureDistance(Coordinates from, Coordinates to)
        {
            var calculator = new GeodeticCalculator(Ellipsoid.WGS84);
            var curve      = calculator.CalculateGeodeticCurve(
                new GlobalCoordinates(from.Latitude, from.Longitude),
                new GlobalCoordinates(to.Latitude, to.Longitude));

            return(MetersToMiles(curve.EllipsoidalDistance));
        }
Ejemplo n.º 13
0
        public static GeodeticMeasurement CalculateDistance(double lat1, double lon1, double lat2, double lon2)
        {
            GlobalCoordinates   p1  = new GlobalCoordinates(new Angle(lat1), new Angle(lon1));
            GlobalCoordinates   p2  = new GlobalCoordinates(new Angle(lat2), new Angle(lon2));
            GeodeticCalculator  gc  = new GeodeticCalculator();
            GlobalPosition      gp1 = new GlobalPosition(p1);
            GlobalPosition      gp2 = new GlobalPosition(p2);
            GeodeticMeasurement gm  = gc.CalculateGeodeticMeasurement(Ellipsoid.WGS84, gp1, gp2);

            return(gm);
        }
Ejemplo n.º 14
0
        public static double GetDistance(double txLat, double txLon, double rxLat, double rxLon)
        {
            GeodeticCalculator geoCalc   = new GeodeticCalculator();
            Ellipsoid          reference = Ellipsoid.WGS84;

            GlobalCoordinates start = new GlobalCoordinates(new Angle(txLat), new Angle(txLon));
            GlobalCoordinates end   = new GlobalCoordinates(new Angle(rxLat), new Angle(rxLon));

            GeodeticCurve path = geoCalc.CalculateGeodeticCurve(reference, start, end);

            return(path.EllipsoidalDistance);
        }
Ejemplo n.º 15
0
 private void calculateProjection()
 {
     Framework.Data.Location ll = Utils.Conversion.StringToLocation(textBox3.Text);
     if (ll != null)
     {
         GeodeticCalculator gc = new GeodeticCalculator();
         GlobalCoordinates  p  = gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(ll.Lat), new Angle(ll.Lon)), new Angle((double)numericUpDown2.Value), radioButton1.Checked ? (double)numericUpDown1.Value : 1609.26939 * (double)numericUpDown2.Value);
         textBox4.Text = Utils.Conversion.GetCoordinatesPresentation(p.Latitude.Degrees, p.Longitude.Degrees);
     }
     else
     {
         textBox4.Text = "";
     }
 }
Ejemplo n.º 16
0
        public static void GetEnvelope(double lat, double lon, double dist, out double minLat, out double minLon, out double maxLat, out double maxLon)
        {
            var gc        = new GeodeticCalculator();
            var endpoints = new List <GlobalCoordinates>();

            endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(0), dist * 1000.0));
            endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(90), dist * 1000.0));
            endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(180), dist * 1000.0));
            endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(270), dist * 1000.0));
            minLat = endpoints.Min(x => x.Latitude.Degrees);
            maxLat = endpoints.Max(x => x.Latitude.Degrees);
            minLon = endpoints.Min(x => x.Longitude.Degrees);
            maxLon = endpoints.Max(x => x.Longitude.Degrees);
        }
Ejemplo n.º 17
0
        public static double NextLat(double lat, double lon, double az, double distance)
        {
            GeodeticCalculator geoCalc   = new GeodeticCalculator();
            Ellipsoid          reference = Ellipsoid.WGS84;

            GlobalCoordinates start   = new GlobalCoordinates(new Angle(lat), new Angle(lon));
            Angle             azimuth = new Angle(az);

            Angle endBearing;

            GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(reference, start, azimuth, distance, out endBearing);

            return(dest.Latitude.Degrees);
        }
Ejemplo n.º 18
0
        private void addConePolyline(double angle, GeodeticCalculator geoCalculator, CustomMap customMap, LatLng userPos, double distTarget)
        {
            var polylineOptions = new PolylineOptions();

            polylineOptions.Clickable(true);
            polylineOptions.InvokeJointType(JointType.Round);
            polylineOptions.InvokeWidth(10f);
            polylineOptions.InvokeColor(0x664444FF);

            polylineOptions.Add(userPos);
            LatLng conePoint = movePoint(angle, customMap.UserPin.Position, customMap.TargetPin.Position);

            Console.WriteLine("conePoint dist = " + CustomMap.DistanceTo(customMap.UserPin.Position.Latitude, customMap.UserPin.Position.Longitude, conePoint.Latitude, conePoint.Longitude, "M"));
            polylineOptions.Add(conePoint);
            coneLines.Add(map.AddPolyline(polylineOptions));
        }
Ejemplo n.º 19
0
        public static object NextPoint(double lat, double lon, double az, double distance)
        {
            GeodeticCalculator geoCalc   = new GeodeticCalculator();
            Ellipsoid          reference = Ellipsoid.WGS84;

            GlobalCoordinates start   = new GlobalCoordinates(new Angle(lat), new Angle(lon));
            Angle             azimuth = new Angle(az);

            Angle endBearing;

            GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(reference, start, azimuth, distance, out endBearing);

            var point = new object[1, 2];

            point[0, 0] = dest.Latitude.Degrees;
            point[0, 1] = dest.Longitude.Degrees;

            return(ArrayResizer.Resize(point));
        }
Ejemplo n.º 20
0
        public override object Execute(object[] args, ExecutionContext ctx)
        {
            string          ret     = "";
            ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);

            checker.CheckForNumberOfArguments(ref args, 3, null);
            Core.Data.Location ll       = Utils.Conversion.StringToLocation(args[0].ToString());
            double             distance = Utils.Conversion.StringToDouble(args[1].ToString());
            double             angle    = Utils.Conversion.StringToDouble(args[2].ToString());

            if (ll != null)
            {
                GeodeticCalculator gc = new GeodeticCalculator();
                GlobalCoordinates  p  = gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84,
                                                                            new GlobalCoordinates(new Angle(ll.Lat), new Angle(ll.Lon)),
                                                                            new Angle(angle), distance);
                ret = Utils.Conversion.GetCoordinatesPresentation(p.Latitude.Degrees, p.Longitude.Degrees);
            }

            return(ret);
        }
Ejemplo n.º 21
0
        public void UpdateShotCone(double angle)
        {
            if (coneLines.Count != 0)
            {
                foreach (Polyline line in coneLines)
                {
                    line.Remove();
                }
            }

            CustomMap          customMap     = (CustomMap)this.Element;
            GeodeticCalculator geoCalculator = new GeodeticCalculator();
            double             distTarget    = 0.0;
            LatLng             userPos       = new LatLng(customMap.UserPin.Position.Latitude, customMap.UserPin.Position.Longitude);

            if (customMap != null)
            {
                distTarget = customMap.getDistanceUserTarget();
                addConePolyline(angle, geoCalculator, customMap, userPos, distTarget);
                addConePolyline(-angle, geoCalculator, customMap, userPos, distTarget);
            }
        }
        private void SetupLibrary(double gap, double earthRadius, string data, ref List <Point> points)
        {
            UseDefaultValues();
            mode    = LibraryMode.Test;
            geoCalc = new GeodeticCalculator();
            distanceBetweenPoints = gap;
            effectiveEarthRadius  = earthRadius;

            var csv = File.ReadAllLines(data);

            points = csv
                     .Skip(1)
                     .Select(p => newPointFromCsv(p))
                     .ToList();

            double d = Convert.ToDouble(csv.Last().Split(',')[0]) * 1000.0;

            path = new GeodeticCurve(d, new Angle(0.0), new Angle(180.0));

            double d_secondLast = Convert.ToDouble(csv[csv.Length - 2].Split(',')[0]) * 1000.0;

            distanceBetweenLastPoints = d - d_secondLast;
        }
Ejemplo n.º 23
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            // Store user inputs
            int maxRadius = (int)numRadius.Value;
            int minRWY    = (int)numRWYmin.Value;
            int minPCN    = (int)numPCNmin.Value;

            string[] mustHaveFields = txtIncludeFields.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            // Find home field
            AirfieldInformation home = airfieldInfo.Find(x => x.Airfield.ICAO == txtHome.Text);
            // instantiate the calculator
            GeodeticCalculator geoCalc = new GeodeticCalculator();
            // select a reference elllipsoid
            Ellipsoid reference = Ellipsoid.WGS84;

            foreach (AirfieldInformation alt in airfieldInfo)
            {
                // calculate the geodetic measurement
                GeodeticMeasurement geoMeasurement;
                geoMeasurement              = geoCalc.CalculateGeodeticMeasurement(reference, home.Airfield.Position, alt.Airfield.Position);
                alt.Airfield.RangeFromHome  = geoMeasurement.PointToPointDistance * 0.000539957;
                alt.Airfield.RadialFromHome = geoMeasurement.Azimuth.Degrees - home.Airfield.MagneticDeclination.Degrees;
            }
            airfieldInfo.Sort((x, y) => x.Airfield.RangeFromHome.CompareTo(y.Airfield.RangeFromHome));

            //Get suitable diverts
            List <AirfieldInformation> suitableDiverts = new List <AirfieldInformation>();

            for (int z = 0; z < airfieldInfo.Count; z++)
            {
                //Field is suitable until proven otherwise
                bool suitField = true;

                if (airfieldInfo[z].Airfield.RangeFromHome > maxRadius)
                {
                    suitField = false;
                }
                //Runway conditions
                bool suitRWY = false;
                foreach (Runway r in airfieldInfo[z].Runways)
                {
                    if (r.Length >= minRWY && (r.PCN >= minPCN || r.PCN == -1))
                    {
                        suitRWY = true;
                    }
                }
                if (!suitRWY)
                {
                    suitField = false;
                }
                //More options later


                if (mustHaveFields.Contains(airfieldInfo[z].Airfield.ICAO))
                {
                    suitField = true;
                }
                //Add to suitable fields as required
                if (suitField)
                {
                    suitableDiverts.Add(airfieldInfo[z]);
                }
            }
            suitableDiverts = import.addSuppAndTerminals(suitableDiverts, flipFileLocation);

            //Create pdf
            createDivertPDF(suitableDiverts);
        }
Ejemplo n.º 24
0
        public DiffractionLossCalculator()
        {
            geoCalc = new GeodeticCalculator();

            try
            {
                config = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
            }
            catch (Exception ex)
            {
                UseDefaultValues();
                throw ex;
            }

            if (config != null)
            {
                KeyValueConfigurationElement element;

                element = config.AppSettings.Settings["distanceBetweenPoints"];
                if (element != null)
                {
                    try
                    {
                        distanceBetweenPoints = double.Parse(element.Value);
                    }
                    catch
                    {
                        distanceBetweenPoints = defaultDistanceBetweenPoints;
                    }
                }

                element = config.AppSettings.Settings["srtmCache"];
                if (element != null)
                {
                    try
                    {
                        srtmData = new SRTMData(element.Value);
                    }
                    catch
                    {
                        srtmData = new SRTMData(defaultSrtmCache);
                    }
                }

                element = config.AppSettings.Settings["ellipsoid"];
                if (element != null)
                {
                    try
                    {
                        switch (element.Value)
                        {
                        case "WGS84":
                            ellipsoid = Ellipsoid.WGS84;
                            break;

                        case "GRS80":
                            ellipsoid = Ellipsoid.GRS80;
                            break;

                        case "GRS67":
                            ellipsoid = Ellipsoid.GRS67;
                            break;

                        case "ANS":
                            ellipsoid = Ellipsoid.ANS;
                            break;

                        case "WGS72":
                            ellipsoid = Ellipsoid.WGS72;
                            break;

                        case "Clarke1858":
                            ellipsoid = Ellipsoid.Clarke1858;
                            break;

                        case "Clarke1880":
                            ellipsoid = Ellipsoid.Clarke1880;
                            break;

                        case "Sphere":
                            ellipsoid = Ellipsoid.Sphere;
                            break;

                        default:
                            ellipsoid = defaultEllipsoid;
                            break;
                        }
                    }
                    catch
                    {
                        ellipsoid = defaultEllipsoid;
                    }
                }

                element = config.AppSettings.Settings["effectiveEarthRadius"];
                if (element != null)
                {
                    try
                    {
                        effectiveEarthRadius = double.Parse(element.Value);
                    }
                    catch
                    {
                        effectiveEarthRadius = defaultEffectiveEarthRadius;
                    }
                }
            }
            else
            {
                UseDefaultValues();
            }
        }
 public LocationDerivation()
 {
     this.calculator = new GeodeticCalculator(Ellipsoid.WGS84);
 }