示例#1
0
int G_begin_geodesic_equation(double lon1, double lat1, double lon2,
			      double lat2)
{
    double sin21, tan1, tan2;

    adjust_lon(&lon1);
    adjust_lon(&lon2);
    adjust_lat(&lat1);
    adjust_lat(&lat2);
    if (lon1 > lon2) {
	double temp;
	temp = lon1; lon1 = lon2; lon2 = temp;
	temp = lat1; lat1 = lat2; lat2 = temp;
    }
    if (lon1 == lon2) {
	st->A = st->B = 0.0;
	return 0;
    }
    lon1 = Radians(lon1);
    lon2 = Radians(lon2);
    lat1 = Radians(lat1);
    lat2 = Radians(lat2);

    sin21 = sin(lon2 - lon1);
    tan1 = tan(lat1);
    tan2 = tan(lat2);

    st->A = (tan2 * cos(lon1) - tan1 * cos(lon2)) / sin21;
    st->B = (tan2 * sin(lon1) - tan1 * sin(lon2)) / sin21;

    return 1;
}
示例#2
0
int G_begin_geodesic_equation(double lon1, double lat1, double lon2,
			      double lat2)
{
    double sin21, tan1, tan2;

    adjust_lon(&lon1);
    adjust_lon(&lon2);
    adjust_lat(&lat1);
    adjust_lat(&lat2);
    if (lon1 > lon2) {
	register double temp;

	SWAP(lon1, lon2);
	SWAP(lat1, lat2);
    }
    if (lon1 == lon2) {
	A = B = 0.0;
	return 0;
    }
    lon1 = Radians(lon1);
    lon2 = Radians(lon2);
    lat1 = Radians(lat1);
    lat2 = Radians(lat2);

    sin21 = sin(lon2 - lon1);
    tan1 = tan(lat1);
    tan2 = tan(lat2);

    A = (tan2 * cos(lon1) - tan1 * cos(lon2)) / sin21;
    B = (tan2 * sin(lon1) - tan1 * sin(lon2)) / sin21;

    return 1;
}
示例#3
0
/* Sinusoidal inverse equations--mapping x,y to lat,long 
  -----------------------------------------------------*/
int sininv(
double x,		/* (I) X projection coordinate */
double y,		/* (I) Y projection coordinate */
double *lon,		/* (O) Longitude */
double *lat)		/* (O) Latitude */
{
  double temp;		/* Re-used temporary variable */
  double mu, ml;
  double sin_phi, cos_phi;
/* Inverse equations
  -----------------*/
  x -= false_easting;
  y -= false_northing;
  
  if (ind != 0) /* Spherical */
    {
      *lat = y / R;
      if (fabs(*lat) > HALF_PI) 
	{
	  p_error("Input data error","sinusoidal-inverse");
	  return(164);
	}
      temp = fabs(*lat) - HALF_PI;
      if (fabs(temp) > EPSLN)
	{
	  temp = lon_center + x / (R * cos(*lat));
	  *lon = adjust_lon(temp);
	}
      else *lon = lon_center;
      return(OK);
    }
  else /* Ellipsoidal */
    {
      ml = y;
      mu = ml / (r_major * imu);
      *lat = mu + 
	(e2 * sin(2.0 * mu)) + 
	(e3 * sin(4.0 * mu)) + 
	(e4 * sin(6.0 * mu)) + 
	(e5 * sin(8.0 * mu));

      if (fabs(*lat) > HALF_PI) 
	{
	  p_error("Input data error","sinusoidal-inverse");
	  return(164);
	}
      temp = fabs(*lat) - HALF_PI;
      if (fabs(temp) > EPSLN)
	{
	  sin_phi = sin(*lat);
	  cos_phi = cos(*lat);
	  temp = lon_center + 
	    x * sqrt(1.0 - es * SQUARE(sin_phi)) / (r_major * cos_phi);
	  *lon = adjust_lon(temp);
	}
     else *lon = lon_center;
     return(OK);
   }
}
/* Azimuthal inverse equations--mapping x,y to lat/long
  ---------------------------------------------------*/
