OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimUpsProjection.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*******************************************************************
9 // $Id: ossimUpsProjection.cpp 17815 2010-08-03 13:23:14Z dburken $
12 
13 #define PI 3.14159265358979323e0 /* PI */
14 #define PI_OVER (PI/2.0e0) /* PI over 2 */
15 #define MAX_LAT ((PI * 90)/180.0) /* 90 degrees in radians */
16 #define MAX_ORIGIN_LAT ((81.114528 * PI) / 180.0)
17 #define MIN_NORTH_LAT (83.5*PI/180.0)
18 #define MIN_SOUTH_LAT (-79.5*PI/180.0)
19 #define MIN_EAST_NORTH 0
20 #define MAX_EAST_NORTH 4000000
21 
22 #define UPS_NO_ERROR 0x0000
23 #define UPS_LAT_ERROR 0x0001
24 #define UPS_LON_ERROR 0x0002
25 #define UPS_HEMISPHERE_ERROR 0x0004
26 #define UPS_EASTING_ERROR 0x0008
27 #define UPS_NORTHING_ERROR 0x0010
28 #define UPS_A_ERROR 0x0020
29 #define UPS_INV_F_ERROR 0x0040
30 
31 RTTI_DEF1(ossimUpsProjection, "ossimUpsProjection", ossimMapProjection);
32 
34  const ossimGpt& origin)
35  :ossimMapProjection(ellipsoid, origin)
36 {
37  setDefaults();
38  update();
39 }
40 
41 
43 {
44  if(theOrigin.latd() >= -FLT_EPSILON)
45  {
47  theHemisphere = 'N';
48  }
49  else
50  {
52  theHemisphere = 'S';
53  }
54  UPS_False_Easting = 2000000;
55  UPS_False_Northing = 2000000;
56  false_easting = 0.0;
57  false_northing = 0.0;
58  UPS_Easting = 0.0;
59  UPS_Northing = 0.0;
62  0.0,0.0);
63 }
64 
65 void ossimUpsProjection::setHemisphere(char hemisphere)
66 {
67  theHemisphere = hemisphere;
68  update();
69 }
70 
71 ossimGpt ossimUpsProjection::inverse(const ossimDpt &eastingNorthing)const
72 {
73  double lat = 0.0;
74  double lon = 0.0;
75 
77  eastingNorthing.x,
78  eastingNorthing.y,
79  &lat,
80  &lon);
81 
82  return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum);
83 }
84 
86 {
87  double easting = 0.0;
88  double northing = 0.0;
89  ossimGpt gpt = latLon;
90 
91  if (theDatum)
92  {
93  if (theDatum->code() != latLon.datum()->code())
94  {
95  gpt.changeDatum(theDatum); // Shift to our datum.
96  }
97  }
98 
100  gpt.lonr(),
101  &theHemisphere,
102  &easting,
103  &northing);
104 
105  return ossimDpt(easting, northing);
106 }
107 
109 {
112 
115 
117 }
118 
124  const char* prefix)const
125 {
126  return ossimMapProjection::saveState(kwl, prefix);
127 }
128 
134  const char* prefix)
135 {
136  setDefaults();
137 
138  return ossimMapProjection::loadState(kwl, prefix);
139 }
140 
141 /************************************************************************/
142 /* FUNCTIONS
143  *
144  */
145 
146 
148  double f)
149 {
150 /*
151  * The function SET_UPS_PARAMETERS receives the ellipsoid parameters and sets
152  * the corresponding state variables. If any errors occur, the error code(s)
153  * are returned by the function, otherwise UPS_NO_ERROR is returned.
154  *
155  * a : Semi-major axis of ellipsoid in meters (input)
156  * f : Flattening of ellipsoid (input)
157  */
158 
159 // double inv_f = 1 / f;
160  long Error_Code = UPS_NO_ERROR;
161 
162 // if (a <= 0.0)
163 // { /* Semi-major axis must be greater than zero */
164 // Error_Code |= UPS_A_ERROR;
165 // }
166 // if ((inv_f < 250) || (inv_f > 350))
167 // { /* Inverse flattening must be between 250 and 350 */
168 // Error_Code |= UPS_INV_F_ERROR;
169 // }
170 
171  if (!Error_Code)
172  { /* no errors */
173  UPS_a = a;
174  UPS_f = f;
175  }
176  return (Error_Code);
177 } /* END of Set_UPS_Parameters */
178 
179 
181  double *f)const
182 {
183 /*
184  * The function Get_UPS_Parameters returns the current ellipsoid parameters.
185  *
186  * a : Semi-major axis of ellipsoid, in meters (output)
187  * f : Flattening of ellipsoid (output)
188  */
189 
190  *a = UPS_a;
191  *f = UPS_f;
192 
193  return;
194 } /* END OF Get_UPS_Parameters */
195 
196 
198  double Longitude,
199  char * /* Hemisphere */,
200  double *Easting,
201  double *Northing)const
202 {
203 /*
204  * The function Convert_Geodetic_To_UPS converts geodetic (latitude and
205  * longitude) coordinates to UPS (hemisphere, easting, and northing)
206  * coordinates, according to the current ellipsoid parameters. If any
207  * errors occur, the error code(s) are returned by the function,
208  * otherwide UPS_NO_ERROR is returned.
209  *
210  * Latitude : Latitude in radians (input)
211  * Longitude : Longitude in radians (input)
212  * Hemisphere : Hemisphere either 'N' or 'S' (output)
213  * Easting : Easting/X in meters (output)
214  * Northing : Northing/Y in meters (output)
215  */
216 
217  double tempEasting, tempNorthing;
218  long Error_Code = UPS_NO_ERROR;
219 
220 // if ((Latitude < -MAX_LAT) || (Latitude > MAX_LAT))
221 // { /* latitude out of range */
222 // Error_Code |= UPS_LAT_ERROR;
223 // }
224 // if ((Latitude < 0) && (Latitude > MIN_SOUTH_LAT))
225 // Error_Code |= UPS_LAT_ERROR;
226 // if ((Latitude >= 0) && (Latitude < MIN_NORTH_LAT))
227 // Error_Code |= UPS_LAT_ERROR;
228 // if ((Longitude < -PI) || (Longitude > (2 * PI)))
229 // { /* slam out of range */
230 // Error_Code |= UPS_LON_ERROR;
231 // }
232 
233  if (!Error_Code)
234  { /* no errors */
235 // if (Latitude < 0)
236 // {
237 // UPS_Origin_Latitude = -MAX_ORIGIN_LAT;
238 // *Hemisphere = 'S';
239 // }
240 // else
241 // {
242 // UPS_Origin_Latitude = MAX_ORIGIN_LAT;
243 // *Hemisphere = 'N';
244 // }
245 
246 
248  UPS_f,
253 
255  Longitude,
256  &tempEasting,
257  &tempNorthing);
258 
259  UPS_Easting = UPS_False_Easting + tempEasting;
260  UPS_Northing = UPS_False_Northing + tempNorthing;
261 
262 
263  *Easting = UPS_Easting;
264  *Northing = UPS_Northing;
265  } /* END of if(!Error_Code) */
266 
267  return (Error_Code);
268 } /* END OF Convert_Geodetic_To_UPS */
269 
270 
272  double Easting,
273  double Northing,
274  double *Latitude,
275  double *Longitude)const
276 {
277 /*
278  * The function Convert_UPS_To_Geodetic converts UPS (hemisphere, easting,
279  * and northing) coordinates to geodetic (latitude and longitude) coordinates
280  * according to the current ellipsoid parameters. If any errors occur, the
281  * error code(s) are returned by the function, otherwise UPS_NO_ERROR is
282  * returned.
283  *
284  * Hemisphere : Hemisphere either 'N' or 'S' (input)
285  * Easting : Easting/X in meters (input)
286  * Northing : Northing/Y in meters (input)
287  * Latitude : Latitude in radians (output)
288  * Longitude : Longitude in radians (output)
289  */
290 
291  long Error_Code = UPS_NO_ERROR;
292 
293 // if ((Hemisphere != 'N') && (Hemisphere != 'S'))
294 // Error_Code |= UPS_HEMISPHERE_ERROR;
295 // if ((Easting < MIN_EAST_NORTH) || (Easting > MAX_EAST_NORTH))
296 // Error_Code |= UPS_EASTING_ERROR;
297 // if ((Northing < MIN_EAST_NORTH) || (Northing > MAX_EAST_NORTH))
298 // Error_Code |= UPS_NORTHING_ERROR;
299 
300  if (Hemisphere =='N')
302  if (Hemisphere =='S')
304 
305  if (!Error_Code)
306  { /* no errors */
308  UPS_f,
313 
314 
315 
317  Northing,
318  Latitude,
319  Longitude);
320 
321 
322 // if ((*Latitude < 0) && (*Latitude > MIN_SOUTH_LAT))
323 // Error_Code |= UPS_LAT_ERROR;
324 // if ((*Latitude >= 0) && (*Latitude < MIN_NORTH_LAT))
325 // Error_Code |= UPS_LAT_ERROR;
326  } /* END OF if(!Error_Code) */
327  return (Error_Code);
328 } /* END OF Convert_UPS_To_Geodetic */
329 
330 //*************************************************************************************************
332 //*************************************************************************************************
334 {
335  if (!ossimMapProjection::operator==(proj))
336  return false;
337 
338  const ossimUpsProjection* p = dynamic_cast<const ossimUpsProjection*>(&proj);
339  if (!p) return false;
340 
341  if (theHemisphere != p->theHemisphere) return false;
342 
343  return true;
344 }
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
#define DEG_PER_RAD
Represents serializable keyword/value map.
long Set_Polar_Stereographic_Parameters(double a, double f, double Latitude_of_True_Scale, double Longitude_Down_from_Pole, double False_Easting, double False_Northing)
long Convert_Geodetic_To_UPS(double Latitude, double Longitude, char *Hemisphere, double *Easting, double *Northing) const
#define MAX_ORIGIN_LAT
double y
Definition: ossimDpt.h:165
virtual const ossimString & code() const
Definition: ossimDatum.h:57
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
void changeDatum(const ossimDatum *datum)
This will actually perform a shift.
Definition: ossimGpt.cpp:316
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
void Get_UPS_Parameters(double *a, double *f) const
RTTI_DEF1(ossimUpsProjection, "ossimUpsProjection", ossimMapProjection)
#define FLT_EPSILON
const double & getA() const
double lonr() const
Returns the longitude in radian measure.
Definition: ossimGpt.h:76
long Set_UPS_Parameters(double a, double f)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual ossimGpt inverse(const ossimDpt &eastingNorthing) const
Will take a point in meters and convert it to ground.
#define UPS_NO_ERROR
long Convert_Geodetic_To_Polar_Stereographic(double Latitude, double Longitude, double *Easting, double *Northing)
virtual bool operator==(const ossimProjection &projection) const
Returns TRUE if principal parameters are within epsilon tolerance.
double x
Definition: ossimDpt.h:164
double latr() const
latr().
Definition: ossimGpt.h:66
void setHemisphere(char hemisphere)
const double & getFlattening() const
ossimEllipsoid theEllipsoid
This method verifies that the projection parameters match the current pcs code.
long Convert_Polar_Stereographic_To_Geodetic(double Easting, double Northing, double *Latitude, double *Longitude)
ossimDpt theFalseEastingNorthing
Hold the false easting northing.
long Convert_UPS_To_Geodetic(char Hemisphere, double Easting, double Northing, double *Latitude, double *Longitude) const
ossimUpsProjection(const ossimEllipsoid &ellipsoid=ossimEllipsoid(), const ossimGpt &origin=ossimGpt())
virtual ossimDpt forward(const ossimGpt &latLon) const
All map projections will convert the world coordinate to an easting northing (Meters).
const ossimDatum * theDatum
This is only set if we want to have built in datum shifting.