/// <summary>
        /// Initializes the transform using the parameters from the specified coordinate system information
        /// </summary>
        /// <param name="projInfo">A ProjectionInfo class contains all the standard and custom parameters needed to initialize this transform</param>
        protected override void OnInit(ProjectionInfo projInfo)
        {
            Y0 = projInfo.IsSouth ? 10000000 : 0;
            projInfo.FalseNorthing = Y0;
            X0 = 500000;
            projInfo.FalseEasting = X0;
            int zone;

            if (projInfo.Zone != null)
            {
                zone = projInfo.Zone.Value;
                if (zone <= 0 || zone > 60)
                {
                    throw new ProjectionException(35);
                }
                zone--;
            }
            else
            {
                zone = (int)Math.Floor((Proj.Adjlon(Lam0) + Math.PI) * 30 / Math.PI);
                if (zone < 0)
                {
                    zone = 0;
                }
                if (zone >= 60)
                {
                    zone = 59;
                }
            }
            Lam0          = (zone + .5) * Math.PI / 30.00 - Math.PI;
            projInfo.Lam0 = Lam0;
            K0            = 0.9996;
            Phi0          = 0;
            base.OnInit(projInfo);
        }
        /// <summary>
        /// Initializes the transform using the parameters from the specified coordinate system information
        /// </summary>
        /// <param name="projInfo">A ProjectionInfo class contains all the standard and custom parameters needed to initialize this transform</param>
        protected override void OnInit(ProjectionInfo projInfo)
        {
            double pp;

            /* get control point locations */
            double phi1 = projInfo.Phi1;
            double lam1 = projInfo.Lam1;
            double phi2 = projInfo.Phi2;
            double lam2 = projInfo.Lam2;

            if (phi1 == phi2 && lam1 == lam2)
            {
                throw new ProjectionException(-25);
            }
            Lam0   = Proj.Adjlon(0.5 * (lam1 + lam2));
            _dlam2 = Proj.Adjlon(lam2 - lam1);
            _cp1   = Math.Cos(phi1);
            _cp2   = Math.Cos(phi2);
            _sp1   = Math.Sin(phi1);
            _sp2   = Math.Sin(phi2);
            _cs    = _cp1 * _sp2;
            _sc    = _sp1 * _cp2;
            _ccs   = _cp1 * _cp2 * Math.Sin(_dlam2);
            _z02   = Proj.Aacos(_sp1 * _sp2 + _cp1 * _cp2 * Math.Cos(_dlam2));
            _hz0   = .5 * _z02;
            double a12 = Math.Atan2(_cp2 * Math.Sin(_dlam2),
                                    _cp1 * _sp2 - _sp1 * _cp2 * Math.Cos(_dlam2));

            _ca     = Math.Cos(pp = Proj.Aasin(_cp1 * Math.Sin(a12)));
            _sa     = Math.Sin(pp);
            _lp     = Proj.Adjlon(Math.Atan2(_cp1 * Math.Cos(a12), _sp1) - _hz0);
            _dlam2 *= .5;
            _lamc   = HALF_PI - Math.Atan2(Math.Sin(a12) * _sp1, Math.Cos(a12)) - _dlam2;
            _thz0   = Math.Tan(_hz0);
            _rhshz0 = .5 / Math.Sin(_hz0);
            _r2Z0   = 0.5 / _z02;
            _z02   *= _z02;
        }