long aziminv
(
    double x,			/* (O) X projection coordinate 	*/
    double y,			/* (O) Y projection coordinate 	*/
    double *lon,			/* (I) Longitude 		*/
    double *lat			/* (I) Latitude 		*/
)
{
double rh;		/* height above ellipsoid			*/
double z;		/* angle					*/
double sinz,cosz;	/* sin of z and cos of z			*/
double con;

/* Inverse equations
  -----------------*/
x -= false_easting;
y -= false_northing;
rh = sqrt(x * x + y * y);
if (rh > (2.0 * HALF_PI * r_major))
   {
   GCTP_PRINT_ERROR("Input data error");
   return(125);
   }
z = rh / r_major;
sincos(z,&sinz,&cosz);
*lon = lon_center;
if (fabs(rh) <= EPSLN)
   {
   *lat = lat_origin;
   return(OK);
   }
*lat = asinz(cosz * sin_p12 + (y * sinz * cos_p12) / rh);
con = fabs(lat_origin) - HALF_PI;
if (fabs(con) <= EPSLN)
   {
   if (lat_origin >= 0.0)
      {
      *lon = adjust_lon(lon_center + atan2(x , -y));
      return(OK);
      }
   else
      {
      *lon = adjust_lon(lon_center - atan2(-x , y));
      return(OK);
      }
   }
con = cosz - sin_p12 * sin(*lat);
if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN))
   return(OK);
*lon = adjust_lon(lon_center + atan2((x * sinz * cos_p12), (con * rh)));

return(OK);
} 
示例#5
0
/* Polar Stereographic inverse equations--mapping x,y to lat/long
  --------------------------------------------------------------*/
long psinv
(
    double x,			/* (O) X projection coordinate 	*/
    double y,			/* (O) Y projection coordinate 	*/
    double *lon,			/* (I) Longitude 		*/
    double *lat			/* (I) Latitude 		*/
)

{
double rh;			/* height above ellipsiod	*/
double ts;			/* small value t		*/
double temp;			/* temporary variable		*/
long   flag;			/* error flag			*/

flag = 0;
x = (x - false_easting) * fac;
y = (y - false_northing) *fac;
rh = sqrt(x * x + y * y);
if (ind != 0)
  ts = rh * tcs/(r_major * mcs);
else
  ts = rh * e4 / (r_major * 2.0);
*lat = fac * phi2z(e,ts,&flag);
if (flag != 0)
   return(flag);
if (rh == 0)
   *lon = fac * center_lon;
else
   {
   temp = atan2(x, -y);
   *lon = adjust_lon(fac *temp + center_lon);
   }

return(GCTP_OK);
}
示例#6
0
/* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
  -----------------------------------------------------------------------*/
long lamazfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)
{
double delta_lon;	/* Delta longitude (Given longitude - center 	*/
double sin_delta_lon;	/* Sine of the delta longitude 			*/
double cos_delta_lon;	/* Cosine of the delta longitude 		*/
double sin_lat;		/* Sine of the given latitude 			*/
double cos_lat;		/* Cosine of the given latitude 		*/
double g;		/* temporary varialbe				*/
double ksp;		/* heigth above elipsiod			*/
char mess[60];

/* Forward equations
  -----------------*/
delta_lon = adjust_lon(lon - lon_center);
gctp_sincos(lat, &sin_lat, &cos_lat);
gctp_sincos(delta_lon, &sin_delta_lon, &cos_delta_lon);
g = sin_lat_o * sin_lat + cos_lat_o * cos_lat * cos_delta_lon;
if (g == -1.0) 
   {
   sprintf(mess, "Point projects to a circle of radius = %f\n", 2.0 * R);
   p_error(mess, "lamaz-forward");
   return(113);
   }
ksp = R * sqrt(2.0 / (1.0 + g));
*x = ksp * cos_lat * sin_delta_lon + false_easting;
*y = ksp * (cos_lat_o * sin_lat - sin_lat_o * cos_lat * cos_delta_lon) + 
	false_northing;
return(GCTP_OK);
}
/* Mollweide inverse equations--mapping x,y to lat,long 
  ----------------------------------------------------*/
long molwinv
(
    double x,		/* (I) X projection coordinate */
    double y,		/* (I) Y projection coordinate */
    double *lon,		/* (O) Longitude */
    double *lat		/* (O) Latitude */
)
{
double theta;
double arg;

/* Inverse equations
  -----------------*/
x -= false_easting;
y -= false_northing;
arg = y /  (1.4142135623731 * R);

/* Because of division by zero problems, 'arg' can not be 1.0.  Therefore
   a number very close to one is used instead.
   -------------------------------------------------------------------*/
if(fabs(arg) > 0.999999999999) arg=0.999999999999;
theta = asin(arg);
*lon = adjust_lon(lon_center + (x / (0.900316316158 * R * cos(theta))));
if(*lon < (-PI)) *lon= -PI;
if(*lon > PI) *lon= PI;
arg = (2.0 * theta + sin(2.0 * theta)) / PI;
if(fabs(arg) > 1.0)arg=1.0;
*lat = asin(arg);
return(OK);
}
/* Orthographic forward equations--mapping lat,long to x,y
  ---------------------------------------------------*/
