OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
lamazfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME LAMBERT AZIMUTHAL EQUAL-AREA
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Lambert Azimuthal Equal-Area projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
8 
9 This function was adapted from the Lambert Azimuthal Equal Area projection
10 code (FORTRAN) in the General Cartographic Transformation Package software
11 which is available from the U.S. Geological Survey National Mapping Division.
12 
13 ALGORITHM REFERENCES
14 
15 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
16  The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
17 
18 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
19  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
20  State Government Printing Office, Washington D.C., 1987.
21 
22 3. "Software Documentation for GCTP General Cartographic Transformation
23  Package", U.S. Geological Survey National Mapping Division, May 1982.
24 *******************************************************************************/
25 #include <stdio.h>
26 #include "oli_cproj.h"
27 #include "oli_local.h"
28 
29 /* Variables common to all subroutines in this code file
30  -----------------------------------------------------*/
31 static double lon_center; /* Center longitude (projection center) */
32 static double R; /* Radius of the earth (sphere) */
33 static double sin_lat_o; /* Sine of the center latitude */
34 static double cos_lat_o; /* Cosine of the center latitude */
35 static double false_easting; /* x offset in meters */
36 static double false_northing; /* y offset in meters */
37 
38 /* Initialize the Lambert Azimuthal Equal Area projection
39  ------------------------------------------------------*/
40 long lamazforint
41 (
42  double r, /* (I) Radius of the earth (sphere) */
43  double center_long, /* (I) Center longitude */
44  double center_lat, /* (I) Center latitude */
45  double false_east, /* x offset in meters */
46  double false_north /* y offset in meters */
47 )
48 {
49 /* Place parameters in static storage for common use
50  -------------------------------------------------*/
51 R = r;
52 lon_center = center_long;
53 false_easting = false_east;
54 false_northing = false_north;
55 sincos(center_lat, &sin_lat_o, &cos_lat_o);
56 
57 /* Report parameters to the user
58  -----------------------------*/
59 gctp_print_title("LAMBERT AZIMUTHAL EQUAL-AREA");
61 gctp_print_cenlon(center_long);
62 gctp_print_cenlat(center_lat);
63 gctp_print_offsetp(false_easting,false_northing);
64 return(OK);
65 }
66 
67 /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
68  -----------------------------------------------------------------------*/
69 long lamazfor
70 (
71  double lon, /* (I) Longitude */
72  double lat, /* (I) Latitude */
73  double *x, /* (O) X projection coordinate */
74  double *y /* (O) Y projection coordinate */
75 )
76 {
77 double delta_lon; /* Delta longitude (Given longitude - center */
78 double sin_delta_lon; /* Sine of the delta longitude */
79 double cos_delta_lon; /* Cosine of the delta longitude */
80 double sin_lat; /* Sine of the given latitude */
81 double cos_lat; /* Cosine of the given latitude */
82 double g; /* temporary varialbe */
83 double ksp; /* heigth above elipsiod */
84 
85 /* Forward equations
86  -----------------*/
87 delta_lon = adjust_lon(lon - lon_center);
88 sincos(lat, &sin_lat, &cos_lat);
89 sincos(delta_lon, &sin_delta_lon, &cos_delta_lon);
90 g = sin_lat_o * sin_lat + cos_lat_o * cos_lat * cos_delta_lon;
91 if (g == -1.0)
92  {
93  GCTP_PRINT_ERROR("Point projects to a circle of radius = %f\n", 2.0 * R);
94  return(113);
95  }
96 ksp = R * sqrt(2.0 / (1.0 + g));
97 *x = ksp * cos_lat * sin_delta_lon + false_easting;
98 *y = ksp * (cos_lat_o * sin_lat - sin_lat_o * cos_lat * cos_delta_lon) +
99  false_northing;
100 return(OK);
101 }
int r
Definition: decode_rs.h:73
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
long lamazfor(double lon, double lat, double *x, double *y)
Definition: lamazfor.c:70
void gctp_print_cenlon(double A)
Definition: gctp_report.c:40
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
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
long lamazforint(double r, double center_long, double center_lat, double false_east, double false_north)
Definition: lamazfor.c:41
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define R
Definition: make_L3_v1.1.c:96
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57