Example #1
0
 /// <summary>
 /// Create instance of <see cref="CompassLogEntry"/> with <see cref="CoordinatePoint"/> and MRU data.
 /// </summary>
 /// <param name="point"><see cref="CoordinatePoint"/></param>
 /// <param name="heading"><see cref="Heading"/></param>
 /// <param name="pitch"><see cref="Pitch"/></param>
 /// <param name="roll"><see cref="Roll"/></param>
 public CompassLogEntry(CoordinatePoint point, double heading, double pitch, double roll)
 {
     Point   = point;
     Heading = heading;
     Pitch   = pitch;
     Roll    = roll;
 }
Example #2
0
 private void lakePNL_MouseMove(object sender, MouseEventArgs e)
 {
     if (_mouseDown)
     {
         if (zoomInCB.Checked)
         {
             _zoomSecondPoint = new Point(e.X, e.Y);
             lakePNL.Invalidate();
         }
         else if (SelectedMark != null && _selectedBouy != null)
         {
             Point           mp = new Point(e.X, e.Y);
             CoordinatePoint cp = ScreenToCoordinates(mp);
             _selectedBouy.Longitude = cp.Longitude;
             _selectedBouy.Latitude  = cp.Latitude;
             _selectedBouy.Save();
             lakePNL.Invalidate();
             mouseCoordsLBL.Text = _selectedBouy.Latitude.ToString() + " " + _selectedBouy.Longitude.ToString();
         }
     }
     else if (!zoomInCB.Checked)
     {
         Bouy b = null;
         if (TryFindCloseBouy(new Point(e.X, e.Y), ref b))
         {
             lakePNL.Cursor = Cursors.Hand;
         }
         else
         {
             lakePNL.Cursor = Cursors.Default;
         }
     }
 }
        public static List <CoordinatePoint> Vertical(this CoordinatePoint CoordinatPoint)
        {
            List <CoordinatePoint> result = new List <CoordinatePoint>();

            if (CoordinatPoint.Y + 1 >= 0 && CoordinatPoint.Y + 1 <= 7)
            {
                if (CoordinatPoint.X - 2 >= 0 && CoordinatPoint.X - 2 <= 7)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X - 2, CoordinatPoint.Y + 1));
                }
                if (CoordinatPoint.X + 2 <= 7 && CoordinatPoint.X + 2 >= 0)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X + 2, CoordinatPoint.Y + 1));
                }
            }
            if (CoordinatPoint.Y - 1 <= 7 && CoordinatPoint.Y - 1 >= 0)
            {
                if (CoordinatPoint.X - 2 >= 0 && CoordinatPoint.X - 2 <= 7)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X - 2, CoordinatPoint.Y - 1));
                }
                if (CoordinatPoint.X + 2 <= 7 && CoordinatPoint.Y + 2 >= 0)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X + 2, CoordinatPoint.Y - 1));
                }
            }
            return(result);
        }
Example #4
0
        public override CoordinatePoint Transform(CoordinatePoint cp)
        {
            CoordinatePoint projectedPoint = new CoordinatePoint();

            projectedPoint.Ord = new double[2];
            if (_isInverse == false)
            {
                double x         = 0.0;
                double y         = 0.0;
                double longitude = (double)cp.Ord.GetValue(0);
                double latitude  = (double)cp.Ord.GetValue(1);

                this.DegreesToMeters(longitude, latitude, out x, out y);


                projectedPoint.Ord.SetValue(x, 0);
                projectedPoint.Ord.SetValue(y, 1);
            }
            else
            {
                double x         = (double)cp.Ord.GetValue(0);
                double y         = (double)cp.Ord.GetValue(1);
                double longitude = 0.0;
                double latitude  = 0.0;

                this.MetersToDegrees(x, y, out longitude, out latitude);

                projectedPoint.Ord.SetValue(longitude, 0);
                projectedPoint.Ord.SetValue(latitude, 1);
            }
            return(projectedPoint);
        }