long orthfor
(
    double lon,			/* (I) Longitude 		*/
    double lat,			/* (I) Latitude 		*/
    double *x,			/* (O) X projection coordinate 	*/
    double *y			/* (O) Y projection coordinate 	*/
)
{
double sinphi, cosphi;	/* sin and cos value				*/
double dlon;		/* delta longitude value			*/
double coslon;		/* cos of longitude				*/
double ksp;		/* scale factor					*/
double g;		

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
sincos(lat,&sinphi,&cosphi);
coslon = cos(dlon);
g = sin_p14 * sinphi + cos_p14 * cosphi * coslon;
ksp = 1.0;
if ((g > 0) || (fabs(g) <= EPSLN))
  {
  *x = false_easting + r_major * ksp * cosphi * sin(dlon);
  *y = false_northing + r_major * ksp * (cos_p14 * sinphi -
					 sin_p14 * cosphi * coslon);
  }
else
  {
  GCTP_PRINT_ERROR("Point can not be projected");
  return(143);
  }
return(OK);
}
示例#9
0
// Polar Stereographic inverse equations--mapping x,y to lat/long
long Projectoid::psinv(
double x,                       // (O) X projection coordinate
double y,                       // (O) Y projection coordinate
double *lon,                    // (I) Longitude
double *lat)                    // (I) Latitude
{
double rh;				// height above ellipsiod
double ts;				// small value t
double temp;			// temporary variable
long   flag;			// error flag

flag = 0;
x = (x - false_easting) * fac;
y = (y - false_northing) * fac;
rh = sqrt(x * x + y * y);
if (ind != 0)
	ts = rh * tcs / (r_major * mcs);
else
	ts = rh * e4 / (r_major * 2.0);
*lat = fac * phi2z(e, ts, &flag);
if (flag != 0)
	return(flag);
if (rh == 0)
	*lon = fac * center_lon;
else
	{
	temp = atan2(x, -y);
	*lon = adjust_lon(fac * temp + center_lon);
	}

return(OK);

}
示例#10
0
/* Cylinderical Equal Area forward equations--mapping lat,long to x,y
  --------------------------------------------------*/
int ceafor(
double lon,			/* (I) Longitude 		*/
double lat,			/* (I) Latitude 		*/
double *x,			/* (O) X projection coordinate 	*/
double *y)			/* (O) Y projection coordinate 	*/
{
double dlon;		        /* delta longitude value	*/
double sinphi;		        /* sin value	       		*/
double q;

/* Forward equations
  -----------------*/
 dlon = adjust_lon(lon - lon_center);
 sinphi = sin(lat);

 if( ind != 0) /* sphere */
   {
     *x = false_easting + r_major * dlon * cosphi1;
     *y = false_northing + r_major * sinphi / cosphi1;
   }
 else /* ellipsoid */
   {
     q = (1.0 - es) * ((sinphi / (1.0 - es * sinphi * sinphi))
		       - (1.0 / (2.0 * e)) * 
		       log((1.0 - e * sinphi)/(1.0 + e * sinphi)));
     *x = false_easting + (r_major * kz * dlon);
     *y = false_northing + (r_major * q) / (2.0 * kz);
   }

return(OK);
}
示例#11
0
/* Polyconic forward equations--mapping lat,long to x,y
  ---------------------------------------------------*/
