Beispiel #1
0
        // Longitude and latitude are in degrees.
        // Output Latitude will be in range [-90, 90].
        // Output Longitude will be in range [-180, 180].
        //
        public void UnprojectPoint(double x, double y, out double latitudeDeg, out double longitudeDeg)
        {
            if (Double.IsNaN(x))
            {
                throw new ArgumentException(Resource.InputCoordinateIsNaN, "x");
            }
            if (Double.IsNaN(y))
            {
                throw new ArgumentException(Resource.InputCoordinateIsNaN, "y");
            }

            double latitude, longitude;

            _projection.Unproject(x, y, out latitude, out longitude);

            if (Double.IsNaN(latitude) || latitude < -Math.PI / 2 || latitude > Math.PI / 2)
            {
                throw new ArgumentOutOfRangeException("latitude", String.Format(CultureInfo.InvariantCulture, Resource.OutputLatitudeIsOutOfRange, latitude));
            }
            if (Double.IsNaN(longitude) || longitude < -Math.PI || longitude > Math.PI)
            {
                throw new ArgumentOutOfRangeException("longitude", String.Format(CultureInfo.InvariantCulture, Resource.OutputLongitudeIsOutOfRange, longitude));
            }

            latitudeDeg  = MathX.Clamp(90, Util.ToDegrees(latitude));
            longitudeDeg = MathX.NormalizeLongitudeDeg(Util.ToDegrees(longitude + _projection.CentralLongitudeRad));
        }
        protected internal override void Unproject(double x, double y, out double latitude, out double longitude)
        {
            double ro = Math.Sign(_n) * Math.Sqrt(x * x + MathX.Square(_ro_0 - y));

            // If ro is zero or very small then then latitude will be +-Pi/2 depending on the sign of f.
            latitude  = 2 * Math.Atan(Math.Pow(_f / ro, _nInv)) - Math.PI / 2;
            longitude = MathX.Clamp(Math.PI, Math.Atan2(x, _ro_0 - y) * _nInv);
        }
Beispiel #3
0
        protected internal override void Unproject(double x, double y, out double latitude, out double longitude)
        {
            double ros = x * x + (_ro_0 - y) * (_ro_0 - y);
            double a   = _c_over_n2 - ros * _n_half;

            if (Double.IsNaN(a) || Math.Abs(a) > 1 + MathX.Tolerance)
            {
                throw new ArgumentOutOfRangeException("x, y");
            }

            latitude  = Math.Asin(MathX.Clamp(1, a));
            longitude = MathX.Clamp(Math.PI, MathX.Atan2(x, _ro_0 - y, "x, y") * _inv_n);
        }
Beispiel #4
0
        protected internal override void Project(double latitude, double longitude, out double x, out double y)
        {
            double sin_lat = Math.Sin(latitude);
            double cos_lat = Math.Cos(latitude);

            double sin_long = Math.Sin(longitude);
            double cos_long = Math.Cos(longitude);

            double a = _sin_fi_p * sin_lat - _cos_fi_p * cos_lat * sin_long;             // sin_fi_p

            if (Double.IsNaN(a) || Math.Abs(a) > 1)
            {
                throw new ArgumentOutOfRangeException("latitude, longitude");
            }

            x = MathX.Atan2(sin_lat / cos_lat * _cos_fi_p + sin_long * _sin_fi_p, cos_long, "latitude, longitude");
            y = MathX.Clamp(MaxY, Math.Log((1 + a) / (1 - a)) / 2);             // protect againt +-Infinity
        }
        // x will be in range [-MaxX, MaxX]
        // y will be in range [-Pi, Pi]
        protected internal override void Project(double latitude, double longitude, out double x, out double y)
        {
            // North pole
            if (latitude >= Math.PI / 2 - MathX.Tolerance)
            {
                x = 0;
                y = Math.PI / 2;
                return;
            }

            // South pole
            if (latitude <= -Math.PI / 2 + MathX.Tolerance)
            {
                x = 0;
                y = -Math.PI / 2;
                return;
            }

            if (Math.Abs(latitude) <= MathX.Tolerance)
            {
                // East of India
                if (Math.Abs(longitude - Math.PI / 2) <= MathX.Tolerance)
                {
                    x = MaxX;
                    y = 0;
                    return;
                }
                // West of South America
                if (Math.Abs(longitude + Math.PI / 2) <= MathX.Tolerance)
                {
                    x = -MaxX;
                    y = 0;
                    return;
                }
            }

            double b = Math.Cos(latitude) * Math.Sin(longitude);

            x = MathX.Clamp(MaxX, Math.Log((1 + b) / (1 - b)) / 2);
            y = Math.Atan2(Math.Tan(latitude), Math.Cos(longitude));
        }
 protected internal override void Project(double latitude, double longitude, out double x, out double y)
 {
     x = longitude;
     y = MathX.Clamp(MaxY, Math.Log(Math.Tan(Math.PI / 4 + latitude / 2)));             // protect againt +-Infinity
 }