Example #5
0
        public override double[] TransformList(double[] ord)
        {
            if (ord.Length % 2 != 0)
            {
                throw new ArgumentException("Array must have an even number of parameters.");
            }
            double[] result = new double[ord.Length];
            double   x;
            double   y;

            for (int i = 0; i < ord.Length; i = i + 2)
            {
                x = result[i];
                y = result[i + 1];
                CoordinatePoint point = new CoordinatePoint();
                point.Ord = new double[2];
                point.Ord.SetValue(x, 0);
                point.Ord.SetValue(y, 1);
                CoordinatePoint projectedPoint;
                if (_isInverse == false)
                {
                    projectedPoint = Transform(point);
                }
                else
                {
                    projectedPoint = GetInverse().Transform(point);
                }
                result[i]     = (double)projectedPoint.Ord.GetValue(0);
                result[i + 1] = (double)projectedPoint.Ord.GetValue(1);
            }
            return(result);
        }
        internal GeographicCoordinateSystem(
            IAngularUnit angularUnit,
            IHorizontalDatum horizontalDatum,
            IPrimeMeridian primeMeridian,
            IAxisInfo axis0,
            IAxisInfo axis1,
            string remarks, string authority, string authorityCode, string name, string alias, string abbreviation)
            : base(remarks, authority, authorityCode, name, alias, abbreviation)
        {
            _angularUnit     = angularUnit;
            _horizontalDatum = horizontalDatum;
            _primeMeridian   = primeMeridian;
            _axisInfo        = new IAxisInfo[] { axis0, axis1 };


            CoordinatePoint minPt = new CoordinatePoint();

            minPt.Ord = new Double[2];
            minPt.Ord.SetValue(-180, 0);
            minPt.Ord.SetValue(-90, 1);

            CoordinatePoint maxPt = new CoordinatePoint();

            maxPt.Ord = new Double[2];
            maxPt.Ord.SetValue(-180, 0);
            maxPt.Ord.SetValue(-90, 1);

            // define the envelope.
            _defaultEnvelope       = new Positioning.Envelope();
            _defaultEnvelope.MinCP = minPt;
            _defaultEnvelope.MaxCP = maxPt;
        }
        public static List <CoordinatePoint> Horizontal(this CoordinatePoint CoordinatPoint)
        {
            List <CoordinatePoint> result = new List <CoordinatePoint>();

            if (CoordinatPoint.Y + 2 >= 0 && CoordinatPoint.Y + 2 <= 7)
            {
                if (CoordinatPoint.X - 1 >= 0 && CoordinatPoint.X - 1 <= 7)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X - 1, CoordinatPoint.Y + 2));
                }
                if (CoordinatPoint.X + 1 <= 7 && CoordinatPoint.X + 1 >= 0)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X + 1, CoordinatPoint.Y + 2));
                }
            }
            if (CoordinatPoint.Y - 2 <= 7 && CoordinatPoint.Y - 2 >= 0)
            {
                if (CoordinatPoint.X - 1 >= 0 && CoordinatPoint.X - 1 <= 7)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X - 1, CoordinatPoint.Y - 2));
                }
                if (CoordinatPoint.X + 1 <= 7 && CoordinatPoint.X + 1 >= 0)
                {
                    result.Add(new CoordinatePoint(CoordinatPoint.X + 1, CoordinatPoint.Y - 2));
                }
            }
            return(result);
        }
Example #8
0
        public void MagneticVariationCalculationCacheTest()
        {
            var point1 = new CoordinatePoint(Latitude.FromDegrees(60.12345888), Longitude.FromDegrees(30.12345888));

            var watch           = Stopwatch.StartNew();
            var point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                         MagneticVariation.MagneticVariationModels.WMM2015, out _);

            watch.Stop();

            var elapsed1 = watch.Elapsed;

            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);

            watch.Restart();
            point1Variation = MagneticVariation.GetMagneticVariation(point1, 6, 0, DateTimeOffset.UtcNow,
                                                                     MagneticVariation.MagneticVariationModels.WMM2015, out _);
            watch.Stop();

            var elapsed2 = watch.Elapsed;

            // first run takes more time
            Assert.IsTrue(elapsed1 > elapsed2);
        }
Example #9
0
        /// <summary>
        /// Execution function for Day 3
        /// </summary>
        public void Execute3()
        {
            UserActionAsync(() =>
            {
                WriteToConsole("Start execution of Day3");
                var parser = GetInputParser("Day3Input.txt");

                var startingPoint = new CoordinatePoint(0, 0);
                var wires         = parser.GetInputData().Select(line => new Wire(startingPoint, line.Split(','))).ToList();

                var wire1 = wires[0];
                var wire2 = wires[1];

                var intersections = wire1.GetIntersectionsWith(wire2);
                var board         = new GridBoard();
                var closestPoint  = board.GetClosestPointTo(intersections, startingPoint);

                WriteToConsole($"The closest intersection point is located at {closestPoint.point} with a distance to the starting point of {closestPoint.distance}");

                AddEmptyLine();

                WriteToConsole($"Now we want to find the closest intersection based on the steps both wires combined have to take to reach it");

                var firstIntersection = wire1.GetFirstIntersectionWith(wire2);

                WriteToConsole($"The first intersection point is located at {firstIntersection.point} with a total number of {firstIntersection.steps} steps");

                AddEmptyLine();
            });
        }
        public void TestCreateFromTransformationCode1()
        {
            ICoordinateTransformation UKNationalGrid1 = _CTfactory.CreateFromTransformationCode("1036");

            double          long1 = -2;
            double          lat1  = 49;
            CoordinatePoint pt    = new CoordinatePoint();

            pt.Ord    = new Double[2];
            pt.Ord[0] = long1;
            pt.Ord[1] = lat1;

            CoordinatePoint result1 = UKNationalGrid1.MathTransform.Transform(pt);

            double metersX = (double)result1.Ord[0];
            double metersY = (double)result1.Ord[1];

            Assertion.AssertEquals("Transverse Mercator Transform X", "400000", metersX.ToString());
            Assertion.AssertEquals("Transverse Mercator Transform Y", "-100000", metersY.ToString());

            CoordinatePoint result2 = UKNationalGrid1.MathTransform.GetInverse().Transform(result1);

            double long2 = (double)result2.Ord[0];
            double lat2  = (double)result2.Ord[1];

            Assertion.AssertEquals("Transverse Mercator InverseTransformPoint X", "-2", long2.ToString());
            Assertion.AssertEquals("TransverseMercator InverseTransformPoint Y", "49", lat2.ToString());
        }
        private bool CheckCollisionRectangle(CollisionRectangle collisionRectangle, CoordinatePoint toCheck)
        {
            var xPair = GetMaxPair(collisionRectangle.CornerOne.X, collisionRectangle.CornerTwo.X);
            var yPair = GetMaxPair(collisionRectangle.CornerOne.Y, collisionRectangle.CornerTwo.Y);

            return(IsWithin(xPair, toCheck.X) && IsWithin(yPair, toCheck.Y));
        }
        public static List <CoordinatePoint> Crosswise(this CoordinatePoint CoordinatPoint)
        {
            var arrayHor  = Horizontal(CoordinatPoint);
            var arrayVert = Vertical(CoordinatPoint);

            arrayHor.AddRange(arrayVert);
            return(arrayHor);
        }
        public static bool Equals(this CoordinatePoint CoordinatPoint, CoordinatePoint poi)
        {
            var knightMoves = Crosswise(CoordinatPoint);
            var endMoves    = Crosswise(poi);
            var result      = endMoves.Intersect(knightMoves).ToList();

            return(result.Count > 0);
        }