long polyfor
(
    double lon,			/* (I) Longitude 		*/
    double lat,			/* (I) Latitude 		*/
    double *x,			/* (O) X projection coordinate 	*/
    double *y			/* (O) Y projection coordinate 	*/
)
{
double sinphi, cosphi;	/* sin and cos value				*/
double con, ml;		/* cone constant, small m			*/
double ms;		/* small m					*/

/* Forward equations
  -----------------*/
con = adjust_lon(lon - lon_center);
if (fabs(lat) <= .0000001)
   {
   *x = false_easting + r_major * con;
   *y = false_northing - r_major * ml0;
   }
else
   {
   gctp_sincos(lat,&sinphi,&cosphi);
   ml = mlfn(e0, e1, e2, e3, lat);
   ms = msfnz(e,sinphi,cosphi);
   con *= sinphi;
   *x = false_easting + r_major * ms * sin(con)/sinphi;
   *y = false_northing + r_major * (ml - ml0 + ms * (1.0 - cos(con))/sinphi);
   }

return(GCTP_OK);
}
示例#12
0
// Sinusoidal inverse equations--mapping x,y to lat,long 
long Projectoid::sininv(
double x,               // (I) X projection coordinate
double y,               // (I) Y projection coordinate
double *lon,            // (O) Longitude
double *lat)            // (O) Latitude
{
double temp;            // Re-used temporary variable

// Inverse equations
x -= false_easting;
y -= false_northing;
*lat = y / R;
if (fabs(*lat) > HALF_PI) 
	{
	p_error("Input data error", "sinusoidal-inverse");
	return(164);
	}
temp = fabs(*lat) - HALF_PI;
if (fabs(temp) > EPSLN)
	{
	temp = lon_center + x / (R * cos(*lat));
	*lon = adjust_lon(temp);
	}
else
	*lon = lon_center;

return(OK);

}
示例#13
0
/* Wagner IV forward equations--mapping lat,long to x,y
  ----------------------------------------------------*/
long wivfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)
{
double delta_lon;	/* Delta longitude (Given longitude - center */
double theta;
double delta_theta;
double con;
long i;

/* Forward equations
  -----------------*/
delta_lon = adjust_lon(lon - lon_center);
theta = lat;
con = 2.9604205062 * sin(lat);

/* Iterate using the Newton-Raphson method to find theta
  -----------------------------------------------------*/
for (i=0;;i++)
   {
   delta_theta = -(theta + sin(theta) - con) / (1.0 + cos(theta));
   theta += delta_theta;
   if (fabs(delta_theta) < EPSLN) break;
   if (i >= 30) p_error("Iteration failed to converge","wagneriv-forward");
   }
theta /= 2.0;
*x = 0.86310 * R * delta_lon * cos(theta) + false_easting;
*y = 1.56548 * R * sin(theta) + false_northing;
return(GCTP_OK);
}
示例#14
0
/* General Vertical Near-Side Perspective forward equations--mapping 
   lat,long to x,y
  ----------------------------------------------------------------*/
long gvnspfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)

{
double dlon;
double sinphi,cosphi;
double coslon;
double g;
double ksp;

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
gctp_sincos(lat,&sinphi,&cosphi);
coslon = cos(dlon);
g = sin_p15 * sinphi + cos_p15 * cosphi * coslon;
if (g < (1.0/ p))
   {
   p_error("Point cannot be projected","gvnsp-for");
   return(153);
   }
ksp = (p - 1.0)/(p - g);
*x = false_easting + R * ksp * cosphi * sin(dlon);
*y = false_northing + R * ksp * (cos_p15 * sinphi - sin_p15 * cosphi * coslon);

return(GCTP_OK);
}
示例#15
0
/* Polar Stereographic forward equations--mapping lat,long to x,y
  --------------------------------------------------------------*/
int psfor(
double lon,			/* (I) Longitude 		*/
double lat,			/* (I) Latitude 		*/
double *x,			/* (O) X projection coordinate 	*/
double *y)			/* (O) Y projection coordinate 	*/

{
double con1;			/* adjusted longitude		*/
double con2;			/* adjusted latitude		*/
double rh;			/* height above ellipsoid	*/
double sinphi;			/* sin value			*/
double ts;			/* value of small t		*/

con1 = fac * adjust_lon(lon - center_lon);
con2 = fac * lat;
sinphi = sin(con2);
ts = tsfnz(e,con2,sinphi);
if (ind != 0)
   rh = r_major * mcs * ts / tcs;
else
   rh = 2.0 * r_major * ts / e4;
*x = fac * rh * sin(con1) + false_easting;
*y = -fac * rh * cos(con1) + false_northing;;

return(OK);
}
示例#16
0
/* Sinusoidal inverse equations--mapping x,y to lat,long 
  -----------------------------------------------------*/
