static PROJ_XY
loc_for(PROJ_LP lp, PROJ *P, double *yc) {
  PROJ_XY xy;
  double xa, ya, xb, yb, xc, D, B, m, sp, t, R=0., C;

  sp = sin(lp.phi);
  m = proj_mdist(lp.phi, sp, cos(lp.phi), P->en);
  xa = P->Pp + P->Qp * m;
  ya = P->P + P->Q * m;
  if (lp.phi) {
    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;
  } else
    C = 0.;
  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));
  }
  if (lp.phi) {
    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;
  } else {
    xy.x = lp.lam;
    xy.y = C;
  }
  return (xy);
}
 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
 {
     double s, al, cp, sp, al2, s2;
     
     cp = cos(lp_lat);
     sp = sin(lp_lat);
     s = proj_mdist(lp_lat, sp, cp,  this->m_proj_parm.en) - this->m_proj_parm.s0;
     s2 = s * s;
     al = lp_lon * cp / sqrt(1. - this->m_par.es * sp * sp);
     al2 = al * al;
     xy_x = this->m_par.k0 * al*(1.+s2*(this->m_proj_parm.A1+s2*this->m_proj_parm.A4)-al2*(this->m_proj_parm.A2+s*this->m_proj_parm.A3+s2*this->m_proj_parm.A5
                 +al2*this->m_proj_parm.A6));
     xy_y = this->m_par.k0 * (al2*(this->m_proj_parm.B1+al2*this->m_proj_parm.B4)+
         s*(1.+al2*(this->m_proj_parm.B3-al2*this->m_proj_parm.B6)+s2*(this->m_proj_parm.B2+s2*this->m_proj_parm.B8)+
         s*al2*(this->m_proj_parm.B5+s*this->m_proj_parm.B7)));
 }
 void setup_rouss(Parameters& par, par_rouss& proj_parm)
 {
     double N0, es2, t, t2, R_R0_2, R_R0_4;
     proj_mdist_ini(par.es, proj_parm.en);
 
     es2 = sin(par.phi0);
     proj_parm.s0 = proj_mdist(par.phi0, es2, cos(par.phi0), proj_parm.en);
     t = 1. - (es2 = par.es * es2 * es2);
     N0 = 1./sqrt(t);
     R_R0_2 = t * t / par.one_es;
     R_R0_4 = R_R0_2 * R_R0_2;
     t = tan(par.phi0);
     t2 = t * t;
     proj_parm.C1 = proj_parm.A1 = R_R0_2 / 4.;
     proj_parm.C2 = proj_parm.A2 = R_R0_2 * (2 * t2 - 1. - 2. * es2) / 12.;
     proj_parm.A3 = R_R0_2 * t * (1. + 4. * t2)/ ( 12. * N0);
     proj_parm.A4 = R_R0_4 / 24.;
     proj_parm.A5 = R_R0_4 * ( -1. + t2 * (11. + 12. * t2))/24.;
     proj_parm.A6 = R_R0_4 * ( -2. + t2 * (11. - 2. * t2))/240.;
     proj_parm.B1 = t / (2. * N0);
     proj_parm.B2 = R_R0_2 / 12.;
     proj_parm.B3 = R_R0_2 * (1. + 2. * t2 - 2. * es2)/4.;
     proj_parm.B4 = R_R0_2 * t * (2. - t2)/(24. * N0);
     proj_parm.B5 = R_R0_2 * t * (5. + 4.* t2)/(8. * N0);
     proj_parm.B6 = R_R0_4 * (-2. + t2 * (-5. + 6. * t2))/48.;
     proj_parm.B7 = R_R0_4 * (5. + t2 * (19. + 12. * t2))/24.;
     proj_parm.B8 = R_R0_4 / 120.;
     proj_parm.C3 = R_R0_2 * t * (1. + t2)/(3. * N0);
     proj_parm.C4 = R_R0_4 * (-3. + t2 * (34. + 22. * t2))/240.;
     proj_parm.C5 = R_R0_4 * (4. + t2 * (13. + 12. * t2))/24.;
     proj_parm.C6 = R_R0_4 / 16.;
     proj_parm.C7 = R_R0_4 * t * (11. + t2 * (33. + t2 * 16.))/(48. * N0);
     proj_parm.C8 = R_R0_4 * t * (1. + t2 * 4.)/(36. * N0);
     proj_parm.D1 = t / (2. * N0);
     proj_parm.D2 = R_R0_2 / 12.;
     proj_parm.D3 = R_R0_2 * (2 * t2 + 1. - 2. * es2) / 4.;
     proj_parm.D4 = R_R0_2 * t * (1. + t2)/(8. * N0);
     proj_parm.D5 = R_R0_2 * t * (1. + t2 * 2.)/(4. * N0);
     proj_parm.D6 = R_R0_4 * (1. + t2 * (6. + t2 * 6.))/16.;
     proj_parm.D7 = R_R0_4 * t2 * (3. + t2 * 4.)/8.;
     proj_parm.D8 = R_R0_4 / 80.;
     proj_parm.D9 = R_R0_4 * t * (-21. + t2 * (178. - t2 * 26.))/720.;
     proj_parm.D10 = R_R0_4 * t * (29. + t2 * (86. + t2 * 48.))/(96. * N0);
     proj_parm.D11 = R_R0_4 * t * (37. + t2 * 44.)/(96. * N0);
     // par.fwd = e_forward;
     // par.inv = e_inverse;
 }
