Ejemplo n.º 1
0
        // longitude0, latitude0, parallel1, parallel2
        public AlbersEqualAreaProjection(Dictionary <String, double> parameters)
            : base(parameters)
        {
            double latitude0_rad = InputLatitude("latitude0");
            double parallel1_rad = InputLatitude("parallel1");
            double parallel2_rad = InputLatitude("parallel2");

            double cos_parallel1 = Math.Cos(parallel1_rad);
            double sin_parallel1 = Math.Sin(parallel1_rad);

            _n2 = sin_parallel1 + Math.Sin(parallel2_rad);
            if (Math.Abs(_n2) <= MathX.Tolerance)
            {
                throw new ArgumentOutOfRangeException();
            }

            _n      = _n2 / 2;
            _n_half = _n2 / 4;
            _inv_n2 = 1 / _n2;
            _inv_n  = 2 / _n2;

            _c         = MathX.Square(cos_parallel1) + sin_parallel1 * _n2;
            _c_over_n2 = _c * _inv_n2;

            double a = _c - Math.Sin(latitude0_rad) * _n2;

            if (a < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            _ro_0 = Math.Sqrt(a) * _inv_n;
        }
        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);
        }