PJ *PROJECTION(labrd) { double Az, sinp, R, N, t; struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->rot = pj_param(P->ctx, P->params, "bno_rot").i == 0; Az = pj_param(P->ctx, P->params, "razi").f; sinp = sin(P->phi0); t = 1. - P->es * sinp * sinp; N = 1. / sqrt(t); R = P->one_es * N / t; Q->kRg = P->k0 * sqrt( N * R ); Q->p0s = atan( sqrt(R / N) * tan(P->phi0) ); Q->A = sinp / sin(Q->p0s); t = P->e * sinp; Q->C = .5 * P->e * Q->A * log((1. + t)/(1. - t)) + - Q->A * log( tan(M_FORTPI + .5 * P->phi0)) + log( tan(M_FORTPI + .5 * Q->p0s)); t = Az + Az; Q->Ca = (1. - cos(t)) * ( Q->Cb = 1. / (12. * Q->kRg * Q->kRg) ); Q->Cb *= sin(t); Q->Cc = 3. * (Q->Ca * Q->Ca - Q->Cb * Q->Cb); Q->Cd = 6. * Q->Ca * Q->Cb; P->inv = e_inverse; P->fwd = e_forward; return P; }
PJ *PROJECTION(qsc) { 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->inv = qsc_e_inverse; P->fwd = qsc_e_forward; /* Determine the cube face from the center of projection. */ if (P->phi0 >= M_HALFPI - M_FORTPI / 2.0) { Q->face = FACE_TOP; } else if (P->phi0 <= -(M_HALFPI - M_FORTPI / 2.0)) { Q->face = FACE_BOTTOM; } else if (fabs(P->lam0) <= M_FORTPI) { Q->face = FACE_FRONT; } else if (fabs(P->lam0) <= M_HALFPI + M_FORTPI) { Q->face = (P->lam0 > 0.0 ? FACE_RIGHT : FACE_LEFT); } else { Q->face = FACE_BACK; } /* Fill in useful values for the ellipsoid <-> sphere shift * described in [LK12]. */ if (P->es != 0.0) { Q->a_squared = P->a * P->a; Q->b = P->a * sqrt(1.0 - P->es); Q->one_minus_f = 1.0 - (P->a - Q->b) / P->a; Q->one_minus_f_squared = Q->one_minus_f * Q->one_minus_f; } return P; }
PJ *PROJECTION(rhealpix) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->north_square = pj_param(P->ctx, P->params,"inorth_square").i; Q->south_square = pj_param(P->ctx, P->params,"isouth_square").i; /* Check for valid north_square and south_square inputs. */ if (Q->north_square < 0 || Q->north_square > 3) { E_ERROR(-47); } if (Q->south_square < 0 || Q->south_square > 3) { E_ERROR(-47); } if (P->es) { Q->apa = pj_authset(P->es); /* For auth_lat(). */ Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */ P->a = P->a*sqrt(0.5*Q->qp); /* Set P->a to authalic radius. */ P->ra = 1.0/P->a; P->fwd = e_rhealpix_forward; P->inv = e_rhealpix_inverse; } else { P->fwd = s_rhealpix_forward; P->inv = s_rhealpix_inverse; } return P; }
PJ *PROJECTION(utm) { int zone; struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; if (!P->es) E_ERROR(-34); P->y0 = pj_param (P->ctx, P->params, "bsouth").i ? 10000000. : 0.; P->x0 = 500000.; if (pj_param (P->ctx, P->params, "tzone").i) /* zone input ? */ if ((zone = pj_param(P->ctx, P->params, "izone").i) > 0 && zone <= 60) --zone; else E_ERROR(-35) else /* nearest central meridian input */ if ((zone = (int)(floor ((adjlon (P->lam0) + M_PI) * 30. / M_PI))) < 0) zone = 0; else if (zone >= 60) zone = 59; P->lam0 = (zone + .5) * M_PI / 30. - M_PI; P->k0 = 0.9996; P->phi0 = 0.; return setup (P); }
PJ *PROJECTION(labrd) { double Az, sinp, R, N, t; 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 (P->phi0 == 0.) { return pj_default_destructor(P, PJD_ERR_LAT_0_IS_ZERO); } Az = pj_param(P->ctx, P->params, "razi").f; sinp = sin(P->phi0); t = 1. - P->es * sinp * sinp; N = 1. / sqrt(t); R = P->one_es * N / t; Q->kRg = P->k0 * sqrt( N * R ); Q->p0s = atan( sqrt(R / N) * tan(P->phi0) ); Q->A = sinp / sin(Q->p0s); t = P->e * sinp; Q->C = .5 * P->e * Q->A * log((1. + t)/(1. - t)) + - Q->A * log( tan(M_FORTPI + .5 * P->phi0)) + log( tan(M_FORTPI + .5 * Q->p0s)); t = Az + Az; Q->Ca = (1. - cos(t)) * ( Q->Cb = 1. / (12. * Q->kRg * Q->kRg) ); Q->Cb *= sin(t); Q->Cc = 3. * (Q->Ca * Q->Ca - Q->Cb * Q->Cb); Q->Cd = 6. * Q->Ca * Q->Cb; 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; }
PJ *PROJECTION(qsc) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; P->inv = e_inverse; P->fwd = e_forward; /* Determine the cube face from the center of projection. */ if (P->phi0 >= HALFPI - FORTPI / 2.0) { Q->face = FACE_TOP; } else if (P->phi0 <= -(HALFPI - FORTPI / 2.0)) { Q->face = FACE_BOTTOM; } else if (fabs(P->lam0) <= FORTPI) { Q->face = FACE_FRONT; } else if (fabs(P->lam0) <= HALFPI + FORTPI) { Q->face = (P->lam0 > 0.0 ? FACE_RIGHT : FACE_LEFT); } else { Q->face = FACE_BACK; } /* Fill in useful values for the ellipsoid <-> sphere shift * described in [LK12]. */ if (P->es) { Q->a_squared = P->a * P->a; Q->b = P->a * sqrt(1.0 - P->es); Q->one_minus_f = 1.0 - (P->a - Q->b) / P->a; Q->one_minus_f_squared = Q->one_minus_f * Q->one_minus_f; } 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; }
PJ *PROJECTION(etmerc) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; return setup (P); }
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; }
/* turn paralist into argc/argv style argument list */ static ARGS ob_tran_target_params (paralist *params) { int i = 0; ARGS args = {0, nullptr}; size_t argc = paralist_params_argc (params); if (argc < 2) return args; /* all args except the proj_ob_tran */ args.argv = static_cast<char**>(pj_calloc (argc - 1, sizeof (char *))); if (nullptr==args.argv) return args; /* Copy all args *except* the proj=ob_tran arg to the argv array */ for (i = 0; params != nullptr; params = params->next) { if (0==strcmp (params->param, "proj=ob_tran")) continue; args.argv[i++] = params->param; } args.argc = i; /* Then convert the o_proj=xxx element to proj=xxx */ for (i = 0; i < args.argc; i++) { if (0!=strncmp (args.argv[i], "o_proj=", 7)) continue; args.argv[i] += 2; break; } return args; }
PJ *PROJECTION(mbt_s) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; return setup(P, 1.48875, 1.36509, 0); }
PJ *PROJECTION(qua_aut) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; return setup(P, 2., 2., 0); }
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(wag4) { 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; return setup(P, M_PI/3.); }
PJ *PROJECTION(kav5) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; return setup(P, 1.50488, 1.35439, 0); }
PJ *PROJECTION(laea) { double t; 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; t = fabs(P->phi0); if (fabs(t - M_HALFPI) < EPS10) Q->mode = P->phi0 < 0. ? S_POLE : N_POLE; else if (fabs(t) < EPS10) Q->mode = EQUIT; else Q->mode = OBLIQ; if (P->es != 0.0) { double sinphi; P->e = sqrt(P->es); Q->qp = pj_qsfn(1., P->e, P->one_es); Q->mmf = .5 / (1. - P->es); Q->apa = pj_authset(P->es); if (0==Q->apa) return destructor(P, ENOMEM); switch (Q->mode) { case N_POLE: case S_POLE: Q->dd = 1.; break; case EQUIT: Q->dd = 1. / (Q->rq = sqrt(.5 * Q->qp)); Q->xmf = 1.; Q->ymf = .5 * Q->qp; break; case OBLIQ: Q->rq = sqrt(.5 * Q->qp); sinphi = sin(P->phi0); Q->sinb1 = pj_qsfn(sinphi, P->e, P->one_es) / Q->qp; Q->cosb1 = sqrt(1. - Q->sinb1 * Q->sinb1); Q->dd = cos(P->phi0) / (sqrt(1. - P->es * sinphi * sinphi) * Q->rq * Q->cosb1); Q->ymf = (Q->xmf = Q->rq) / Q->dd; Q->xmf *= Q->dd; break; } P->inv = e_inverse; P->fwd = e_forward; } else { if (Q->mode == OBLIQ) { Q->sinb1 = sin(P->phi0); Q->cosb1 = cos(P->phi0); } P->inv = s_inverse; P->fwd = s_forward; } return P; }
PJ *PROJECTION(aitoff) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return pj_default_destructor(P, ENOMEM); P->opaque = Q; Q->mode = AITOFF; return setup(P); }
PJ *PROJECTION(wag1) { 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; static_cast<struct pj_opaque*>(P->opaque)->n = 0.8660254037844386467637231707; return setup(P); }
PJ *PROJECTION(nsper) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->tilt = 0; return setup(P); }
PJ *PROJECTION(stere) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->phits = pj_param (P->ctx, P->params, "tlat_ts").i ? pj_param (P->ctx, P->params, "rlat_ts").f : HALFPI; return setup(P); }
PJ *PROJECTION(apian) { 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->bacn = Q->ortl = 0; P->es = 0.; P->fwd = s_forward; return P; }
static PJ *pj_create_pipeline (PJ *P, size_t steps) { /* Room for the pipeline: An array of PJ * with room for sentinels at both ends */ static_cast<struct pj_opaque*>(P->opaque)->pipeline = static_cast<PJ**>(pj_calloc (steps + 2, sizeof(PJ *))); if (nullptr==static_cast<struct pj_opaque*>(P->opaque)->pipeline) return nullptr; static_cast<struct pj_opaque*>(P->opaque)->steps = (int)steps; return P; }
PJ *PROJECTION(vandg2) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->vdg3 = 0; P->fwd = s_forward; return P; }
PJ *PROJECTION(wag6) { 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->C_x = Q->C_y = 0.94745; Q->A = 0.0; Q->B = 0.30396355092701331433; return setup(P); }
PJ *PROJECTION(lcc) { 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; Q->phi1 = pj_param(P->ctx, P->params, "rlat_1").f; if (pj_param(P->ctx, P->params, "tlat_2").i) Q->phi2 = pj_param(P->ctx, P->params, "rlat_2").f; else { Q->phi2 = Q->phi1; if (!pj_param(P->ctx, P->params, "tlat_0").i) P->phi0 = Q->phi1; } if (fabs(Q->phi1 + Q->phi2) < EPS10) return pj_default_destructor(P, PJD_ERR_CONIC_LAT_EQUAL); 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; P->e = sqrt(P->es); m1 = pj_msfn(sinphi, cosphi, P->es); ml1 = pj_tsfn(Q->phi1, sinphi, P->e); if (secant) { /* secant cone */ sinphi = sin(Q->phi2); Q->n = log(m1 / pj_msfn(sinphi, cos(Q->phi2), P->es)); Q->n /= log(ml1 / pj_tsfn(Q->phi2, sinphi, P->e)); } Q->c = (Q->rho0 = m1 * pow(ml1, -Q->n) / Q->n); Q->rho0 *= (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) ? 0. : pow(pj_tsfn(P->phi0, sin(P->phi0), P->e), Q->n); } else { if (secant) Q->n = log(cosphi / cos(Q->phi2)) / log(tan(M_FORTPI + .5 * Q->phi2) / tan(M_FORTPI + .5 * Q->phi1)); Q->c = cosphi * pow(tan(M_FORTPI + .5 * Q->phi1), Q->n) / Q->n; Q->rho0 = (fabs(fabs(P->phi0) - M_HALFPI) < EPS10) ? 0. : Q->c * pow(tan(M_FORTPI + .5 * P->phi0), -Q->n); } P->inv = e_inverse; P->fwd = e_forward; return P; }
PJ *PROJECTION(eck3) { 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->C_x = 0.42223820031577120149; Q->C_y = 0.84447640063154240298; Q->A = 1.0; Q->B = 0.4052847345693510857755; return setup(P); }
PJ *PROJECTION(wink1) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; P->opaque->cosphi1 = cos (pj_param(P->ctx, P->params, "rlat_ts").f); P->es = 0.; P->inv = s_inverse; P->fwd = s_forward; return P; }
PJ *PROJECTION(putp3p) { 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->A = 2. * RPISQ; P->es = 0.; P->inv = s_inverse; P->fwd = s_forward; return P; }
PJ *PROJECTION(putp3p) { struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); if (0==Q) return freeup_new (P); P->opaque = Q; Q->A = 2. * RPISQ; P->es = 0.; P->inv = s_inverse; P->fwd = s_forward; return P; }