Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void TestEnding()
        {
            var curve = calc.CalculateGeodeticCurve(Constants.MyHome, Constants.MyOffice);
            var final = calc.CalculateEndingGlobalCoordinates(
                Constants.MyHome,
                curve.Azimuth,
                curve.EllipsoidalDistance);

            Assert.AreEqual(final, Constants.MyOffice);
            Assert.AreEqual(curve.Calculator, calc);
        }
Ejemplo n.º 3
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.º 4
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);
        }
        /// <summary>
        /// Move platforms in the world to the new place.
        /// based on <see cref="Platform"/> <see cref="Spacial.Movement"/> data and the time that passed.
        /// </summary>
        /// <param name="timePassed">The time that passed from the last update</param>
        public void MovePlatformsNextStep(Duration timePassed)
        {
            foreach (var platform in platforms)
            {
                // Get current position and movement data
                var platformPosition = platform.Spacial.Position;
                var platformMovement = platform.Spacial.Movement;

                // Translate position to a Geodesy Coordinate instance
                var originalGeoPosition = new GlobalCoordinates(
                    latitude: new Geodesy.Angle(platformPosition.Latitude.Degrees),
                    longitude: new Geodesy.Angle(platformPosition.Longitude.Degrees));

                // Calculate the distance in meters based on the time that passed and platform speed
                var distanceInMeters = timePassed.Seconds * platformMovement.Speed.MetersPerSecond;

                // Calculate and get the position where the platform should be now
                var nextGeoPosition =
                    geodeticCalculator.CalculateEndingGlobalCoordinates(
                        start: originalGeoPosition,
                        startBearing: new Geodesy.Angle(platformMovement.Course.Degrees),
                        distance: distanceInMeters);

                // Update the platform position
                platformPosition.Latitude  = Angle.FromDegrees(nextGeoPosition.Latitude.Degrees);
                platformPosition.Longitude = Angle.FromDegrees(nextGeoPosition.Longitude.Degrees);
            }
        }
        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.º 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
        /// <summary>
        /// Прямая геодезическая задача
        /// </summary>
        /// <param name="angle">Азимут визира</param>
        /// <returns></returns>
        GlobalCoordinates get_line_position(double angle)
        {
            GlobalCoordinates start = UserPosition;
            GlobalCoordinates end   = geo_calc.CalculateEndingGlobalCoordinates(start, angle, line_length);

            return(end);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Calculates a point at the specified distance along a radial from a
        /// center point.
        /// </summary>
        /// <param name="latitude">The latitude of the center point.</param>
        /// <param name="longitude">The longitude of the center point.</param>
        /// <param name="distance">The distance in meters.</param>
        /// <param name="radial">
        /// The radial in degrees, measures clockwise from north.
        /// </param>
        /// <returns>
        /// A <see cref="GeoPoint"/> containing the Latitude and Longitude of the
        /// calculated point.
        /// </returns>
        /// <remarks>The antemeridian is not considered.</remarks>
        public static GeoPoint RadialPoint(double latitude, double longitude, double distance, double radial)
        {
            radial = !double.IsNaN(radial) ? radial : 0;
            var coordinates = Calculator.CalculateEndingGlobalCoordinates(
                new GlobalCoordinates(new Angle(latitude), new Angle(longitude)), new Angle(radial), distance);

            return(new GeoPoint(coordinates.Latitude.Degrees, coordinates.Longitude.Degrees));
        }
Ejemplo n.º 10
0
        public static GeoCoordinate CalculateNextWaypoint(GeoCoordinate startingLocation, double bearing, double distance)
        {
            GlobalCoordinates startingLocation2 = startingLocation.ToGlobalCoordinates();

            GlobalCoordinates targetLocation = _geodeticCalculator.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, startingLocation2, bearing, distance);

            return(targetLocation.ToGeoCoordinate());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Прямая геодезическая задача
        /// </summary>
        /// <param name="angle">Азимут визира</param>
        /// <returns></returns>
        PointLatLng get_line_position2(double angle)
        {
            PointLatLng result = new PointLatLng();

            GlobalCoordinates start = new GlobalCoordinates(UserPosition.Lat, UserPosition.Lng);
            GlobalCoordinates end   = geo_calc.CalculateEndingGlobalCoordinates(start, angle, line_length);

            result.Lat = end.Latitude.Degrees;
            result.Lng = end.Longitude.Degrees;

            return(result);
        }
Ejemplo n.º 12
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.º 13
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.º 14
0
        public IList <DerivedPointDto> CreateArc(double radius, SuppliedPointDto centerPoint, SuppliedPointDto startPoint, SuppliedPointDto endPoint)
        {
            Angle centerLatitude  = new Angle(centerPoint.Latitude);
            Angle centerLongitude = new Angle(centerPoint.Longitude);
            Angle startLatitude   = new Angle(startPoint.Latitude);
            Angle startLongitude  = new Angle(startPoint.Longitude);
            Angle endLatitude     = new Angle(endPoint.Latitude);
            Angle endLongitude    = new Angle(endPoint.Longitude);

            GlobalCoordinates centerCoordinate = new GlobalCoordinates(centerLatitude, centerLongitude);
            GlobalCoordinates startCoordinate  = new GlobalCoordinates(startLatitude, startLongitude);
            GlobalCoordinates endCoordinate    = new GlobalCoordinates(endLatitude, endLongitude);

            GlobalPosition centerPosition = new GlobalPosition(centerCoordinate);
            GlobalPosition startPosition  = new GlobalPosition(startCoordinate);
            GlobalPosition endPosition    = new GlobalPosition(endCoordinate);

            GeodeticMeasurement centerToStartMeasurement = calculator.CalculateGeodeticMeasurement(centerPosition, startPosition);
            GeodeticMeasurement centerToEndMeasurement   = calculator.CalculateGeodeticMeasurement(centerPosition, endPosition);

            // Radius should ensure that it is tolerable (we are going to ingore it in this implementation)
            double startDistance   = centerToStartMeasurement.PointToPointDistance;
            double endDistance     = centerToEndMeasurement.PointToPointDistance;
            double distanceDelta   = Math.Abs(startDistance - endDistance);
            double distanceEpsilon = distanceDelta / 10;

            Angle startBearing = centerToStartMeasurement.Azimuth;
            Angle endBearing   = centerToEndMeasurement.Azimuth;

            double degreesDelta   = Math.Abs(startBearing.Degrees - endBearing.Degrees);
            double degreesEpsilon = degreesDelta / 10;  // Our angular distribution

            IList <DerivedPointDto> arcPoints = new List <DerivedPointDto>();

            // We are going to assume that arc derivation is done in a clockwise position.
            for (int i = 0; i < 10; i++) // Such that the 10th increment should equate to the end point and the initial the start
            {
                Angle             nextBearing   = new Angle(startBearing.Degrees + (degreesEpsilon * (i + 1)));
                GlobalCoordinates thetaLocation = calculator.CalculateEndingGlobalCoordinates(centerCoordinate, nextBearing, startDistance + (distanceEpsilon * (i + 1)));
                DerivedPointDto   thetaPoint    = new DerivedPointDto(thetaLocation.Latitude.Degrees, thetaLocation.Longitude.Degrees);

                arcPoints.Add(thetaPoint);
            }

            return(arcPoints);
        }
Ejemplo n.º 15
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.º 16
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.º 17
0
        public List <Point> GenerateIntermediateProfilePoints(GlobalCoordinates start, GlobalCoordinates end)
        {
            List <Point> points = new List <Point>();

            int?startHeight = srtmData.GetElevation(start.Latitude.Degrees, start.Longitude.Degrees);

            points.Add(new Point(start, startHeight));

            path = geoCalc.CalculateGeodeticCurve(ellipsoid, start, end);
            Angle  azimuth       = path.Azimuth.Degrees;
            double totalDistance = path.EllipsoidalDistance;

            int numberOfPoints = (Convert.ToInt32(Math.Floor(totalDistance / distanceBetweenPoints)));

            for (int i = 0; i < numberOfPoints; i++)
            {
                GlobalCoordinates nextPoint = geoCalc.CalculateEndingGlobalCoordinates(ellipsoid, points[i].coordinate, azimuth, distanceBetweenPoints, out azimuth);
                int?height = srtmData.GetElevation(nextPoint.Latitude.Degrees, nextPoint.Longitude.Degrees);

                points.Add(new Point(nextPoint, height));
            }

            int?endHeight = srtmData.GetElevation(end.Latitude.Degrees, end.Longitude.Degrees);

            points.Add(new Point(end, endHeight));

            /*
             * Perform a sanity check
             * Occasionally the SRTM library throws up odd values like 65,535 so if we detect values above mount everest (about 8900m) we use the average height between the next points
             */
            FixHeights(ref points);



            return(points);
        }