void setup_eqdc(Parameters& par, par_eqdc& proj_parm) { double cosphi, sinphi; int secant; proj_parm.phi1 = pj_param(par.params, "rlat_1").f; proj_parm.phi2 = pj_param(par.params, "rlat_2").f; if (fabs(proj_parm.phi1 + proj_parm.phi2) < EPS10) throw proj_exception(-21); pj_enfn(par.es, proj_parm.en); proj_parm.n = sinphi = sin(proj_parm.phi1); cosphi = cos(proj_parm.phi1); secant = fabs(proj_parm.phi1 - proj_parm.phi2) >= EPS10; if( (proj_parm.ellips = (par.es > 0.)) ) { double ml1, m1; m1 = pj_msfn(sinphi, cosphi, par.es); ml1 = pj_mlfn(proj_parm.phi1, sinphi, cosphi, proj_parm.en); if (secant) { /* secant cone */ sinphi = sin(proj_parm.phi2); cosphi = cos(proj_parm.phi2); proj_parm.n = (m1 - pj_msfn(sinphi, cosphi, par.es)) / (pj_mlfn(proj_parm.phi2, sinphi, cosphi, proj_parm.en) - ml1); } proj_parm.c = ml1 + m1 / proj_parm.n; proj_parm.rho0 = proj_parm.c - pj_mlfn(par.phi0, sin(par.phi0), cos(par.phi0), proj_parm.en); } else { if (secant) proj_parm.n = (cosphi - cos(proj_parm.phi2)) / (proj_parm.phi2 - proj_parm.phi1); proj_parm.c = proj_parm.phi1 + cos(proj_parm.phi1) / proj_parm.n; proj_parm.rho0 = proj_parm.c - par.phi0; } // par.inv = e_inverse; // par.fwd = e_forward; // par.spc = fac; }
PJ *PROJECTION(imw_p) { double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2; int err; struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque))); if (nullptr==Q) return pj_default_destructor (P, ENOMEM); P->opaque = Q; if (!(Q->en = pj_enfn(P->es))) return pj_default_destructor (P, ENOMEM); if( (err = phi12(P, &del, &sig)) != 0) { return destructor(P, err); } if (Q->phi_2 < Q->phi_1) { /* make sure P->phi_1 most southerly */ del = Q->phi_1; Q->phi_1 = Q->phi_2; Q->phi_2 = del; } if (pj_param(P->ctx, P->params, "tlon_1").i) Q->lam_1 = pj_param(P->ctx, P->params, "rlon_1").f; else { /* use predefined based upon latitude */ sig = fabs(sig * RAD_TO_DEG); if (sig <= 60) sig = 2.; else if (sig <= 76) sig = 4.; else sig = 8.; Q->lam_1 = sig * DEG_TO_RAD; } Q->mode = NONE_IS_ZERO; if (Q->phi_1 != 0.0) xy(P, Q->phi_1, &x1, &y1, &Q->sphi_1, &Q->R_1); else { Q->mode = PHI_1_IS_ZERO; y1 = 0.; x1 = Q->lam_1; } if (Q->phi_2 != 0.0) xy(P, Q->phi_2, &x2, &T2, &Q->sphi_2, &Q->R_2); else { Q->mode = PHI_2_IS_ZERO; T2 = 0.; x2 = Q->lam_1; } m1 = pj_mlfn(Q->phi_1, Q->sphi_1, cos(Q->phi_1), Q->en); m2 = pj_mlfn(Q->phi_2, Q->sphi_2, cos(Q->phi_2), Q->en); t = m2 - m1; s = x2 - x1; y2 = sqrt(t * t - s * s) + y1; Q->C2 = y2 - T2; t = 1. / t; Q->P = (m2 * y1 - m1 * y2) * t; Q->Q = (y2 - y1) * t; Q->Pp = (m2 * x1 - m1 * x2) * t; Q->Qp = (x2 - x1) * t; P->fwd = e_forward; P->inv = e_inverse; P->destructor = destructor; return P; }
PJ *PROJECTION(eqdc) { double cosphi, sinphi; int secant; struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return pj_default_destructor (P, ENOMEM); P->opaque = Q; P->destructor = destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; Q->phi2 = pj_param(P->ctx, P->params, "rlat_2").f; if (fabs(Q->phi1 + Q->phi2) < EPS10) return pj_default_destructor (P, PJD_ERR_CONIC_LAT_EQUAL); if (!(Q->en = pj_enfn(P->es))) return pj_default_destructor(P, ENOMEM); Q->n = sinphi = sin(Q->phi1); cosphi = cos(Q->phi1); secant = fabs(Q->phi1 - Q->phi2) >= EPS10; if( (Q->ellips = (P->es > 0.)) ) { double ml1, m1; m1 = pj_msfn(sinphi, cosphi, P->es); ml1 = pj_mlfn(Q->phi1, sinphi, cosphi, Q->en); if (secant) { /* secant cone */ sinphi = sin(Q->phi2); cosphi = cos(Q->phi2); Q->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) / (pj_mlfn(Q->phi2, sinphi, cosphi, Q->en) - ml1); } Q->c = ml1 + m1 / Q->n; Q->rho0 = Q->c - pj_mlfn(P->phi0, sin(P->phi0), cos(P->phi0), Q->en); } else { if (secant) Q->n = (cosphi - cos(Q->phi2)) / (Q->phi2 - Q->phi1); Q->c = Q->phi1 + cos(Q->phi1) / Q->n; Q->rho0 = Q->c - P->phi0; } P->inv = e_inverse; P->fwd = e_forward; return P; }
PJ *PROJECTION(bonne) { double c; struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque))); if (nullptr==Q) return pj_default_destructor (P, ENOMEM); P->opaque = Q; P->destructor = destructor; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; if (fabs(Q->phi1) < EPS10) return destructor (P, PJD_ERR_LAT1_IS_ZERO); if (P->es != 0.0) { Q->en = pj_enfn(P->es); if (nullptr==Q->en) return destructor(P, ENOMEM); Q->m1 = pj_mlfn(Q->phi1, Q->am1 = sin(Q->phi1), c = cos(Q->phi1), Q->en); Q->am1 = c / (sqrt(1. - P->es * Q->am1 * Q->am1) * Q->am1); P->inv = e_inverse; P->fwd = e_forward; } else { if (fabs(Q->phi1) + EPS10 >= M_HALFPI) Q->cphi1 = 0.; else Q->cphi1 = 1. / tan(Q->phi1); P->inv = s_inverse; P->fwd = s_forward; } return P; }
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const { double s, c; xy_y = pj_mlfn(lp_lat, s = sin(lp_lat), c = cos(lp_lat), this->m_proj_parm.en); xy_x = lp_lon * c / sqrt(1. - this->m_par.es * s * s); }
PJ *PROJECTION(lcca) { double s2p0, N0, R0, tan0; struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque))); if (nullptr==Q) return pj_default_destructor (P, ENOMEM); P->opaque = Q; (Q->en = pj_enfn(P->es)); if (!Q->en) return pj_default_destructor (P, ENOMEM); if (P->phi0 == 0.) { return destructor(P, PJD_ERR_LAT_0_IS_ZERO); } Q->l = sin(P->phi0); Q->M0 = pj_mlfn(P->phi0, Q->l, cos(P->phi0), Q->en); s2p0 = Q->l * Q->l; R0 = 1. / (1. - P->es * s2p0); N0 = sqrt(R0); R0 *= P->one_es * N0; tan0 = tan(P->phi0); Q->r0 = N0 / tan0; Q->C = 1. / (6. * R0 * N0); P->inv = lcca_e_inverse; P->fwd = lcca_e_forward; P->destructor = destructor; return P; }
PJ *PROJECTION(bonne) { double c; struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; if (fabs(Q->phi1) < EPS10) E_ERROR(-23); if (P->es) { Q->en = pj_enfn(P->es); Q->m1 = pj_mlfn(Q->phi1, Q->am1 = sin(Q->phi1), c = cos(Q->phi1), Q->en); Q->am1 = c / (sqrt(1. - P->es * Q->am1 * Q->am1) * Q->am1); P->inv = e_inverse; P->fwd = e_forward; } else { if (fabs(Q->phi1) + EPS10 >= M_HALFPI) Q->cphi1 = 0.; else Q->cphi1 = 1. / tan(Q->phi1); P->inv = s_inverse; P->fwd = s_forward; } return P; }
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const { double rh, E, c; rh = this->m_proj_parm.am1 + this->m_proj_parm.m1 - pj_mlfn(lp_lat, E = sin(lp_lat), c = cos(lp_lat), this->m_proj_parm.en); E = c * lp_lon / (rh * sqrt(1. - this->m_par.es * E * E)); xy_x = rh * sin(E); xy_y = this->m_proj_parm.am1 - rh * cos(E); }
// FORWARD(e_forward) ellipsoid // Project coordinates from geographic (lon, lat) to cartesian (x, y) inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const { CalculationType S, r, dr; S = pj_mlfn(lp_lat, sin(lp_lat), cos(lp_lat), this->m_proj_parm.en) - this->m_proj_parm.M0; dr = fS(S, this->m_proj_parm.C); r = this->m_proj_parm.r0 - dr; xy_x = this->m_par.k0 * (r * sin( lp_lon *= this->m_proj_parm.l ) ); xy_y = this->m_par.k0 * (this->m_proj_parm.r0 - r * cos(lp_lon) ); }
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ XY xy = {0.0,0.0}; struct pj_opaque *Q = P->opaque; Q->rho = Q->c - (Q->ellips ? pj_mlfn(lp.phi, sin(lp.phi), cos(lp.phi), Q->en) : lp.phi); xy.x = Q->rho * sin( lp.lam *= Q->n ); xy.y = Q->rho0 - Q->rho * cos(lp.lam); return xy; }
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ XY xy = {0.0,0.0}; struct pj_opaque *Q = P->opaque; double rh, E, c; rh = Q->am1 + Q->m1 - pj_mlfn(lp.phi, E = sin(lp.phi), c = cos(lp.phi), Q->en); E = c * lp.lam / (rh * sqrt(1. - P->es * E * E)); xy.x = rh * sin(E); xy.y = Q->am1 - rh * cos(E); return xy; }
inline void e_guam_fwd(T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y, Par const& par, ProjParm const& proj_parm) { T cosphi, sinphi, t; cosphi = cos(lp_lat); sinphi = sin(lp_lat); t = 1. / sqrt(1. - par.es * sinphi * sinphi); xy_x = lp_lon * cosphi * t; xy_y = pj_mlfn(lp_lat, sinphi, cosphi, proj_parm.en) - proj_parm.M1 + .5 * lp_lon * lp_lon * cosphi * sinphi * t; }
static PJ_XY lcca_e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0,0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double S, r, dr; S = pj_mlfn(lp.phi, sin(lp.phi), cos(lp.phi), Q->en) - Q->M0; dr = fS(S, Q->C); r = Q->r0 - dr; xy.x = P->k0 * (r * sin( lp.lam *= Q->l ) ); xy.y = P->k0 * (Q->r0 - r * cos(lp.lam) ); return xy; }
double pj_inv_mlfn(double arg, double es, double *en) { double s, t, phi, k = 1./(1.-es); int i; phi = arg; for (i = MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */ s = sin(phi); t = 1. - es * s * s; phi -= t = (pj_mlfn(phi, s, cos(phi), en) - arg) * (t * sqrt(t)) * k; if (fabs(t) < EPS) return phi; } pj_errno = -17; return phi; }
static PJ_XY e_forward (PJ_LP lp, PJ *P) { /* Ellipsoidal, forward */ PJ_XY xy = {0.0,0.0}; struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); double rh, E, c; rh = Q->am1 + Q->m1 - pj_mlfn(lp.phi, E = sin(lp.phi), c = cos(lp.phi), Q->en); if (fabs(rh) > EPS10) { E = c * lp.lam / (rh * sqrt(1. - P->es * E * E)); xy.x = rh * sin(E); xy.y = Q->am1 - rh * cos(E); } else { xy.x = 0.; xy.y = 0.; } return xy; }
inline double pj_inv_mlfn(double arg, double es, const double *en) { double s, t, phi, k = 1./(1.-es); int i; phi = arg; for (i = MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */ s = sin(phi); t = 1. - es * s * s; phi -= t = (pj_mlfn(phi, s, cos(phi), en) - arg) * (t * sqrt(t)) * k; if (geometry::math::abs(t) < EPS) return phi; } throw proj_exception(-17); return phi; }
static XY loc_for(LP lp, PJ *P, double *yc) { XY xy; if (! lp.phi) { xy.x = lp.lam; xy.y = 0.; } else { double xa, ya, xb, yb, xc, D, B, m, sp, t, R, C; sp = sin(lp.phi); m = pj_mlfn(lp.phi, sp, cos(lp.phi), P->en); xa = P->Pp + P->Qp * m; ya = P->P + P->Q * m; R = 1. / (tan(lp.phi) * sqrt(1. - P->es * sp * sp)); C = sqrt(R * R - xa * xa); if (lp.phi < 0.) C = - C; C += ya - R; if (P->mode < 0) { xb = lp.lam; yb = P->C2; } else { t = lp.lam * P->sphi_2; xb = P->R_2 * sin(t); yb = P->C2 + P->R_2 * (1. - cos(t)); } if (P->mode > 0) { xc = lp.lam; *yc = 0.; } else { t = lp.lam * P->sphi_1; xc = P->R_1 * sin(t); *yc = P->R_1 * (1. - cos(t)); } D = (xb - xc)/(yb - *yc); B = xc + D * (C + R - *yc); xy.x = D * sqrt(R * R * (1 + D * D) - B * B); if (lp.phi > 0) xy.x = - xy.x; xy.x = (B + xy.x) / (1. + D * D); xy.y = sqrt(R * R - xy.x * xy.x); if (lp.phi > 0) xy.y = - xy.y; xy.y += C + R; } return (xy); }
static PJ_XY loc_for(PJ_LP lp, PJ *P, double *yc) { struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque); PJ_XY xy; if (lp.phi == 0.0) { xy.x = lp.lam; xy.y = 0.; } else { double xa, ya, xb, yb, xc, D, B, m, sp, t, R, C; sp = sin(lp.phi); m = pj_mlfn(lp.phi, sp, cos(lp.phi), Q->en); xa = Q->Pp + Q->Qp * m; ya = Q->P + Q->Q * m; R = 1. / (tan(lp.phi) * sqrt(1. - P->es * sp * sp)); C = sqrt(R * R - xa * xa); if (lp.phi < 0.) C = - C; C += ya - R; if (Q->mode == PHI_2_IS_ZERO) { xb = lp.lam; yb = Q->C2; } else { t = lp.lam * Q->sphi_2; xb = Q->R_2 * sin(t); yb = Q->C2 + Q->R_2 * (1. - cos(t)); } if (Q->mode == PHI_1_IS_ZERO) { xc = lp.lam; *yc = 0.; } else { t = lp.lam * Q->sphi_1; xc = Q->R_1 * sin(t); *yc = Q->R_1 * (1. - cos(t)); } D = (xb - xc)/(yb - *yc); B = xc + D * (C + R - *yc); xy.x = D * sqrt(R * R * (1 + D * D) - B * B); if (lp.phi > 0) xy.x = - xy.x; xy.x = (B + xy.x) / (1. + D * D); xy.y = sqrt(R * R - xy.x * xy.x); if (lp.phi > 0) xy.y = - xy.y; xy.y += C + R; } return xy; }
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ XY xy = {0.0,0.0}; struct pj_opaque *Q = P->opaque; double ms, sp, cp; if (fabs(lp.phi) <= TOL) { xy.x = lp.lam; xy.y = -Q->ml0; } else { sp = sin(lp.phi); ms = fabs(cp = cos(lp.phi)) > TOL ? pj_msfn(sp, cp, P->es) / sp : 0.; xy.x = ms * sin(lp.lam *= sp); xy.y = (pj_mlfn(lp.phi, sp, cp, Q->en) - Q->ml0) + ms * (1. - cos(lp.lam)); } return xy; }
inline void setup_aeqd(Params const& params, Parameters& par, par_aeqd<T>& proj_parm, bool is_sphere, bool is_guam) { static const T half_pi = detail::half_pi<T>(); par.phi0 = pj_get_param_r<T, srs::spar::lat_0>(params, "lat_0", srs::dpar::lat_0); if (fabs(fabs(par.phi0) - half_pi) < epsilon10) { proj_parm.mode = par.phi0 < 0. ? s_pole : n_pole; proj_parm.sinph0 = par.phi0 < 0. ? -1. : 1.; proj_parm.cosph0 = 0.; } else if (fabs(par.phi0) < epsilon10) { proj_parm.mode = equit; proj_parm.sinph0 = 0.; proj_parm.cosph0 = 1.; } else { proj_parm.mode = obliq; proj_parm.sinph0 = sin(par.phi0); proj_parm.cosph0 = cos(par.phi0); } if (is_sphere) { /* empty */ } else { proj_parm.en = pj_enfn<T>(par.es); if (is_guam) { proj_parm.M1 = pj_mlfn(par.phi0, proj_parm.sinph0, proj_parm.cosph0, proj_parm.en); } else { switch (proj_parm.mode) { case n_pole: proj_parm.Mp = pj_mlfn<T>(half_pi, 1., 0., proj_parm.en); break; case s_pole: proj_parm.Mp = pj_mlfn<T>(-half_pi, -1., 0., proj_parm.en); break; case equit: case obliq: proj_parm.N1 = 1. / sqrt(1. - par.es * proj_parm.sinph0 * proj_parm.sinph0); proj_parm.G = proj_parm.sinph0 * (proj_parm.He = par.e / sqrt(par.one_es)); proj_parm.He *= proj_parm.cosph0; break; } // Boost.Geometry specific, in proj4 geodesic is initialized at the beginning T const b = math::sqrt(math::sqr(par.a) * (1. - par.es)); proj_parm.spheroid = srs::spheroid<T>(par.a, b); } } }
inline T pj_inv_mlfn(T const& arg, T const& es, detail::en<T> const& en) { static const T EPS = 1e-11; static const int MAX_ITER = 10; T s, t, phi, k = 1./(1.-es); int i; phi = arg; for (i = MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */ s = sin(phi); t = 1. - es * s * s; phi -= t = (pj_mlfn(phi, s, cos(phi), en) - arg) * (t * sqrt(t)) * k; if (geometry::math::abs(t) < EPS) return phi; } BOOST_THROW_EXCEPTION( projection_exception(error_non_conv_inv_meri_dist) ); return phi; }
PJ *PROJECTION(poly) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; if (P->es) { if (!(Q->en = pj_enfn(P->es))) E_ERROR_0; Q->ml0 = pj_mlfn(P->phi0, sin(P->phi0), cos(P->phi0), Q->en); P->inv = e_inverse; P->fwd = e_forward; } else { Q->ml0 = -P->phi0; P->inv = s_inverse; P->fwd = s_forward; } return P; }
void setup_lcca(Parameters& par, par_lcca& proj_parm) { double s2p0, N0, R0, tan0, tan20; pj_enfn(par.es, proj_parm.en); if (!pj_param(par.params, "tlat_0").i) throw proj_exception(50); if (par.phi0 == 0.) throw proj_exception(51); proj_parm.l = sin(par.phi0); proj_parm.M0 = pj_mlfn(par.phi0, proj_parm.l, cos(par.phi0), proj_parm.en); s2p0 = proj_parm.l * proj_parm.l; R0 = 1. / (1. - par.es * s2p0); N0 = sqrt(R0); R0 *= par.one_es * N0; tan0 = tan(par.phi0); tan20 = tan0 * tan0; proj_parm.r0 = N0 / tan0; proj_parm.C = 1. / (6. * R0 * N0); // par.inv = e_inverse; // par.fwd = e_forward; }
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ double n, t, a1, c, a2, tn; XY xy = {0.0, 0.0}; struct pj_opaque *Q = P->opaque; xy.y = pj_mlfn (lp.phi, n = sin (lp.phi), c = cos (lp.phi), Q->en); n = 1./sqrt(1. - P->es * n*n); tn = tan(lp.phi); t = tn * tn; a1 = lp.lam * c; c *= P->es * c / (1 - P->es); a2 = a1 * a1; xy.x = n * a1 * (1. - a2 * t * (C1 - (8. - t + 8. * c) * a2 * C2)); xy.y -= Q->m0 - n * tn * a2 * (.5 + (5. - t + 6. * c) * a2 * C3); return xy; }
long double pj_inv_mlfn(long double arg, long double es, long double *en) { long double s, t, phi, k = 1.-es; int i; phi = arg; for (i = MAX_ITER; i ; --i) { /* rarely goes over 5 iterations */ s = sin(phi); t = 1. - es * s * s; t = (pj_mlfn(phi, s, std::cos(phi), en) - arg) / ( k * t * std::sqrt(t)); phi -= t; if (std::fabs(t) < EPS) break; } /* if (i <= 0) pj_errno = -17; */ return phi; }
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */ LP lp = {0.0,0.0}; struct pj_opaque *Q = P->opaque; xy.y += Q->ml0; if (fabs(xy.y) <= TOL) { lp.lam = xy.x; lp.phi = 0.; } else { double r, c, sp, cp, s2ph, ml, mlb, mlp, dPhi; int i; r = xy.y * xy.y + xy.x * xy.x; for (lp.phi = xy.y, i = I_ITER; i ; --i) { sp = sin(lp.phi); s2ph = sp * ( cp = cos(lp.phi)); if (fabs(cp) < ITOL) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return lp; } c = sp * (mlp = sqrt(1. - P->es * sp * sp)) / cp; ml = pj_mlfn(lp.phi, sp, cp, Q->en); mlb = ml * ml + r; mlp = P->one_es / (mlp * mlp * mlp); lp.phi += ( dPhi = ( ml + ml + c * mlb - 2. * xy.y * (c * ml + 1.) ) / ( P->es * s2ph * (mlb - 2. * xy.y * ml) / c + 2.* (xy.y - ml) * (c * mlp - 1. / s2ph) - mlp - mlp )); if (fabs(dPhi) <= ITOL) break; } if (!i) { proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION); return lp; } c = sin(lp.phi); lp.lam = asin(xy.x * tan(lp.phi) * sqrt(1. - P->es * c * c)) / sin(lp.phi); } return lp; }
void setup_bonne(Parameters& par, par_bonne& proj_parm) { double c; proj_parm.phi1 = pj_param(par.params, "rlat_1").f; if (fabs(proj_parm.phi1) < EPS10) throw proj_exception(-23); if (par.es) { pj_enfn(par.es, proj_parm.en); proj_parm.m1 = pj_mlfn(proj_parm.phi1, proj_parm.am1 = sin(proj_parm.phi1), c = cos(proj_parm.phi1), proj_parm.en); proj_parm.am1 = c / (sqrt(1. - par.es * proj_parm.am1 * proj_parm.am1) * proj_parm.am1); // par.inv = e_inverse; // par.fwd = e_forward; } else { if (fabs(proj_parm.phi1) + EPS10 >= HALFPI) proj_parm.cphi1 = 0.; else proj_parm.cphi1 = 1. / tan(proj_parm.phi1); // par.inv = s_inverse; // par.fwd = s_forward; } }
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */ XY xy = {0.0, 0.0}; struct pj_opaque *Q = P->opaque; double al, als, n, cosphi, sinphi, t; /* * Fail if our longitude is more than 90 degrees from the * central meridian since the results are essentially garbage. * Is error -20 really an appropriate return value? * * http://trac.osgeo.org/proj/ticket/5 */ if( lp.lam < -HALFPI || lp.lam > HALFPI ) { xy.x = HUGE_VAL; xy.y = HUGE_VAL; pj_ctx_set_errno( P->ctx, -14 ); return xy; } sinphi = sin (lp.phi); cosphi = cos (lp.phi); t = fabs (cosphi) > 1e-10 ? sinphi/cosphi : 0.; t *= t; al = cosphi * lp.lam; als = al * al; al /= sqrt (1. - P->es * sinphi * sinphi); n = Q->esp * cosphi * cosphi; xy.x = P->k0 * al * (FC1 + FC3 * als * (1. - t + n + FC5 * als * (5. + t * (t - 18.) + n * (14. - 58. * t) + FC7 * als * (61. + t * ( t * (179. - t) - 479. ) ) ))); xy.y = P->k0 * (pj_mlfn(lp.phi, sinphi, cosphi, Q->en) - Q->ml0 + sinphi * al * lp.lam * FC2 * ( 1. + FC4 * als * (5. - t + n * (9. + 4. * n) + FC6 * als * (61. + t * (t - 58.) + n * (270. - 330 * t) + FC8 * als * (1385. + t * ( t * (543. - t) - 3111.) ) )))); return (xy); }
PJ *PROJECTION(poly) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return pj_default_destructor (P, ENOMEM); P->opaque = Q; P->destructor = destructor; if (P->es != 0.0) { if (!(Q->en = pj_enfn(P->es))) return pj_default_destructor (P, ENOMEM); Q->ml0 = pj_mlfn(P->phi0, sin(P->phi0), cos(P->phi0), Q->en); P->inv = e_inverse; P->fwd = e_forward; } else { Q->ml0 = -P->phi0; P->inv = s_inverse; P->fwd = s_forward; } return P; }
inline void setup_lcca(Parameters& par, par_lcca<T>& proj_parm) { T s2p0, N0, R0, tan0, tan20; if (!pj_enfn(par.es, proj_parm.en)) BOOST_THROW_EXCEPTION( projection_exception(0) ); if (!pj_param(par.params, "tlat_0").i) BOOST_THROW_EXCEPTION( projection_exception(50) ); if (par.phi0 == 0.) BOOST_THROW_EXCEPTION( projection_exception(51) ); proj_parm.l = sin(par.phi0); proj_parm.M0 = pj_mlfn(par.phi0, proj_parm.l, cos(par.phi0), proj_parm.en); s2p0 = proj_parm.l * proj_parm.l; R0 = 1. / (1. - par.es * s2p0); N0 = sqrt(R0); R0 *= par.one_es * N0; tan0 = tan(par.phi0); tan20 = tan0 * tan0; proj_parm.r0 = N0 / tan0; proj_parm.C = 1. / (6. * R0 * N0); boost::ignore_unused(tan20); }