long sininv
(
    double x,		/* (I) X projection coordinate */
    double y,		/* (I) Y projection coordinate */
    double *lon,		/* (O) Longitude */
    double *lat		/* (O) Latitude */
)
{
double temp;		/* Re-used temporary variable */

/* Inverse equations
  -----------------*/
x -= false_easting;
y -= false_northing;
*lat = y / R;
if (fabs(*lat) > HALF_PI) 
   {
   GCTP_PRINT_ERROR("Input data error");
   return(164);
   }
temp = fabs(*lat) - HALF_PI;
if (fabs(temp) > EPSLN)
   {
   temp = lon_center + x / (R * cos(*lat));
   *lon = adjust_lon(temp);
   }
else *lon = lon_center;
return(OK);
}
示例#17
0
// Polyconic inverse equations--mapping x,y to lat/long
long Projectoid::polyinv(
double x,						// (O) X projection coordinate
double y,						// (O) Y projection coordinate
double *lon,					// (I) Longitude
double *lat)					// (I) Latitude
{
double al;			// temporary values
double b;			// temporary values
double c;			// temporary values
double t;			// <<<F2 OPT>>>
long iflg;			// error flag

// Inverse equations
x -= false_easting;
y -= false_northing;
al = ml0 + y / r_major;
iflg = 0;
t = x / r_major;
if (fabs(al) <= .0000001)
	{
	*lon = t + lon_center;
	*lat = 0.0;
	}
else
	{
	b = al * al + t * t;
	iflg = phi4z(es, e0, e1, e2, e3, al, b, &c, lat);
	if (iflg != OK)
		return(iflg);
	*lon = adjust_lon((asinz(t * c) / sin(*lat)) + lon_center);
	}

return(OK);

}
示例#18
0
double G_geodesic_lat_from_lon(double lon)
{
    adjust_lon(&lon);
    lon = Radians(lon);

    return Degrees(atan(st->A * sin(lon) - st->B * cos(lon)));
}
示例#19
0
/* Mercator inverse equations--mapping x,y to lat/long
  --------------------------------------------------*/
long merinv
(
    double x,			/* (O) X projection coordinate 	*/
    double y,			/* (O) Y projection coordinate 	*/
    double *lon,			/* (I) Longitude 		*/
    double *lat			/* (I) Latitude 		*/
)
{
double ts;		/* small t value				*/
long flag;		/* error flag 					*/


/* Inverse equations
  -----------------*/
flag = 0;
x -= false_easting;
y -= false_northing;
ts = exp(-y/(r_major * m1));
flag = gctp_calc_phi2(e,ts,lat);
if (flag != GCTP_SUCCESS)
   return GCTP_ERROR;
*lon = adjust_lon(lon_center + x/(r_major * m1));

return(OK);
}
示例#20
0
/* Albers Conical Equal Area inverse equations--mapping x,y to lat/long
  -------------------------------------------------------------------*/
int alberinv(
double x,			/* (O) X projection coordinate 	*/
double y,			/* (O) Y projection coordinate 	*/
double *lon,			/* (I) Longitude 		*/
double *lat)			/* (I) Latitude 		*/
{
double rh1;			/* height above ellipsoid	*/
double qs;			/* function q			*/
double con;			/* temporary sign value		*/
double theta;			/* angle			*/
long   flag;			/* error flag;			*/


flag = 0;
x -= false_easting;
y = rh - y + false_northing;;
if (ns0 >= 0)
   {
   rh1 = sqrt(x * x + y * y);
   con = 1.0;
   }
else
   {
   rh1 = -sqrt(x * x + y * y);
   con = -1.0;
   }
theta = 0.0;
if (rh1 != 0.0)
   theta = atan2(con * x, con * y);
con = rh1 * ns0 / r_major;
qs = (c - con * con) / ns0;
if (e3 >= 1e-10)
   {
   con = 1 - .5 * (1.0 - es) * log((1.0 - e3) / (1.0 + e3))/e3;
   if (fabs(fabs(con) - fabs(qs)) > .0000000001 )
      {
      *lat = phi1z(e3,qs,&flag);
      if (flag != 0)
         return(flag);
      }
   else
      {
      if (qs >= 0)
         *lat = .5 * PI;
      else
         *lat = -.5 * PI;
      }
   }
else
   {
   *lat = phi1z(e3,qs,&flag);
   if (flag != 0)
      return(flag);
   }

*lon = adjust_lon(theta/ns0 + lon_center);

return(OK);
}
示例#21
0
/* Universal Transverse Mercator forward equations--mapping lat,long to x,y
   Note:  The algorithm for UTM is exactly the same as TM and therefore
	  if a change is implemented, also make the change to TMFOR.c
  -----------------------------------------------------------------------*/