Example #14
0
        private Bouy NewBouy(Mark m)
        {
            CoordinatePoint bouyC = ScreenToCoordinates(new Point(lakePNL.Width / 2, lakePNL.Height / 2));
            Bouy            b     = new Bouy(m, bouyC.Latitude, bouyC.Longitude);

            b.Save();
            return(b);
        }
Example #15
0
        /// <summary>
        /// calculate vmc and vmg values if possible with current state
        /// </summary>
        /// <param name="state">current race state</param>
        public void Calculate(State state)
        {
            if (state.Location != null && state.TargetMark != null && state.TargetMark.Location != null && state.Course is CourseByMarks)
            {
                double meters = CoordinatePoint.HaversineDistance(state.Location, state.TargetMark.Location);
                if (meters < _distanceCutoff)//if the reported distance is more than this threshold, it's probably garbage data
                {
                    state.StateValues[StateValue.DistanceToTargetMarkInYards] = meters * MetersToYards;
                }

                var calculation = new MarkCalculation();
                calculation.Location = state.Location;
                calculation.Time     = state.BestTime;

                _previousCalculations.Add(calculation);
                while (_previousCalculations.Count > _previousCalculationCount)
                {
                    _previousCalculations.RemoveAt(0);
                }

                if (_previousCalculations.Count > 1)
                {
                    var previous = _previousCalculations[_previousCalculations.Count - 2];
                    var duration = calculation.Time - previous.Time;

                    //calculate vmc
                    var previousDistanceMeters = CoordinatePoint.HaversineDistance(previous.Location,
                                                                                   state.TargetMark.Location);
                    var distanceDelta      = previousDistanceMeters - meters;
                    var vmcMetersPerSecond = distanceDelta / duration.TotalSeconds;
                    var vmcKnots           = MetersPerSecondToKnots * vmcMetersPerSecond;
                    calculation.VelocityMadeGoodOnCourse = vmcKnots;
                    state.StateValues[StateValue.VelocityMadeGoodOnCourse] = vmcKnots;                    //_previousCalculations.Average(x => x.VelocityMadeGoodOnCourse);

                    state.StateValues[StateValue.VelocityMadeGoodOnCoursePercent] = vmcKnots / state.StateValues[StateValue.SpeedInKnots] * 100;

                    //TODO: calculate vmg
                    if (state.PreviousMark != null && state.StateValues.ContainsKey(StateValue.SpeedInKnots))
                    {
                        calculation.VelocityMadeGood = VelocityMadeGood(state.TargetMark, state.PreviousMark,
                                                                        calculation.Location, previous.Location, state.StateValues[StateValue.SpeedInKnots]);

                        state.StateValues[StateValue.VelocityMadeGoodPercent] = calculation.VelocityMadeGood.Value / state.StateValues[StateValue.SpeedInKnots] * 100;

                        var relativeAngle = RelativeAngleToCourse(state.TargetMark, state.PreviousMark, calculation.Location, previous.Location);
                        state.StateValues[StateValue.CourseOverGroundRelativeToCourse] = AngleUtilities.RadiansToDegrees(relativeAngle);
                    }
                }
            }
            else if (state.Course is CourseByAngle && state.StateValues.ContainsKey(StateValue.CourseOverGroundDirection) && state.StateValues.ContainsKey(StateValue.SpeedInKnots))
            {
                state.StateValues[StateValue.VelocityMadeGood]        = VelocityMadeGood((state.Course as CourseByAngle).CourseAngle, state.StateValues[StateValue.CourseOverGroundDirection], state.StateValues[StateValue.SpeedInKnots]);
                state.StateValues[StateValue.VelocityMadeGoodPercent] = state.StateValues[StateValue.VelocityMadeGood] / state.StateValues[StateValue.SpeedInKnots] * 100;

                var relativeAngle = AngleUtilities.AngleDifference(AngleUtilities.DegreestoRadians((state.Course as CourseByAngle).CourseAngle), AngleUtilities.DegreestoRadians(state.StateValues[StateValue.CourseOverGroundDirection]));
                state.StateValues[StateValue.CourseOverGroundRelativeToCourse] = AngleUtilities.RadiansToDegrees(relativeAngle);
            }
        }
        private Point CoordinatesToScreen(CoordinatePoint point)
        {
            Point off = Offset;
            Point p   = ScaleCoordinatesToScreen(point);

            p.X = p.X + off.X;
            p.Y = p.Y + off.Y;
            return(p);
        }