Exemple #3
0
        /// <inheritdoc />
        protected override void OnForward(double[] lp, double[] xy, int startIndex, int numPoints)
        {
            bool   bAlphaIs90     = Math.Abs(Math.Abs(_alpha) - HALF_PI) <= EPS10;
            double _lamcMinusLam0 = Proj.Adjlon(_lamc - Lam0);

            for (int i = startIndex; i < startIndex + numPoints; i++)
            {
                int    phi = i * 2 + PHI;
                int    lam = i * 2 + LAMBDA;
                int    x = i * 2 + X;
                int    y = i * 2 + Y;
                double ul, us;
                double vl = Math.Sin(_bl * lp[lam]);
                if (Math.Abs(Math.Abs(lp[phi]) - Math.PI / 2) <= EPS10)
                {
                    ul = lp[phi] < 0 ? -_singam : _singam;
                    us = _al * lp[phi] / _bl;
                }
                else
                {
                    double q = _el / (_ellips ? Math.Pow(Proj.Tsfn(lp[phi], Math.Sin(lp[phi]), E), _bl) : Tsfn0(lp[phi]));
                    double s = .5 * (q - 1 / q);
                    ul = 2.0 * (s * _singam - vl * _cosgam) / (q + 1.0 / q);
                    double con = Math.Cos(_bl * lp[lam]);
                    if (Math.Abs(con) >= TOLERANCE)
                    {
                        us = _al * Math.Atan((s * _cosgam + vl * _singam) / con) / _bl;
                        // if (con < 0) us += Math.PI * _al / _bl; taken care of below...
                    }
                    else
                    {
                        us = _al * _bl * lp[lam];
                    }
                }
                if (Math.Abs(Math.Abs(ul) - 1.0) <= EPS10)
                {
                    xy[x] = double.NaN;
                    xy[y] = double.NaN;
                    continue;
                    //ProjectionException(20);
                }
                double vs = .5 * _al * Math.Log((1 - ul) / (1 + ul)) / _bl;

                if (bAlphaIs90)
                {
                    if (Math.Abs(_lamcMinusLam0 - lp[lam]) < EPS10)
                    {
                        us = 0;
                    }
                    else if (_lamcMinusLam0 - lp[lam] < 0)  // from OGP guidance note 7 term: "SIGN(lamc-lam)"
                    {
                        us -= -_u0;
                    }
                    else
                    {
                        us -= _u0;
                    }
                }
                else
                {
                    us -= _u0;
                }

                xy[x] = vs * _cosrot + us * _sinrot;
                xy[y] = us * _cosrot - vs * _sinrot;
            }
        }
        /// <summary>
        /// Initializes the transform using the parameters from the specified coordinate system information
        /// </summary>
        /// <param name="projInfo">A ProjectionInfo class contains all the standard and custom parameters needed to initialize this transform</param>
        protected override void OnInit(ProjectionInfo projInfo)
        {
            double con;
            double f;
            double d;
            double toRadians = projInfo.GeographicInfo.Unit.Radians;

            _rot = !projInfo.no_rot.HasValue || projInfo.no_rot.Value == 0;
            bool azi = projInfo.alpha.HasValue;

            if (azi)
            {
                if (projInfo.lonc.HasValue)
                {
                    _lamc = projInfo.lonc.Value * toRadians;
                }
                if (projInfo.alpha.HasValue)
                {
                    _alpha = projInfo.alpha.Value * toRadians;
                }
                if (Math.Abs(_alpha) < TOLERANCE ||
                    Math.Abs(Math.Abs(Phi0) - HALF_PI) <= TOLERANCE ||
                    Math.Abs(Math.Abs(_alpha) - HALF_PI) <= TOLERANCE)
                {
                    throw new ProjectionException(32);
                }
            }
            else
            {
                _lam1 = projInfo.Lam1;
                _phi1 = projInfo.Phi1;
                _lam2 = projInfo.Lam2;
                _phi2 = projInfo.Phi2;
                if (Math.Abs(_phi1 - _phi2) <= TOLERANCE ||
                    (con = Math.Abs(_phi1)) <= TOLERANCE ||
                    Math.Abs(con - HALF_PI) <= TOLERANCE ||
                    Math.Abs(Math.Abs(Phi0) - HALF_PI) <= TOLERANCE ||
                    Math.Abs(Math.Abs(_phi2) - HALF_PI) <= TOLERANCE)
                {
                    throw new ProjectionException(33);
                }
            }
            _ellips = Es > 0;
            double com = _ellips ? Math.Sqrt(OneEs) : 1;

            if (Math.Abs(Phi0) > EPS10)
            {
                double sinph0 = Math.Sin(Phi0);
                double cosph0 = Math.Cos(Phi0);
                if (_ellips)
                {
                    con = 1 - Es * sinph0 * sinph0;
                    _bl = cosph0 * cosph0;
                    _bl = Math.Sqrt(1 + Es * _bl * _bl / OneEs);
                    _al = _bl * K0 * com / con;
                    d   = _bl * com / (cosph0 * Math.Sqrt(con));
                }
                else
                {
                    _bl = 1;
                    _al = K0;
                    d   = 1 / cosph0;
                }

                if ((f = d * d - 1) <= 0)
                {
                    f = 0;
                }
                else
                {
                    f = Math.Sqrt(f);
                    if (Phi0 < 0)
                    {
                        f = -f;
                    }
                }
                _el = f += d;
                if (_ellips)
                {
                    _el *= Math.Pow(Proj.Tsfn(Phi0, sinph0, E), _bl);
                }
                else
                {
                    _el *= Tsfn0(Phi0);
                }
            }
            else
            {
                _bl = 1 / com;
                _al = K0;
                _el = d = f = 1;
            }
            if (azi)
            {
                _gamma        = Math.Asin(Math.Sin(_alpha) / d);
                Lam0          = _lamc - Math.Asin((.5 * (f - 1 / f)) * Math.Tan(_gamma)) / _bl;
                projInfo.Lam0 = Lam0;
            }
            else
            {
                double h;
                double l;
                if (_ellips)
                {
                    h = Math.Pow(Proj.Tsfn(_phi1, Math.Sin(_phi1), E), _bl);
                    l = Math.Pow(Proj.Tsfn(_phi2, Math.Sin(_phi2), E), _bl);
                }
                else
                {
                    h = Tsfn0(_phi1);
                    l = Tsfn0(_phi2);
                }
                f = _el / h;
                double p = (l - h) / (l + h);
                double j = _el * _el;
                j = (j - l * h) / (j + l * h);
                if ((con = _lam1 - _lam2) < -Math.PI)
                {
                    _lam2 -= Math.PI * 2;
                }
                else if (con > Math.PI)
                {
                    _lam2 += Math.PI * 2;
                }
                Lam0          = Proj.Adjlon(.5 * (_lam1 + _lam2) - Math.Atan(j * Math.Tan(.5 * _bl * (_lam1 - _lam2)) / p) / _bl);
                projInfo.Lam0 = Lam0;
                _gamma        = Math.Atan(2 * Math.Sin(_bl * Proj.Adjlon(_lam1 - Lam0)) / (f - 1 / f));
                _alpha        = Math.Asin(d * Math.Sin(_gamma));
            }
            _singam = Math.Sin(_gamma);
            _cosgam = Math.Cos(_gamma);
            if (projInfo.rot_conv.HasValue)
            {
                f = _alpha;
            }
            else
            {
                f = _gamma;
            }
            _sinrot = Math.Sin(f);
            _cosrot = Math.Cos(f);
            if (projInfo.no_uoff.HasValue)
            {
                _u0 = Math.Abs(_al * Math.Atan(Math.Sqrt(d * d - 1) / _cosrot) / _bl);
            }
            else
            {
                _u0 = 0;
            }
            if (Phi0 < 0)
            {
                _u0 = -_u0;
            }
        }