Example #4
0
double proj_inv_mdist(projCtx ctx, double dist, const void *b) {
	double s, t, phi, k;
	int i;

	k = 1. / (1. - B->es);
	i = MAX_ITER;
	phi = dist;
	while (i--) {
		s = sin(phi);
		t = 1. - B->es * s * s;
		phi -= t = (proj_mdist(phi, s, cos(phi), b) - dist) * (t * sqrt(t)) * k;
		if (fabs(t) < TOL) /* that is no change */
			return phi;
	}
	/* convergence failed */
	pj_ctx_set_errno(ctx, -17);
	return phi;
}
Example #5
0
    inline double proj_inv_mdist(double dist, const MDIST& b)
    {
        static const double TOL = 1e-14;
        double s, t, phi, k;
        int i;

        k = 1./(1.- b.es);
        i = MDIST_MAX_ITER;
        phi = dist;
        while ( i-- ) {
            s = sin(phi);
            t = 1. - b.es * s * s;
            phi -= t = (proj_mdist(phi, s, cos(phi), b) - dist) *
                (t * sqrt(t)) * k;
            if (geometry::math::abs(t) < TOL) /* that is no change */
                return phi;
        }
            /* convergence failed */
        throw proj_exception(-17);
    }
Example #6
0
  void  *en; \
  double  m, n, C_x, C_y;
#define PROJ_LIB__
#include  <lib_proj.h>
PROJ_HEAD(gn_sinu, "General Sinusoidal Series") "\n\tPCyl, Sph.\n\tm= n=";
PROJ_HEAD(sinu, "Sinusoidal (Sanson-Flamsteed)") "\n\tPCyl, Sph&Ell";
PROJ_HEAD(eck6, "Eckert VI") "\n\tPCyl, Sph.";
PROJ_HEAD(mbtfps, "McBryde-Thomas Flat-Polar Sinusoidal") "\n\tPCyl, Sph.";
#define EPS10  1e-10
#define MAX_ITER 8
#define LOOP_TOL 1e-7
/* Ellipsoidal Sinusoidal only */
FORWARD(e_forward); /* ellipsoid */
  double s, c;

  xy.y = proj_mdist(lp.phi, s = sin(lp.phi), c = cos(lp.phi), P->en);
  xy.x = lp.lam * proj_msfn(s, c, P->es);
  return (xy);
}
INVERSE(e_inverse); /* ellipsoid */
  double s;

  if ((s = fabs(lp.phi = proj_inv_mdist(xy.y, P->en))) < HALFPI)
    lp.lam = xy.x / proj_msfn(sin(lp.phi), cos(lp.phi), P->es);
  else if ((s - EPS10) < HALFPI)
    lp.lam = 0.;
  else I_ERROR;
  return (lp);
}
/* General spherical sinusoidals */
FORWARD(s_forward); /* sphere */
Example #7
0
#define PROJ_PARMS__ \
  double s0; \
  double A1, A2, A3, A4, A5, A6; \
  double B1, B2, B3, B4, B5, B6, B7, B8; \
  double C1, C2, C3, C4, C5, C6, C7, C8; \
  double D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11; \
  void *en;
