| 1 |
/******************************************************************************* |
| 2 |
NAME SINUSOIDAL |
| 3 |
|
| 4 |
PURPOSE: Transforms input longitude and latitude to Easting and |
| 5 |
Northing for the Sinusoidal projection. The |
| 6 |
longitude and latitude must be in radians. The Easting |
| 7 |
and Northing values will be returned in meters. |
| 8 |
|
| 9 |
PROGRAMMER DATE REASON |
| 10 |
---------- ---- ------ |
| 11 |
D. Steinwand, EROS May, 1991 |
| 12 |
Abe Taaheri/Raytheon IIS March, 2017 Modified to support both |
| 13 |
spherical and ellipsoidal |
| 14 |
models of earth for r |
| 15 |
Sinusoidal projection |
| 16 |
|
| 17 |
This function was adapted from the Sinusoidal projection code (FORTRAN) in the |
| 18 |
General Cartographic Transformation Package software which is available from |
| 19 |
the U.S. Geological Survey National Mapping Division. |
| 20 |
|
| 21 |
ALGORITHM REFERENCES |
| 22 |
|
| 23 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 24 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 25 |
State Government Printing Office, Washington D.C., 1987. |
| 26 |
|
| 27 |
2. "Software Documentation for GCTP General Cartographic Transformation |
| 28 |
Package", U.S. Geological Survey National Mapping Division, May 1982. |
| 29 |
*******************************************************************************/ |
| 30 |
#include <stdio.h> |
| 31 |
#include "cproj.h" |
| 32 |
|
| 33 |
/* Variables common to all subroutines in this code file |
| 34 |
-----------------------------------------------------*/ |
| 35 |
static double r_major; /* major axis */ |
| 36 |
static double r_minor; /* minor axis */ |
| 37 |
static double lon_center; /* Center longitude (projection center) */ |
| 38 |
static double R; /* Radius of the earth (sphere) */ |
| 39 |
static double false_easting; /* x offset in meters */ |
| 40 |
static double false_northing; /* y offset in meters */ |
| 41 |
static long ind; /* spherical flag */ |
| 42 |
static double e, es; /* eccentricity constants */ |
| 43 |
static double e0,e1,e2,e3; /* eccentricity constants */ |
| 44 |
|
| 45 |
/* Initialize the Sinusoidal projection |
| 46 |
------------------------------------*/ |
| 47 |
int sinforint( |
| 48 |
double r_maj, /* major axis */ |
| 49 |
double r_min, /* minor axis */ |
| 50 |
double center_long, /* (I) Center longitude */ |
| 51 |
double false_east, /* x offset in meters */ |
| 52 |
double false_north) /* y offset in meters */ |
| 53 |
{ |
| 54 |
/* Place parameters in static storage for common use |
| 55 |
-------------------------------------------------*/ |
| 56 |
R = r_maj; |
| 57 |
if(fabs(r_min) < EPSLN ) /* sphere */ |
| 58 |
{ |
| 59 |
r_major = r_maj; |
| 60 |
r_minor = r_maj; |
| 61 |
} |
| 62 |
else /* sphere or ellipsoide */ |
| 63 |
{ |
| 64 |
r_major = r_maj; |
| 65 |
r_minor = r_min; |
| 66 |
} |
| 67 |
|
| 68 |
lon_center = center_long; |
| 69 |
false_easting = false_east; |
| 70 |
false_northing = false_north; |
| 71 |
|
| 72 |
es = 1.0 - SQUARE(r_minor / r_major); |
| 73 |
e = sqrt(es); |
| 74 |
e0 = e0fn(es); |
| 75 |
e1 = e1fn(es); |
| 76 |
e2 = e2fn(es); |
| 77 |
e3 = e3fn(es); |
| 78 |
|
| 79 |
if(es < 0.00001) |
| 80 |
{ |
| 81 |
ind = 1; /* sphere */ } |
| 82 |
else |
| 83 |
{ |
| 84 |
ind = 0; /* ellipsoid */ |
| 85 |
} |
| 86 |
|
| 87 |
/* Report parameters to the user |
| 88 |
-----------------------------*/ |
| 89 |
ptitle("SINUSOIDAL"); |
| 90 |
radius2(r_major, r_minor); |
| 91 |
cenlon(center_long); |
| 92 |
offsetp(false_easting,false_northing); |
| 93 |
return(OK); |
| 94 |
} |
| 95 |
|
| 96 |
/* Sinusoidal forward equations--mapping lat,long to x,y |
| 97 |
-----------------------------------------------------*/ |
| 98 |
int sinfor( |
| 99 |
double lon, /* (I) Longitude */ |
| 100 |
double lat, /* (I) Latitude */ |
| 101 |
double *x, /* (O) X projection coordinate */ |
| 102 |
double *y) /* (O) Y projection coordinate */ |
| 103 |
{ |
| 104 |
double delta_lon; /* Delta longitude (Given longitude - center */ |
| 105 |
double sin_phi, cos_phi;/* sin and cos value */ |
| 106 |
double con, ml; /* cone constant, small m */ |
| 107 |
/* Forward equations |
| 108 |
-----------------*/ |
| 109 |
if (ind != 0) /* Spherical */ |
| 110 |
{ |
| 111 |
delta_lon = adjust_lon(lon - lon_center); |
| 112 |
*x = R * delta_lon * cos(lat) + false_easting; |
| 113 |
*y = R * lat + false_northing; |
| 114 |
return(OK); |
| 115 |
} |
| 116 |
else /* Ellipsoidal */ |
| 117 |
{ |
| 118 |
delta_lon = adjust_lon(lon - lon_center); |
| 119 |
tsincos(lat, &sin_phi, &cos_phi); |
| 120 |
con = 1.0 - es * SQUARE(sin_phi); |
| 121 |
ml = r_major * mlfn(e0, e1, e2, e3, lat); |
| 122 |
*x = r_major * delta_lon * cos_phi / sqrt(con) + false_easting; |
| 123 |
*y = ml + false_northing; |
| 124 |
return(OK); |
| 125 |
} |
| 126 |
} |