| 1 |
/******************************************************************************* |
| 2 |
NAME SPACE OBLIQUE MERCATOR (SOM) |
| 3 |
|
| 4 |
PURPOSE: The first method to Transform input Easting and Northing to |
| 5 |
longitude and latitude for the SOM projection. The |
| 6 |
Easting and Northing must be in meters. The longitude |
| 7 |
and latitude values will be returned in radians. |
| 8 |
|
| 9 |
PROGRAM HISTORY |
| 10 |
PROGRAMMER DATE |
| 11 |
---------- ---- |
| 12 |
D. Steinwand July, 1992 |
| 13 |
T. Mittan Mar, 1993 |
| 14 |
Raj Gejjagaraguppe(ARC) Aug, 1996 Landsat Ratio is removed as hard |
| 15 |
coded value. Now this ratio can be |
| 16 |
an input from the user through the |
| 17 |
projection parameter array element |
| 18 |
number 9. |
| 19 |
|
| 20 |
ALGORITHM REFERENCES |
| 21 |
|
| 22 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 23 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 24 |
State Government Printing Office, Washington D.C., 1987. |
| 25 |
|
| 26 |
2. "Software Documentation for GCTP General Cartographic Transformation |
| 27 |
Package", U.S. Geological Survey National Mapping Division, May 1982. |
| 28 |
*******************************************************************************/ |
| 29 |
#include <stdio.h> |
| 30 |
#include "cproj.h" |
| 31 |
|
| 32 |
static double lon_center,a,b,a2,a4,c1,c3,q,t,u,w,xj,p21,sa,ca,es,s; |
| 33 |
static double som_series(double *fb, double *fa2, double *fa4, double *fc1, |
| 34 |
double *fc3, double *dlam); |
| 35 |
static double false_easting; |
| 36 |
static double false_northing; |
| 37 |
|
| 38 |
int sominvint( |
| 39 |
double r_major, /* major axis */ |
| 40 |
double r_minor, /* minor axis */ |
| 41 |
long satnum, /* Landsat satellite number (1,2,3,4,5) */ |
| 42 |
long path, /* Landsat path number */ |
| 43 |
double alf_in, |
| 44 |
double lon, |
| 45 |
double false_east, /* x offset in meters */ |
| 46 |
double false_north, /* y offset in meters */ |
| 47 |
double time, |
| 48 |
long flag, |
| 49 |
double sat_ratio) |
| 50 |
{ |
| 51 |
long i; |
| 52 |
double alf,e2c,e2s,one_es; |
| 53 |
double dlam,fb,fa2,fa4,fc1,fc3,suma2,suma4,sumc1,sumc3,sumb; |
| 54 |
|
| 55 |
/* Place parameters in static storage for common use |
| 56 |
-------------------------------------------------*/ |
| 57 |
false_easting = false_east; |
| 58 |
false_northing = false_north; |
| 59 |
a = r_major; |
| 60 |
b = r_minor; |
| 61 |
es = 1.0 - SQUARE(r_minor/r_major); |
| 62 |
|
| 63 |
if (flag != 0) |
| 64 |
{ |
| 65 |
alf = alf_in; |
| 66 |
lon_center = lon; |
| 67 |
p21 = time/1440.0; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
if (satnum < 4) |
| 72 |
{ |
| 73 |
alf = 99.092 * D2R; |
| 74 |
p21=103.2669323/1440.0; |
| 75 |
lon_center = (128.87 - (360.0/251.0 * path)) * D2R; |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
alf = 98.2 * D2R; |
| 80 |
p21=98.8841202/1440.0; |
| 81 |
lon_center = (129.30 - (360.0/233.0 * path)) * D2R; |
| 82 |
/* |
| 83 |
lon_center = (129.30557714 - (360.0/233.0 * path)) * D2R; |
| 84 |
*/ |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* Report parameters to the user (to device set up prior to this call) |
| 89 |
-------------------------------------------------------------------*/ |
| 90 |
ptitle("SPACE OBLIQUE MERCATOR"); |
| 91 |
radius2(a,b); |
| 92 |
genrpt_long(path, "Path Number: "); |
| 93 |
genrpt_long(satnum, "Satellite Number: "); |
| 94 |
genrpt(alf*R2D, "Inclination of Orbit: "); |
| 95 |
genrpt(lon_center*R2D, "Longitude of Ascending Orbit: "); |
| 96 |
offsetp(false_easting,false_northing); |
| 97 |
genrpt(sat_ratio, "Landsat Ratio: "); |
| 98 |
|
| 99 |
ca=cos(alf); |
| 100 |
if (fabs(ca)<1.e-9) ca=1.e-9; |
| 101 |
sa=sin(alf); |
| 102 |
e2c=es*ca*ca; |
| 103 |
e2s=es*sa*sa; |
| 104 |
w=(1.0-e2c)/(1.0-es); |
| 105 |
w=w*w-1.0; |
| 106 |
one_es=1.0-es; |
| 107 |
q = e2s / one_es; |
| 108 |
t = (e2s*(2.0-es)) / (one_es*one_es); |
| 109 |
u= e2c / one_es; |
| 110 |
xj = one_es*one_es*one_es; |
| 111 |
dlam=0.0; |
| 112 |
som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam); |
| 113 |
suma2=fa2; |
| 114 |
suma4=fa4; |
| 115 |
sumb=fb; |
| 116 |
sumc1=fc1; |
| 117 |
sumc3=fc3; |
| 118 |
for(i=9;i<=81;i+=18) |
| 119 |
{ |
| 120 |
dlam=i; |
| 121 |
som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam); |
| 122 |
suma2=suma2+4.0*fa2; |
| 123 |
suma4=suma4+4.0*fa4; |
| 124 |
sumb=sumb+4.0*fb; |
| 125 |
sumc1=sumc1+4.0*fc1; |
| 126 |
sumc3=sumc3+4.0*fc3; |
| 127 |
} |
| 128 |
for(i=18; i<=72; i+=18) |
| 129 |
{ |
| 130 |
dlam=i; |
| 131 |
som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam); |
| 132 |
suma2=suma2+2.0*fa2; |
| 133 |
suma4=suma4+2.0*fa4; |
| 134 |
sumb=sumb+2.0*fb; |
| 135 |
sumc1=sumc1+2.0*fc1; |
| 136 |
sumc3=sumc3+2.0*fc3; |
| 137 |
} |
| 138 |
|
| 139 |
dlam=90.0; |
| 140 |
som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam); |
| 141 |
suma2=suma2+fa2; |
| 142 |
suma4=suma4+fa4; |
| 143 |
sumb=sumb+fb; |
| 144 |
sumc1=sumc1+fc1; |
| 145 |
sumc3=sumc3+fc3; |
| 146 |
a2=suma2/30.0; |
| 147 |
a4=suma4/60.0; |
| 148 |
b=sumb/30.0; |
| 149 |
c1=sumc1/15.0; |
| 150 |
c3=sumc3/45.0; |
| 151 |
return(OK); |
| 152 |
} |
| 153 |
|
| 154 |
int sominv( |
| 155 |
double y, /* (I) Y projection coordinate */ |
| 156 |
double x, /* (I) X projection coordinate */ |
| 157 |
double *lon, /* (O) Longitude */ |
| 158 |
double *lat) /* (O) Latitude */ |
| 159 |
{ |
| 160 |
double tlon,conv,sav,sd,sdsq,blon,dif,st,defac,actan,tlat,dd,bigk,bigk2,xlamt; |
| 161 |
double sl,scl,dlat,dlon,temp; |
| 162 |
long inumb; |
| 163 |
|
| 164 |
/* Inverse equations. Begin inverse computation with approximation for tlon. |
| 165 |
Solve for transformed long. |
| 166 |
---------------------------*/ |
| 167 |
temp=y; y=x - false_easting; x= temp - false_northing; |
| 168 |
tlon= x/(a*b); |
| 169 |
conv=1.e-9; |
| 170 |
for(inumb=0;inumb<50;inumb++) |
| 171 |
{ |
| 172 |
sav=tlon; |
| 173 |
sd=sin(tlon); |
| 174 |
sdsq=sd*sd; |
| 175 |
s=p21*sa*cos(tlon)*sqrt((1.0+t*sdsq)/((1.0+w*sdsq)*(1.0+q*sdsq))); |
| 176 |
blon=(x/a)+(y/a)*s/xj-a2*sin(2.0*tlon)-a4*sin(4.0*tlon)-(s/xj)*(c1* |
| 177 |
sin(tlon)+c3*sin(3.0*tlon)); |
| 178 |
tlon=blon/b; |
| 179 |
dif=tlon-sav; |
| 180 |
if(fabs(dif)<conv)break; |
| 181 |
} |
| 182 |
if(inumb>=50) |
| 183 |
{ |
| 184 |
p_error("50 iterations without convergence","som-inverse"); |
| 185 |
return(214); |
| 186 |
} |
| 187 |
|
| 188 |
/* Compute transformed lat. |
| 189 |
------------------------*/ |
| 190 |
st=sin(tlon); |
| 191 |
defac=exp(sqrt(1.0+s*s/xj/xj)*(y/a-c1*st-c3*sin(3.0*tlon))); |
| 192 |
actan=atan(defac); |
| 193 |
tlat=2.0*(actan-(PI/4.0)); |
| 194 |
|
| 195 |
/* Compute geodetic longitude |
| 196 |
--------------------------*/ |
| 197 |
dd=st*st; |
| 198 |
if(fabs(cos(tlon))<1.e-7) tlon=tlon-1.e-7; |
| 199 |
bigk=sin(tlat); |
| 200 |
bigk2=bigk*bigk; |
| 201 |
xlamt=atan(((1.0-bigk2/(1.0-es))*tan(tlon)*ca-bigk*sa*sqrt((1.0+q*dd) |
| 202 |
*(1.0-bigk2)-bigk2*u)/cos(tlon))/(1.0-bigk2*(1.0+u))); |
| 203 |
|
| 204 |
/* Correct inverse quadrant |
| 205 |
------------------------*/ |
| 206 |
if(xlamt>=0.0) sl=1.0; |
| 207 |
if(xlamt<0.0) sl= -1.0; |
| 208 |
if(cos(tlon)>=0.0) scl=1.0; |
| 209 |
if(cos(tlon)<0.0) scl= -1.0; |
| 210 |
xlamt=xlamt-((PI/2.0)*(1.0-scl)*sl); |
| 211 |
dlon=xlamt-p21*tlon; |
| 212 |
|
| 213 |
/* Compute geodetic latitude |
| 214 |
-------------------------*/ |
| 215 |
if(fabs(sa)<1.e-7)dlat=asin(bigk/sqrt((1.0-es)*(1.0-es)+es*bigk2)); |
| 216 |
if(fabs(sa)>=1.e-7)dlat=atan((tan(tlon)*cos(xlamt)-ca*sin(xlamt))/((1.0-es)*sa)); |
| 217 |
*lon = adjust_lon(dlon+lon_center); |
| 218 |
*lat = dlat; |
| 219 |
return(OK); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
/* Series to calculate a,b,c coefficients to convert from transform |
| 226 |
latitude,longitude to Space Oblique Mercator (SOM) rectangular coordinates |
| 227 |
|
| 228 |
Mathematical analysis by John Snyder 6/82 |
| 229 |
--------------------------------------------------------------------------*/ |
| 230 |
static double som_series( |
| 231 |
double *fb, |
| 232 |
double *fa2, |
| 233 |
double *fa4, |
| 234 |
double *fc1, |
| 235 |
double *fc3, |
| 236 |
double *dlam) |
| 237 |
{ |
| 238 |
double sd,sdsq,h,sq,fc; |
| 239 |
|
| 240 |
*dlam= *dlam*0.0174532925; /* Convert dlam to radians */ |
| 241 |
sd=sin(*dlam); |
| 242 |
sdsq=sd*sd; |
| 243 |
s=p21*sa*cos(*dlam)*sqrt((1.0+t*sdsq)/((1.0+w*sdsq)*(1.0+q*sdsq))); |
| 244 |
h=sqrt((1.0+q*sdsq)/(1.0+w*sdsq))*(((1.0+w*sdsq)/((1.0+q*sdsq)*(1.0+ |
| 245 |
q*sdsq)))-p21*ca); |
| 246 |
sq=sqrt(xj*xj+s*s); |
| 247 |
*fb=(h*xj-s*s)/sq; |
| 248 |
*fa2= *fb*cos(2.0* *dlam); |
| 249 |
*fa4= *fb*cos(4.0* *dlam); |
| 250 |
fc=s*(h+xj)/sq; |
| 251 |
*fc1=fc*cos(*dlam); |
| 252 |
*fc3=fc*cos(3.0* *dlam); |
| 253 |
return(0); |
| 254 |
} |