#define PROJ_LIB__
# include  <lib_proj.h>
PROJ_HEAD(rouss, "Roussilhe Stereographic") "\n\tAzi., Ellps.";
FORWARD(e_forward); /* ellipsoid */
  double s, al, cp, sp, al2, s2;
  
  cp = cos(lp.phi);
  sp = sin(lp.phi);
  s = proj_mdist(lp.phi, sp, cp,  P->en) - P->s0;
  s2 = s * s;
  al = lp.lam * cp / sqrt(1. - P->es * sp * sp);
  al2 = al * al;
  xy.x = P->k0 * al*(1.+s2*(P->A1+s2*P->A4)-al2*(P->A2+s*P->A3+s2*P->A5
        +al2*P->A6));
  xy.y = P->k0 * (al2*(P->B1+al2*P->B4)+
    s*(1.+al2*(P->B3-al2*P->B6)+s2*(P->B2+s2*P->B8)+
    s*al2*(P->B5+s*P->B7)));
  return (xy);
}
INVERSE(e_inverse); /* ellipsoid */
  double s, al, x = xy.x / P->k0, y = xy.y / P->k0, x2, y2;;

  x2 = x * x;
  y2 = y * y;
Example #8
0
  double al, als, n, cosphi, sinphi, t;

  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 = P->esp * cosphi * cosphi;
  xy.x = P->k0 * al * (FC1 +
    FC3 * als * (1. - t + n +
    FC5 * als * (5. + t * (t - 18.) + n * (14. - 58. * t +
     n * (13. - 64. * t + n * (4. - 24 * t)))
    + FC7 * als * (61. + t * ( t * (179. - t) - 479. ) )
    )));
  xy.y = P->k0 * (proj_mdist(lp.phi, sinphi, cosphi, P->en) - P->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 +
     n * (445. - 680. * t + n * (324. - 600. * t + n * (88. - 192. * t))))
    + FC8 * als * (1385. + t * ( t * (543. - t) - 3111.) )
    ))));
  return (xy);
}
FORWARD(s_forward); /* sphere */
  double b, cosphi;

  b = (cosphi = cos(lp.phi)) * sin(lp.lam);
  if (fabs(fabs(b) - 1.) <= EPS10) F_ERROR;
  xy.x = aks5 * log((1. + b) / (1. - b));
  if ((b = fabs( xy.y = cosphi * cos(lp.lam) / sqrt(1. - b * b) )) >= 1.) {
Example #9
0
#define PROJ_PARMS__ \
	double phi1; \
	double phi2; \
	double n; \
	double rho; \
	double rho0; \
	double c; \
	void *en; \
	int		ellips;
#define PROJ_LIB__
#include	<lib_proj.h>
PROJ_HEAD(eqdc, "Equidistant Conic")
	"\n\tConic, Sph&Ell\n\tlat_1= lat_2=";
# define EPS10	1.e-10
FORWARD(e_forward); /* sphere & ellipsoid */
	P->rho = P->c - (P->ellips ? proj_mdist(lp.phi, sin(lp.phi),
		cos(lp.phi), P->en) : lp.phi);
	xy.x = P->rho * sin( lp.lam *= P->n );
	xy.y = P->rho0 - P->rho * cos(lp.lam);
	return (xy);
}
INVERSE(e_inverse); /* sphere & ellipsoid */
	if ((P->rho = hypot(xy.x, xy.y = P->rho0 - xy.y))) {
		if (P->n < 0.) {
			P->rho = -P->rho;
			xy.x = -xy.x;
			xy.y = -xy.y;
		}
		lp.phi = P->c - P->rho;
		if (P->ellips)
			lp.phi = proj_inv_mdist(lp.phi, P->en);
		lp.lam = atan2(xy.x, xy.y) / P->n;
Example #10
0
*/
#define PROJ_PARMS__ \
	double phi1; \
	double cphi1; \
	double am1; \
	double m1; \
	void *en;
#define PROJ_LIB__
#include	<lib_proj.h>
PROJ_HEAD(bonne, "Bonne (Werner lat_1=90)")
	"\n\tConic Sph&Ell\n\tlat_1=";
#define EPS10	1e-10
FORWARD(e_forward); /* ellipsoid */
	double rh, E, c;

	rh = P->am1 + P->m1 - proj_mdist(lp.phi, E = sin(lp.phi), c = cos(lp.phi), P->en);
	E = c * lp.lam / (rh * sqrt(1. - P->es * E * E));
	xy.x = rh * sin(E);
	xy.y = P->am1 - rh * cos(E);
	return (xy);
}
FORWARD(s_forward); /* spheroid */
	double E, rh;

	rh = P->cphi1 + P->phi1 - lp.phi;
	if (fabs(rh) > EPS10) {
		xy.x = rh * sin(E = lp.lam * cos(lp.phi) / rh);
		xy.y = P->cphi1 - rh * cos(E);
	} else
		xy.x = xy.y = 0.;
	return (xy);