long utmfor
(
    double lon,			/* (I) Longitude 		*/
    double lat,			/* (I) Latitude 		*/
    double *x,			/* (O) X projection coordinate 	*/
    double *y			/* (O) Y projection coordinate 	*/
)
{
    double delta_lon;	/* Delta longitude (Given longitude - center 	*/
    double sin_phi, cos_phi;/* sin and cos value				*/
    double al, als;		/* temporary values				*/
    double b;		/* temporary values				*/
    double c, t, tq;	/* temporary values				*/
    double con, n, ml;	/* cone constant, small m			*/

    /* Forward equations
      -----------------*/
    delta_lon = adjust_lon(lon - lon_center);
    gctp_sincos(lat, &sin_phi, &cos_phi);

    /* This part was in the fortran code and is for the spherical form
    ----------------------------------------------------------------*/
    if (ind != 0)
    {
        b = cos_phi * sin(delta_lon);
        if ((fabs(fabs(b) - 1.0)) < .0000000001)
        {
            p_error("Point projects into infinity","utm-for");
            return(93);
        }
        else
        {
            *x = .5 * r_major * scale_factor * log((1.0 + b)/(1.0 - b));
            con = acos(cos_phi * cos(delta_lon)/sqrt(1.0 - b*b));
            if (lat < 0)
                con = - con;
            *y = r_major * scale_factor * (con - lat_origin);
            return(GCTP_OK);
        }
    }

    al  = cos_phi * delta_lon;
    als = SQUARE(al);
    c   = esp * SQUARE(cos_phi);
    tq  = tan(lat);
    t   = SQUARE(tq);
    con = 1.0 - es * SQUARE(sin_phi);
    n   = r_major / sqrt(con);
    ml  = r_major * mlfn(e0, e1, e2, e3, lat);

    *x  = scale_factor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 *
                                   (5.0 - 18.0 * t + SQUARE(t) + 72.0 * c - 58.0 * esp))) + false_easting;

    *y  = scale_factor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 *
                          (5.0 - t + 9.0 * c + 4.0 * SQUARE(c) + als / 30.0 * (61.0 - 58.0 * t
                                  + SQUARE(t) + 600.0 * c - 330.0 * esp))))) + false_northing;

    return(GCTP_OK);
}
示例#22
0
/* Van Der Grinten forward equations--mapping lat,long to x,y
  ---------------------------------------------------------*/
long vandgfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)

{
    double dlon;
    double theta;
    double al,asq;
    double g,gsq;
    double m,msq;
    double con;
    double costh,sinth;

    /* Forward equations
      -----------------*/
    dlon = adjust_lon(lon  - lon_center);

    if (fabs(lat) <= EPSLN)
    {
        *x = false_easting  + R * dlon;
        *y = false_northing;
        return (GCTP_OK);
    }
    theta = asinz(2.0 * fabs(lat / PI));
    if ((fabs(dlon) <= EPSLN) || (fabs(fabs(lat) - HALF_PI) <= EPSLN))
    {
        *x = false_easting;
        if (lat >= 0)
            *y = false_northing + PI * R * tan(.5 * theta);
        else
            *y = false_northing + PI * R * -tan(.5 * theta);
        return(GCTP_OK);
    }
    al = .5 * fabs((PI / dlon) - (dlon / PI));
    asq = al * al;
    gctp_sincos(theta,&sinth,&costh);
    g = costh / (sinth + costh - 1.0);
    gsq = g * g;
    m = g * (2.0 / sinth - 1.0);
    msq = m * m;
    con = PI * R * (al * (g - msq) + sqrt(asq * (g - msq) * (g - msq) - (msq + asq)
                                          * (gsq - msq))) / (msq + asq);
    if (dlon < 0)
        con = -con;
    *x = false_easting + con;
    con = fabs(con / (PI * R));
    if (lat >= 0)
        *y = false_northing + PI * R * sqrt(1.0 - con * con - 2.0 * al * con);
    else
        *y = false_northing - PI * R * sqrt(1.0 - con * con - 2.0 * al * con);

    return(GCTP_OK);
}
示例#23
0
/* Van Der Grinten inverse equations--mapping x,y to lat/long
  ---------------------------------------------------------*/
long vandginv
(
    double x,			/* (O) X projection coordinate */
    double y,			/* (O) Y projection coordinate */
    double *lon,			/* (I) Longitude */
    double *lat			/* (I) Latitude */
)

