OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
sterfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME STEREOGRAPHIC
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Stereographic projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
8 
9 ALGORITHM REFERENCES
10 
11 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
12  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
13  State Government Printing Office, Washington D.C., 1987.
14 
15 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
16  U.S. Geological Survey Professional Paper 1453 , United State Government
17  Printing Office, Washington D.C., 1989.
18 *******************************************************************************/
19 #include "oli_cproj.h"
20 #include "oli_local.h"
21 
22 /* Variables common to all subroutines in this code file
23  -----------------------------------------------------*/
24 static double r_major; /* major axis */
25 static double lon_center; /* Center longitude (projection center) */
26 static double lat_origin; /* center latitude */
27 static double false_northing; /* y offset in meters */
28 static double false_easting; /* x offset in meters */
29 static double sin_p10; /* sin of center latitude */
30 static double cos_p10; /* cos of center latitude */
31 
32 /* Initialize the Stereographic projection
33  --------------------------------------*/
34 long sterforint
35 (
36  double r_maj, /* major axis */
37  double center_lon, /* center longitude */
38  double center_lat, /* center latitude */
39  double false_east, /* x offset in meters */
40  double false_north /* y offset in meters */
41 )
42 {
43 /* Place parameters in static storage for common use
44  -------------------------------------------------*/
45 r_major = r_maj;
46 lon_center = center_lon;
47 lat_origin = center_lat;
48 false_northing = false_north;
49 false_easting = false_east;
50 
51 sincos(center_lat,&sin_p10,&cos_p10);
52 
53 /* Report parameters to the user
54  -----------------------------*/
55 gctp_print_title("STEREOGRAPHIC");
56 gctp_print_radius(r_major);
57 gctp_print_cenlonmer(lon_center);
58 gctp_print_origin(lat_origin);
59 gctp_print_offsetp(false_easting,false_northing);
60 return(OK);
61 }
62 
63 
64 /* Stereographic forward equations--mapping lat,long to x,y
65  ---------------------------------------------------*/
66 long sterfor
67 (
68  double lon, /* (I) Longitude */
69  double lat, /* (I) Latitude */
70  double *x, /* (O) X projection coordinate */
71  double *y /* (O) Y projection coordinate */
72 )
73 {
74 double sinphi, cosphi; /* sin and cos value */
75 double dlon; /* delta longitude value */
76 double coslon; /* cos of longitude */
77 double ksp; /* scale factor */
78 double g;
79 
80 /* Forward equations
81  -----------------*/
82 dlon = adjust_lon(lon - lon_center);
83 sincos(lat,&sinphi,&cosphi);
84 coslon = cos(dlon);
85 g = sin_p10 * sinphi + cos_p10 * cosphi * coslon;
86 if (fabs(g + 1.0) <= EPSLN)
87  {
88  GCTP_PRINT_ERROR("Point projects into infinity");
89  return(103);
90  }
91 else
92  {
93  ksp = 2.0 / (1.0 + g);
94  *x = false_easting + r_major * ksp * cosphi * sin(dlon);
95  *y = false_northing + r_major * ksp * (cos_p10 * sinphi - sin_p10 *
96  cosphi * coslon);
97  }
98 return(OK);
99 }
void gctp_print_origin(double A)
Definition: gctp_report.c:65
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
long sterforint(double r_maj, double center_lon, double center_lat, double false_east, double false_north)
Definition: sterfor.c:35
long sterfor(double lon, double lat, double *x, double *y)
Definition: sterfor.c:67
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
#define sincos
Definition: proj_define.h:108
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
#define fabs(a)
Definition: misc.h:93
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define EPSLN
Definition: proj_define.h:86