Example #17
0
        private static CoordinatePoint CreateCoordinatePoint(PointF point)
        {
            CoordinatePoint pt = new CoordinatePoint();

            pt.Ord    = new Double[2];
            pt.Ord[0] = point.X;
            pt.Ord[1] = point.Y;
            return(pt);
        }
Example #18
0
        private CoordinatePoint CreateCoordinatePoint(Coordinate coord)
        {
            CoordinatePoint pt = new CoordinatePoint();

            pt.Ord    = new Double[2];
            pt.Ord[0] = coord.x;
            pt.Ord[1] = coord.y;

            return(pt);
        }
Example #19
0
        public void ExtractPoints(ref Dictionary<DateTime, CoordinatePoint> points,XmlNode node)
        {
            if (node.Name.ToLower() == "placemark")
            {
                DateTime? when=null;
                CoordinatePoint point=null;
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name.ToLower() == "timestamp")
                    {
                        foreach (XmlNode whenNode in child.ChildNodes)
                        {
                            if (whenNode.Name.ToLower() == "when")
                            {
                                string timeString = whenNode.InnerText;
                                timeString = timeString.Replace('T', ' ').Replace('Z', ' ');
                                when = DateTime.Parse(timeString);
                            }
                        }
                    }
                    else if (child.Name.ToLower() == "point")
                    {
                        foreach (XmlNode coordinateNode in child.ChildNodes)
                        {
                            if (coordinateNode.Name.ToLower() == "coordinates")
                            {
                                string coordinateString = coordinateNode.InnerText;

                                char[] splitters = { ',' };
                                string[] coordinateParts = coordinateString.Split(splitters);

                                double longitude = double.Parse(coordinateParts[0],_numberCulture.NumberFormat);
                                double latitude = double.Parse(coordinateParts[1], _numberCulture.NumberFormat);
                                double altitude = double.Parse(coordinateParts[2], _numberCulture.NumberFormat);
                                point = new CoordinatePoint(new Coordinate(latitude), new Coordinate(longitude), altitude);
                            }
                        }
                    }
                }
                if (when.HasValue && point != null)
                {
                    if (!points.ContainsKey(when.Value))
                    {
                        points.Add(when.Value, point);
                    }
                }
            }
            else
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    ExtractPoints(ref points, child);
                }
            }
        }
Example #20
0
        public void ExtractPoints(ref Dictionary <DateTime, CoordinatePoint> points, XmlNode node)
        {
            if (node.Name.ToLower() == "placemark")
            {
                DateTime?       when  = null;
                CoordinatePoint point = null;
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name.ToLower() == "timestamp")
                    {
                        foreach (XmlNode whenNode in child.ChildNodes)
                        {
                            if (whenNode.Name.ToLower() == "when")
                            {
                                string timeString = whenNode.InnerText;
                                timeString = timeString.Replace('T', ' ').Replace('Z', ' ');
                                when       = DateTime.Parse(timeString);
                            }
                        }
                    }
                    else if (child.Name.ToLower() == "point")
                    {
                        foreach (XmlNode coordinateNode in child.ChildNodes)
                        {
                            if (coordinateNode.Name.ToLower() == "coordinates")
                            {
                                string coordinateString = coordinateNode.InnerText;

                                char[]   splitters       = { ',' };
                                string[] coordinateParts = coordinateString.Split(splitters);

                                double longitude = double.Parse(coordinateParts[0], _numberCulture.NumberFormat);
                                double latitude  = double.Parse(coordinateParts[1], _numberCulture.NumberFormat);
                                double altitude  = double.Parse(coordinateParts[2], _numberCulture.NumberFormat);
                                point = new CoordinatePoint(new Coordinate(latitude), new Coordinate(longitude), altitude);
                            }
                        }
                    }
                }
                if (when.HasValue && point != null)
                {
                    if (!points.ContainsKey(when.Value))
                    {
                        points.Add(when.Value, point);
                    }
                }
            }
            else
            {
                foreach (XmlNode child in node.ChildNodes)
                {
                    ExtractPoints(ref points, child);
                }
            }
        }
