Ejemplo n.º 1
0
        private const double RadiusOfEarth = 6371000.0; // radius in meter

        public IGeoCoordinate DoubleToGeoCoordinate(GeoCoordinateType coordinateType, double angleInDegrees)
        {
            //ensure the value will fall within the primary range [-180.0..+180.0]
            while (angleInDegrees < -180.0)
            {
                angleInDegrees += 360.0;
            }

            while (angleInDegrees > 180.0)
            {
                angleInDegrees -= 360.0;
            }

            var isNegative = angleInDegrees < 0;

            //switch the value to positive
            angleInDegrees = Math.Abs(angleInDegrees);

            //gets the degree
            var degrees = (int)Math.Floor(angleInDegrees);
            var delta   = angleInDegrees - degrees;

            //gets minutes and seconds
            var secondsTotal     = delta * 3600.0;
            var minutes          = (int)Math.Floor(secondsTotal / 60.0);
            var secondsRemainder = secondsTotal - minutes * 60;

            return(new GeoCoordinate(coordinateType, isNegative, degrees, minutes, secondsRemainder));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new Geo Coordinate of type DMS. (Degree, Minute, Second)
        /// </summary>
        /// <param name="type">type of the coordinate</param>
        /// <param name="isNegative">should be true for locations to the south and west. false for locations to the north and east.</param>
        /// <param name="degrees">angle in degrees (must be positive value)</param>
        /// <param name="minutes">partial of 1 degree in minutes. (60 min = 1°)</param>
        /// <param name="seconds">partial of 1 degree in seconds. (3600 s = 1°)</param>
        public GeoCoordinate(
            GeoCoordinateType type,
            bool isNegative,
            int degrees,
            int minutes,
            double seconds)
        {
            // Argument validation
            switch (type)
            {
            case GeoCoordinateType.Latitude when degrees < 0 || degrees > 90:
                throw new ArgumentOutOfRangeException(nameof(degrees), $"latitude value of {nameof(degrees)} must be between 0 to 90. Value: {degrees}");

            case GeoCoordinateType.Longitude when degrees < 0 || degrees > 180:
                throw new ArgumentOutOfRangeException(nameof(degrees), $"longitude values of {nameof(degrees)} must be between 0 to 180. Value: {degrees}");
            }
            if (minutes < 0 || minutes > 59)
            {
                throw new ArgumentOutOfRangeException(nameof(minutes), $"{nameof(minutes)} must be 0 to 59. Value: {minutes}");
            }
            if (seconds < 0.0 || seconds >= 60.0)
            {
                throw new ArgumentOutOfRangeException(nameof(seconds), $"{nameof(seconds)} must be greater or even 0 and lesser than 60. Value: {seconds}");
            }

            Type       = type;
            IsNegative = isNegative;
            Degrees    = degrees;
            Minutes    = minutes;
            Seconds    = seconds;
        }
Ejemplo n.º 3
0
 public GeoCoordinate(GeoCoordinate coordinate, GeoCoordinateType type = GeoCoordinateType.Latitude)
 {
     this.IsPositiveCoordinate = coordinate.IsPositiveCoordinate;
     this.Degrees        = coordinate.Degrees;
     this.Minutes        = coordinate.Minutes;
     this.Seconds        = coordinate.Seconds;
     this.CoordinateType = type;
     this.Total          = coordinate.Total;
 }
Ejemplo n.º 4
0
 public GeoCoordinate(int degrees, int minutes, double seconds, GeoCoordinateType type = GeoCoordinateType.Latitude)
 {
     this.IsPositiveCoordinate = !((degrees < 0) || (minutes < 0) || (seconds < 0));
     this.Degrees        = System.Math.Abs(degrees);
     this.Minutes        = System.Math.Abs(minutes);
     this.Seconds        = System.Math.Abs(seconds);
     this.CoordinateType = type;
     this.Total          = this.ConvertToDouble();
 }
Ejemplo n.º 5
0
 public GeoCoordinate(double location, GeoCoordinateType type = GeoCoordinateType.Latitude)
     : this(GeoCoordinate.ConvertFromDouble(location), type)
 {
 }
Ejemplo n.º 6
0
 public GeoCoordinate(GeoCoordinateType type = GeoCoordinateType.Latitude)
     : this(0, 0, 0.0, type)
 {
 }
Ejemplo n.º 7
0
        public GeodeticPoint(ReferenceEllipsoid refEll, GeoCoordinateType geoType, params string[] data)
        {
            re = refEll;
            GeoXYZ gXYZ = new GeoXYZ(0, 0, 0);
            GeoBLH gBLH = new GeoBLH(0, 0, 0);
            GeoxyH gxyH = new GeoxyH(0, 0, 0);

            switch (geoType)
            {
            case GeoCoordinateType.XYZ:
                if (data.Length != 3)
                {
                    break;
                }
                else
                {
                    gXYZ = new GeoXYZ(data[0], data[1], data[2]);
                    gBLH = ConvertXYZToBLH(gXYZ);
                    gxyH = ConvertBLHToxyH(gBLH);
                }
                break;

            case GeoCoordinateType.BLH:
                if (data.Length == 2)
                {
                    gBLH = new GeoBLH(data[0], data[1]);
                    gXYZ = ConvertBLHToXYZ(gBLH);
                    gxyH = ConvertBLHToxyH(gBLH);
                }
                else if (data.Length == 3)
                {
                    gBLH = new GeoBLH(data[0], data[1], data[2]);
                    gXYZ = ConvertBLHToXYZ(gBLH);
                    gxyH = ConvertBLHToxyH(gBLH);
                }
                else
                {
                    break;
                }
                break;

            default:
                if (data.Length == 2)
                {
                    gxyH = new GeoxyH(data[0], data[1]);
                    gBLH = ConvertxyHToBLH(gxyH);
                    gXYZ = ConvertBLHToXYZ(gBLH);
                }
                else if (data.Length == 3)
                {
                    gxyH = new GeoxyH(data[0], data[1], data[3]);
                    gBLH = ConvertxyHToBLH(gxyH);
                    gXYZ = ConvertBLHToXYZ(gBLH);
                }
                else
                {
                    break;
                }
                break;
            }
            gX = gXYZ.gX;
            gY = gXYZ.gY;
            gZ = gXYZ.gZ;
            gB = gBLH.gB;
            gL = gBLH.gL;
            gH = gBLH.gH;
            gx = gxyH.gx;
            gy = gxyH.gy;
        }