{
double xx,yy,xys,c1,c2,c3;
double a1;
double m1;
double con;
double th1;
double d;

/* inverse equations
  -----------------*/
x -= false_easting;
y -= false_northing;
con = PI * R;
xx = x / con;
yy = y / con;
xys = xx * xx + yy * yy;
c1 = -fabs(yy) * (1.0 + xys);
c2 = c1 - 2.0 * yy * yy + xx * xx;
c3 = -2.0 * c1 + 1.0 + 2.0 * yy * yy + xys * xys;
d = yy * yy / c3 + (2.0 * c2 * c2 * c2 / c3 / c3 / c3 - 9.0 * c1 * c2 / c3 /c3)
    / 27.0;
a1 = (c1 - c2 * c2 / 3.0 / c3) / c3;
m1 = 2.0 * sqrt( -a1 / 3.0);
con = ((3.0 * d) / a1) / m1;
if (fabs(con) > 1.0)
   {
   if (con >= 0.0)
      con = 1.0;
   else
      con = -1.0;
   }
th1 = acos(con) / 3.0;
if (y >= 0)
   *lat = (-m1 * cos(th1 + PI / 3.0) - c2 / 3.0 / c3) * PI;
else
   *lat = -(-m1 * cos(th1 + PI / 3.0) - c2 / 3.0 / c3) * PI;

if (fabs(xx) < EPSLN)
   {
   *lon = lon_center;
   return(GCTP_OK);
   }
*lon = adjust_lon(lon_center + PI * (xys - 1.0 + sqrt(1.0 + 2.0 * 
		 (xx * xx - yy * yy) + xys * xys)) / 2.0 / xx);

return(GCTP_OK);
}
示例#24
0
long imolwinv
(
    double x,		/* (I) X projection coordinate */
    double y,		/* (I) Y projection coordinate */
    double *lon,		/* (O) Longitude */
    double *lat		/* (O) Latitude */
)
{
double theta;
long region;

/* Inverse equations
  -----------------*/
if (y >= 0.0)
   {
   if (x <= R * -1.41421356248) region = 0;
   else if (x <= R * 0.942809042) region = 1;
   else region = 2;
   }
else
   {
   if (x <= R * -0.942809042) region = 3;
   else if (x <= R * 1.41421356248) region = 4;
   else region = 5;
   }
x = x - feast[region];

theta = asin(y / (1.4142135623731 * R));
*lon = adjust_lon(lon_center[region] + (x / (0.900316316158*R * cos(theta))));
*lat = asin((2.0 * theta + sin(2.0 * theta)) / PI);

/* Are we in a interrupted area?  If so, return status code of GCTP_IN_BREAK.
  ---------------------------------------------------------------------*/
if (region == 0 && (*lon < 0.34906585 || *lon > 1.91986217719))
   return(GCTP_IN_BREAK);
if (region == 1 && ((*lon < 1.91986217719 && *lon > 0.34906585) || 
              (*lon > -1.74532925199 && *lon < 0.34906585)))
   return(GCTP_IN_BREAK);
if (region == 2 && (*lon < -1.745329252 || *lon > 0.34906585))
    return(GCTP_IN_BREAK);
if (region == 3 && (*lon < 0.34906585 || *lon > 2.44346095279))
   return(GCTP_IN_BREAK);
if (region == 4 && ((*lon < 2.44346095279 && *lon > 0.34906585) || 
              (*lon > -1.2217304764 && *lon < 0.34906585)))
   return(GCTP_IN_BREAK);
if (region == 5 && (*lon < -1.2217304764 || *lon> 0.34906585))
   return(GCTP_IN_BREAK);
return(GCTP_OK);
}
示例#25
0
/* Equirectangular forward equations--mapping lat,long to x,y
  ---------------------------------------------------------*/
int equifor(
double lon,			/* (I) Longitude 		*/
double lat,			/* (I) Latitude 		*/
double *x,			/* (O) X projection coordinate 	*/
double *y)			/* (O) Y projection coordinate 	*/
{
double dlon;		/* delta longitude value			*/

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
*x = false_easting + r_major * dlon * cos(lat_origin);
*y = false_northing + r_major * lat;
return(OK);
}
示例#26
0
/* Miller Cylindrical forward equations--mapping lat,long to x,y
  ------------------------------------------------------------*/
int millfor(
double lon,			/* (I) Longitude */
double lat,			/* (I) Latitude */
double *x,			/* (O) X projection coordinate */
double *y)			/* (O) Y projection coordinate */