Example #21
0
        private bool FindGpsBounds(ref CoordinatePoint nw, ref CoordinatePoint se, ref double alt)
        {
            double?minLat  = null; // = double.MaxValue;
            double?maxLat  = null; // = double.MinValue;
            double?minLong = null; // = double.MaxValue;
            double?maxLong = null; // = double.MinValue;

            //double altitude = 0;
            //int altcount = 0;
            foreach (AmphibianSoftware.VisualSail.Data.Boat b in _boats)
            {
                //bool increment=false;
                if (b.GpsMinimumLatitude != null && (minLat == null || b.GpsMinimumLatitude < minLat))
                {
                    minLat = b.GpsMinimumLatitude;
                }
                if (b.GpsMaximumLatitude != null && (maxLat == null || b.GpsMaximumLatitude > maxLat))
                {
                    maxLat = b.GpsMaximumLatitude;
                }
                if (b.GpsMinimumLongitude != null && (minLong == null || b.GpsMinimumLongitude < minLong))
                {
                    minLong = b.GpsMinimumLongitude;
                }
                if (b.GpsMaximumLongitude != null && (maxLong == null || b.GpsMaximumLongitude > maxLong))
                {
                    maxLong = b.GpsMaximumLongitude;
                }
                //if (r.altitude != 0)
                //{
                //    if (altitude == 0)
                //    {
                //        altitude = r.altitude;
                //    }
                //    else
                //    {
                //        altitude = ((altitude * altcount) + r.altitude) / (altcount + 1);
                //    }
                //    altcount++;
                //}
                //count++;
            }

            if (minLat != null && maxLat != null && minLong != null && maxLong != null)
            {
                //alt = altitude;
                nw = new CoordinatePoint(new Coordinate((double)maxLat), new Coordinate((double)minLong), alt);
                se = new CoordinatePoint(new Coordinate((double)minLat), new Coordinate((double)maxLong), alt);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #22
0
        public void EqualTest()
        {
            var point1 = new CoordinatePoint(43.81234123, -164.243457567);
            var point2 = new CoordinatePoint(43.81234123, -164.243457567);
            var point3 = new CoordinatePoint(-60.813454769, 95.4567427812);

            Assert.AreEqual(point1, point2);
            Assert.IsTrue(point1 == point2);
            Assert.IsFalse(point1 == point3);
            Assert.IsTrue(point1 != point3);
        }
        public Desk CreateDesk()
        {
            string          deskNumber  = reader["DeskNumber"].ToString();
            CoordinatePoint TopLeft     = new CoordinatePoint((double)reader["TopLeftX"], (double)reader["TopLeftY"]);
            double          Orientation = (double)reader["Orientation"];
            Location        loc         = new Location((int)reader["FloorNumber"], TopLeft, Orientation);
            Employee        TempGuy     = this.CreateEmployee();

            Desk TempDesk = new Desk(loc, deskNumber, TempGuy);

            return(TempDesk);
        }
Example #24
0
        public void DistanceTest()
        {
            // expected distances takes from:
            //1. Lowrance HDS7 Gen3
            //2. http://edwilliams.org/gccalc.htm
            var basePoint = new CoordinatePoint(new Latitude(60, 07.328), new Longitude(32, 18.719));

            var two = new CoordinatePoint(new Latitude(60, 12.324), new Longitude(32, 15.530));

            //Lowrance HDS7 Gen3
            Assert.AreEqual(9710, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 5);
            Assert.AreEqual(9710, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 26);

            //edwilliams.org
            Assert.AreEqual(9735.229, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 25);
            Assert.AreEqual(9735.229, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.01d);             //great accuracy

            two = new CoordinatePoint(new Latitude(57, 36.631), new Longitude(29, 44.306));
            //Lowrance HDS7 Gen3
            Assert.AreEqual(315800, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 200);
            Assert.AreEqual(315800, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 1000);

            //edwilliams.org
            Assert.AreEqual(316682.824, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 700);
            Assert.AreEqual(316682.824, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 10);

            two = new CoordinatePoint(new Latitude(51, 11.377), new Longitude(44, 14.519));
            Assert.AreEqual(1239000, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 700);
            Assert.AreEqual(1239000, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 5000);

            two = new CoordinatePoint(new Latitude(60, 07.317), new Longitude(32, 18.822));
            //Lowrance HDS7 Gen3
            Assert.AreEqual(97.3d, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 0.1d);
            Assert.AreEqual(97.3d, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.4d);

            //edwilliams.org
            Assert.AreEqual(97.598, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 0.4d);
            Assert.AreEqual(97.598, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.01d);

            two = new CoordinatePoint(new Latitude(60, 07.330), new Longitude(32, 18.716));
            Assert.AreEqual(5.1d, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 0.5d);
            Assert.AreEqual(5.1d, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.5d);
            //too poor accuracy with flat method
            Assert.AreEqual(5.1d, CoordinatePoint.GetDistanceBetweenPointsOnTheFlat(basePoint, two).GetMeters(), 2);

            two = new CoordinatePoint(new Latitude(60, 07.374), new Longitude(32, 18.754));
            Assert.AreEqual(90.6d, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 1);
            Assert.AreEqual(90.6d, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.8d);

            two = new CoordinatePoint(new Latitude(60, 07.318), new Longitude(32, 18.734));
            Assert.AreEqual(23.2d, CoordinatePoint.GetDistanceBetweenPointsWithHaversine(basePoint, two).GetMeters(), 1);
            Assert.AreEqual(23.2d, CoordinatePoint.GetDistanceBetweenPointsOnAnEllipsoid(basePoint, two).GetMeters(), 0.01d);
        }
        public static bool Equals(this List <CoordinatePoint> arr, CoordinatePoint CoordinatPoint)
        {
            List <CoordinatePoint> result = new List <CoordinatePoint>();

            foreach (var item in arr)
            {
                result.AddRange(Crosswise(item));
            }
            var endMoves = Crosswise(CoordinatPoint);

            return(endMoves.Intersect(result).ToList().Count > 0);
        }
        private void LakeResizeControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (_lake != null)
            {
                _mousePosition = new Point(e.X, e.Y);
                if (_mouseDown && _selectedCorner.HasValue)
                {
                    this.Invalidate();
                }
                else
                {
                    double minDistance = 25.0;

                    CoordinatePoint a2 = new CoordinatePoint(new Coordinate(_lake.South), new Coordinate(_lake.East), 0);
                    CoordinatePoint b2 = new CoordinatePoint(new Coordinate(_lake.North), new Coordinate(_lake.West), 0);
                    Point           tl = CoordinatesToScreen(b2);
                    Point           br = CoordinatesToScreen(a2);
                    Point           tr = new Point(br.X, tl.Y);
                    Point           bl = new Point(tl.X, br.Y);

                    double tlDistance = CoordinatePoint.TwoDimensionalDistance(_mousePosition.X, _mousePosition.Y, tl.X, tl.Y);
                    double brDistance = CoordinatePoint.TwoDimensionalDistance(_mousePosition.X, _mousePosition.Y, br.X, br.Y);
                    double trDistance = CoordinatePoint.TwoDimensionalDistance(_mousePosition.X, _mousePosition.Y, tr.X, tr.Y);
                    double blDistance = CoordinatePoint.TwoDimensionalDistance(_mousePosition.X, _mousePosition.Y, bl.X, bl.Y);

                    if (tlDistance <= brDistance && tlDistance <= trDistance && tlDistance <= blDistance && tlDistance < minDistance)
                    {
                        _selectedCorner = SelectedCorner.TopLeft;
                        this.Cursor     = Cursors.PanNW;
                    }
                    else if (brDistance <= tlDistance && brDistance <= trDistance && brDistance <= blDistance && brDistance < minDistance)
                    {
                        _selectedCorner = SelectedCorner.BottomRight;
                        this.Cursor     = Cursors.PanSE;
                    }
                    else if (trDistance <= tlDistance && trDistance <= brDistance && trDistance <= blDistance && trDistance < minDistance)
                    {
                        _selectedCorner = SelectedCorner.TopRight;
                        this.Cursor     = Cursors.PanNE;
                    }
                    else if (blDistance <= tlDistance && blDistance <= brDistance && blDistance <= trDistance && blDistance < minDistance)
                    {
                        _selectedCorner = SelectedCorner.BottomLeft;
                        this.Cursor     = Cursors.PanSW;
                    }
                    else
                    {
                        _selectedCorner = null;
                        this.Cursor     = Cursors.No;
                    }
                }
            }
        }
Example #27
0
        /// <summary>
        /// Applies the filter to the <b>Coordinate</b>.
        /// </summary>
        /// <param name="coord">The <b>Coordinate</b>.</param>
        public void filter(Coordinate coord)
        {
            if (_projection == null)
            {
                return;
            }

            CoordinatePoint projectedCoordinatePoint = _projection.MathTransform.Transform(this.CreateCoordinatePoint(coord));

            coord.x = projectedCoordinatePoint.Ord[0];
            coord.y = projectedCoordinatePoint.Ord[1];
        }
Example #28
0
        public void GetCoordinatePointAtDistanceAndDirectionTest()
        {
            var baseCoordinatePoint = new CoordinatePoint(new Latitude(60, 07.328), new Longitude(32, 18.719));
            var _d2R = Math.PI / 180D;

            //expected values taken from http://edwilliams.org/gccalc.htm

            var pointWithSphereFormula    = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionWithHaversine(baseCoordinatePoint, LinearDimension.FromMeters(3.1d), 70 * _d2R, out _);
            var pointWithEllipsoidFormula = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionOnAnEllipsoid(baseCoordinatePoint, LinearDimension.FromMeters(3.1d), 70 * _d2R, out _);

            //Sphere
            Assert.AreEqual(60 + 7.3286 / 60d, pointWithSphereFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.7221 / 60d, pointWithSphereFormula.Longitude.ToDegrees(), 0.000001d);

            //Ellipsoid
            Assert.AreEqual(60 + 7.3286 / 60d, pointWithEllipsoidFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.7221 / 60d, pointWithEllipsoidFormula.Longitude.ToDegrees(), 0.000001d);

            pointWithSphereFormula    = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionWithHaversine(baseCoordinatePoint, LinearDimension.FromMeters(10.9d), 71 * _d2R, out _);
            pointWithEllipsoidFormula = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionOnAnEllipsoid(baseCoordinatePoint, LinearDimension.FromMeters(10.9d), 71 * _d2R, out _);

            //Sphere
            Assert.AreEqual(60 + 7.3299 / 60d, pointWithSphereFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.7301 / 60d, pointWithSphereFormula.Longitude.ToDegrees(), 0.000002d);             //2*10-6 !!!!

            //Ellipsoid
            Assert.AreEqual(60 + 7.3299 / 60d, pointWithEllipsoidFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.7301 / 60d, pointWithEllipsoidFormula.Longitude.ToDegrees(), 0.000001d);

            pointWithSphereFormula    = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionWithHaversine(baseCoordinatePoint, LinearDimension.FromMeters(97.8d), 88 * _d2R, out _);
            pointWithEllipsoidFormula = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionOnAnEllipsoid(baseCoordinatePoint, LinearDimension.FromMeters(97.8d), 88 * _d2R, out _);

            //Sphere
            Assert.AreEqual(60 + 7.3298 / 60d, pointWithSphereFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.8245 / 60d, pointWithSphereFormula.Longitude.ToDegrees(), 0.000007d);             //7*10-6 !!!!

            //Ellipsoid
            Assert.AreEqual(60 + 7.3298 / 60d, pointWithEllipsoidFormula.Latitude.ToDegrees(), 0.000001d);
            Assert.AreEqual(32 + 18.8245 / 60d, pointWithEllipsoidFormula.Longitude.ToDegrees(), 0.000001d);

            pointWithSphereFormula    = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionWithHaversine(baseCoordinatePoint, LinearDimension.FromMeters(1400), 233 * _d2R, out _);
            pointWithEllipsoidFormula = CoordinatePoint.GetCoordinatePointAtDistanceAndDirectionOnAnEllipsoid(baseCoordinatePoint, LinearDimension.FromMeters(1400), 233 * _d2R, out _);

            //Sphere
            //poor accuracy
            Assert.AreEqual(60 + 6.8742 / 60d, pointWithSphereFormula.Latitude.ToDegrees(), 0.00002d);             //2*10-5 !!!!
            Assert.AreEqual(32 + 17.5126 / 60d, pointWithSphereFormula.Longitude.ToDegrees(), 0.00008d);           //8*10-5 !!!!

            //Ellipsoid
            Assert.AreEqual(60 + 6.8742 / 60d, pointWithEllipsoidFormula.Latitude.ToDegrees(), 0.0000011d);
            Assert.AreEqual(32 + 17.5126 / 60d, pointWithEllipsoidFormula.Longitude.ToDegrees(), 0.000003d);
        }
        //This function adds coordinate points to the global list
        //These points will be displayed on the map.
        static void OnMesg(object sender, MesgEventArgs e)
        {
            try
            {
                CoordinatePoint coordinatePoint = new CoordinatePoint();
                foreach (Field field in e.mesg.Fields)
                {
                    for (int i = 0; i < field.GetNumValues(); i++)
                    {
                        //Use switch statement to set value on the coordinatePoint.
                        switch (field.GetName())
                        {
                        case LATITUDE:
                            coordinatePoint.latitude = reformatLatLong(field.GetValue(i).ToString());
                            break;

                        case LONGITUDE:
                            coordinatePoint.longitude = reformatLatLong(field.GetValue(i).ToString());
                            break;

                        case TIMESTAMP:
                            coordinatePoint.timeStamp = double.Parse(field.GetValue(i).ToString());
                            break;

                        case DISTANCE:
                            coordinatePoint.distance = double.Parse(field.GetValue(i).ToString());
                            break;

                        case SPEED:
                            coordinatePoint.speed = double.Parse(field.GetValue(i).ToString());
                            break;

                        case HEARTRATE:
                            coordinatePoint.heartRate = double.Parse(field.GetValue(i).ToString());
                            break;

                        default:
                            //do nothing :)
                            break;
                        }
                    }
                }
                if (coordinatePoint.HasLatLong())
                {
                    route.addCoordinatePoint(coordinatePoint);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing double for JSON." + ex.Message);
            }
        }
Example #30
0
        private Point CoordinatesToScreen(CoordinatePoint point)
        {
            Lake lake = _lake;

            if (_zoomed && _zoomedLake != null)
            {
                lake = _zoomedLake;
            }

            //find length and width of the scaled area
            double scaleWidth  = Math.Abs(lake.West - lake.East);
            double scaleHeight = Math.Abs(lake.North - lake.South);

            double scale;         //the ratio of panel width to scaled width
            int    dimension = 0; //the smallest dimension of the panel

            //set the scale based on whichever dimension is the longest
            //(if they are equal it doesn't matter)

            if (scaleWidth > scaleHeight)
            {
                if ((lakePNL.Width / scaleWidth) * scaleHeight <= lakePNL.Height)
                {
                    dimension = lakePNL.Width;
                    scale     = (double)dimension / scaleWidth;
                }
                else
                {
                    dimension = lakePNL.Height;
                    scale     = (double)dimension / scaleHeight;
                }
            }
            else
            {
                if (((double)lakePNL.Height / scaleHeight) * scaleWidth <= lakePNL.Width)
                {
                    dimension = lakePNL.Height;
                    scale     = (double)dimension / scaleHeight;
                }
                else
                {
                    dimension = lakePNL.Width;
                    scale     = (double)dimension / scaleWidth;
                }
            }

            Point output = new Point();

            output.X = (int)((point.Longitude.Value - lake.West) * scale);
            output.Y = (int)(scaleHeight * scale) - (int)((point.Latitude.Value - lake.South) * scale);
            return(output);
        }
Example #31
0
 /// <summary>
 /// find difference between current heading and course heading
 /// </summary>
 /// <param name="targetMark"></param>
 /// <param name="previousMark"></param>
 /// <param name="current"></param>
 /// <param name="previous"></param>
 /// <returns></returns>
 private double RelativeAngleToCourse(Mark targetMark, Mark previousMark, CoordinatePoint current, CoordinatePoint previous)
 {
     if (previousMark != null && targetMark != null)
     {
         float courseAngle = (float)AngleUtilities.FindAngle(targetMark.Location.Project(), previousMark.Location.Project());
         float boatAngle   = (float)AngleUtilities.FindAngle(previous.Project(), current.Project());;
         return(AngleUtilities.AngleDifference(courseAngle, boatAngle));
     }
     else
     {
         return(0);
     }
 }
        private void bindURI()
        {
            List<CoordinatePoint> pointURIs = new List<CoordinatePoint>();

            List<DBpedia.DbpediaInfo> dbpediaResults = DBpedia.getDbpediaInfo(_rasterInfo.rasterTopLeftX, _rasterInfo.rasterTopLeftY, _rasterInfo.rasterDownRightX, _rasterInfo.rasterDownRightY);
            DBpedia.DbpediaInfo answer = new DBpedia.DbpediaInfo();

            foreach (CoordinatePoint item in coordinatePoints)
            {
                answer = findMinDistance(item, dbpediaResults);
                CoordinatePoint pnt = new CoordinatePoint();
                pnt.lat = item.lat;
                pnt.lng = item.lng;
                item.URI = pnt.URI = answer.uri;
                item.type = pnt.type = answer.type;
                dbpediaResults.Remove(answer);
                pointURIs.Add(pnt);
            }
            string type = votting();
            for (int i = 0; i < coordinatePoints.Length; i++)

                if (pointURIs[i].type != type)
                    pointURIs[i].type = "";
        }
 private DBpedia.DbpediaInfo findMinDistance(CoordinatePoint item, List<DBpedia.DbpediaInfo> dbpediaResults)
 {
     double dis = int.MaxValue;
     double xS, yS, xD, yD;
     DBpedia.DbpediaInfo min = new DBpedia.DbpediaInfo();
     foreach (DBpedia.DbpediaInfo node in dbpediaResults)
     {
         GetXY(item.lng, item.lat, out xS, out yS);
         GetXY(node.lng, node.lat, out xD, out yD);
         double d = shortestDistance(xS, yS, xD, yD);
         if (d < dis)
         {
             dis = d;
             min = node;
         }
     }
     return min;
 }
        public void SymbolExtraction()
        {
            try
            {
                List<Bitmap> imgfnp_list = new List<Bitmap>();
                List<Bitmap> imgfnn_list = new List<Bitmap>();

                Image<Bgr, Byte> srcImage = new Image<Bgr, byte>(_rasterInfo.ratserImgPath);

                //sourceImageDir = CreateDirectory(parentInfo.FullName, "Data");
                ////////////////////Geo Spatial PRoject Sima//////////////////////

                fillSymbolList(imgfnp_list, srcImage);

                Image<Gray, Byte> gElement = null;

                HashSet<float[]> hash = symbolRecognition(out gElement, _rasterInfo.rasterData);

                coordinatePoints = new CoordinatePoint[hash.Count];
                pointSet = new Points[hash.Count];

                //....................................................................
                int j = 0;

                foreach (float[] i in hash)
                {
                    double lng, lat, x, y;
                    int neg = 1;
                    if (i[1] > 0 && _rasterInfo.ratserNegative < 0)
                        neg = _rasterInfo.ratserNegative;
                    pointSet[j] = new Points();
                    pointSet[j].leftTopX = i[0];
                    pointSet[j].leftTopY = i[1] * neg;
                    pointSet[j].rightTopX = i[0] + gElement.Size.Width;
                    pointSet[j].rightTopY = i[1] * neg;
                    pointSet[j].leftDownX = i[0];
                    pointSet[j].leftDownY = (i[1] + gElement.Size.Height) * neg;
                    pointSet[j].rightDownX = i[0] + gElement.Size.Width;
                    pointSet[j].rightDownY = (i[1] + gElement.Size.Height) * neg;

                    if (_rasterInfo.rasterType != "Unknown")
                    {

                        x = i[0] + gElement.Size.Width / 2;
                        y = i[1] + gElement.Size.Height / 2;
                        getLngLat(x, y, out lng, out lat);
                        coordinatePoints[j] = new CoordinatePoint();
                        coordinatePoints[j].lng = lng;
                        coordinatePoints[j].lat = lat;
                    }

                    j++;

                }
                #region Geo-Spatial Project- Connection to DBpredia
                if (_rasterInfo.rasterType != "Unknown")
                {
                    bindURI();
                    int num = 0;
                    foreach (CoordinatePoint pn in coordinatePoints)
                    {
                        pointSet[num].URI = pn.URI;
                        num++;
                    }
                }
                #endregion

            }
            catch (Exception e)
            {
                Log.WriteLine("textLayerExtract:  " + e.Message);
            }
        }