{
double dlon;

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
*x = false_easting + R * dlon;
*y = false_northing + R * log(tan((PI / 4.0) + (lat / 2.5))) * 1.25;

return(OK);
}
示例#27
0
// Lambert Conformal Conic inverse equations--mapping x,y to lat/long
long Projectoid::lamccinv(
double x,                       // (O) X projection coordinate
double y,                       // (O) Y projection coordinate
double *lon,                    // (I) Longitude
double *lat)                    // (I) Latitude
{
double rh1;                     // height above ellipsoid
double con;                     // sign variable
double ts;                      // small t
double theta;                   // angle
long   flag;                    // error flag

flag = 0;
x -= false_easting;
y = rh - y + false_northing;
if (ns > 0)
	{
	rh1 = sqrt(x * x + y * y);
	con = 1.0;
	}
else
	{
	rh1 = -sqrt(x * x + y * y);
	con = -1.0;
	}

theta = 0.0;
if (rh1 != 0)
	theta = atan2((con * x), (con * y));
if ((rh1 != 0) || (ns > 0.0))
	{
	con = 1.0 / ns;
	ts = pow((rh1 / (r_major * f0)), con);
	*lat = phi2z(e, ts, &flag);
	if (flag != 0)
		return(flag);
	}
else
	*lat = -HALF_PI;
*lon = adjust_lon(theta / ns + center_lon);

return(OK);

}
示例#28
0
/* Mollweide forward equations--mapping lat,long to x,y
  ----------------------------------------------------*/
long molwfor
(
    double lon,			/* (I) Longitude */
    double lat,			/* (I) Latitude */
    double *x,			/* (O) X projection coordinate */
    double *y			/* (O) Y projection coordinate */
)
{
double delta_lon;	/* Delta longitude (Given longitude - center */
double theta;
double delta_theta;
double con;
long i;

/* Forward equations
  -----------------*/
delta_lon = adjust_lon(lon - lon_center);
theta = lat;
con = PI * sin(lat);

/* Iterate using the Newton-Raphson method to find theta
  -----------------------------------------------------*/
for (i=0;;i++)
   {
   delta_theta = -(theta + sin(theta) - con)/ (1.0 + cos(theta));
   theta += delta_theta;
   if (fabs(delta_theta) < EPSLN) break;
   if (i >= 50) 
     {
     GCTP_PRINT_ERROR("Iteration failed to converge");
     return(241);
     }
   }
theta /= 2.0;

/* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
   this is done here because of precision problems with "cos(theta)"
   --------------------------------------------------------------------------*/
if (PI/2 - fabs(lat) < EPSLN)
   delta_lon =0;
*x = 0.900316316158 * R * delta_lon * cos(theta) + false_easting;
*y = 1.4142135623731 * R * sin(theta) + false_northing;
return(OK);
}
示例#29
0
/* HAMMER inverse equations--mapping x,y to lat/long
  ------------------------------------------------*/
int haminv(
double x,			/* (O) X projection coordinate */
double y,			/* (O) Y projection coordinate */
double *lon,			/* (I) Longitude */
double *lat)			/* (I) Latitude */

{
double fac;

/* Inverse equations
  -----------------*/
x -= false_easting;
y -= false_northing;
fac = sqrt(4.0 * R * R - (x * x)/ 4.0 - y * y) / 2.0;
*lon = adjust_lon(lon_center + 2.0 * 
                  atan2((x * fac), (2.0 * R * R - x * x/4 - y * y)));
*lat = asinz(y * fac / R / R);
return(OK);
}
示例#30
0
/* Azimuthal forward equations--mapping lat,long to x,y
  ---------------------------------------------------*/
long azimfor
(
    double lon,			/* (I) Longitude 		*/
    double lat,			/* (I) Latitude 		*/
    double *x,			/* (O) X projection coordinate 	*/
    double *y			/* (O) Y projection coordinate 	*/
)
{
double sinphi, cosphi;	/* sin and cos value				*/
double dlon;		/* delta longitude value			*/
double coslon;		/* cos of longitude				*/
double ksp;		/* scale factor					*/
double g;		
double con;		/* radius of circle				*/
double z;		/* angle					*/

/* Forward equations
  -----------------*/
dlon = adjust_lon(lon - lon_center);
sincos(lat,&sinphi,&cosphi);
coslon = cos(dlon);
g = sin_p12 * sinphi + cos_p12 * cosphi * coslon;
if (fabs(fabs(g) - 1.0) < EPSLN)
   {
   ksp = 1.0;
   if (g < 0.0)
     {
     con = 2.0 * HALF_PI * r_major;
     GCTP_PRINT_ERROR("Point projects into a circle of radius = %12.2f",con);
     return(123);
     }
   }
else
   {
   z = acos(g);
   ksp = z/ sin(z);
   }
*x = false_easting + r_major * ksp * cosphi * sin(dlon);
*y = false_northing + r_major * ksp * (cos_p12 * sinphi - sin_p12 * 
				cosphi * coslon); 
return(OK);
}