OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimUnitConversionTool.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimUnitConversionTool.cpp 17503 2010-06-02 11:18:49Z dburken $
12 
13 #include <iostream>
14 #include <iomanip>
16 #include <ossim/base/ossimGpt.h>
17 
19  const ossimUnitConversionTool& data)
20 {
21  out << std::setprecision(15) << std::setiosflags(std::ios::fixed)
22  << "Meters: " << data.getMeters()
23  << "\nFeet: " << data.getFeet()
24  << "\nU.S. Survey Feet: " << data.getUsSurveyFeet()
25  << "\nNautical miles: " << data.getNauticalMiles()
26  << "\nDegrees: " << data.getDegrees()
27  << "\nMinutes: " << data.getMinutes()
28  << "\nSeconds: " << data.getSeconds() << std::endl;
29 
30  return out;
31 }
32 
34  ossimUnitType unitType)
35  : theValue(value),
36  theUnitType(unitType),
37  theOrigin()
38 {
39 }
40 
42  double value,
43  ossimUnitType unitType)
44  : theValue(value),
45  theUnitType(unitType),
46  theOrigin(origin)
47 {
48 }
49 
51 {
52  theOrigin = gpt;
53 }
54 
56 {
57  return theOrigin;
58 }
59 
61 {
62  result = theOrigin;
63 }
64 
66  ossimUnitType unitType)
67 {
68  theValue = value;
69  theUnitType = unitType;
70 }
71 
73 {
74  switch(unitType)
75  {
76  case OSSIM_METERS:
77  {
78  return getMeters();
79  }
80  case OSSIM_RADIANS:
81  {
82  return getRadians();
83  }
84  case OSSIM_DEGREES:
85  {
86  return getDegrees();
87  }
89  {
90  return getUsSurveyFeet();
91  }
92  case OSSIM_FEET:
93  {
94  return getFeet();
95  }
96  case OSSIM_SECONDS:
97  {
98  return getSeconds();
99  }
100  case OSSIM_MINUTES:
101  {
102  return getMinutes();
103  }
105  {
106  return getNauticalMiles();
107  }
108  case OSSIM_MILES:
109  {
110  return getMiles();
111  }
112  case OSSIM_MICRONS:
113  {
114  return getMicrons();
115  }
116  case OSSIM_CENTIMETERS:
117  {
118  return getCentimeters();
119  }
120  case OSSIM_MILLIMETERS:
121  {
122  return getMillimeters();
123  }
124  case OSSIM_YARDS:
125  {
126  return getYards();
127  }
128  case OSSIM_INCHES:
129  {
130  return getInches();
131  }
132  case OSSIM_KILOMETERS:
133  {
134  return getKilometers();
135  }
136  default:
137  break;
138  }
139 
140  return ossim::nan();
141 }
142 
144 {
145  setValue(value, OSSIM_METERS);
146 }
147 
149 {
150  setValue(value, OSSIM_RADIANS);
151 }
152 
154 {
155  setValue(value, OSSIM_DEGREES);
156 }
157 
159 {
160  setValue(value, OSSIM_MINUTES);
161 }
162 
164 {
165  setValue(value, OSSIM_SECONDS);
166 }
167 
169 {
171 }
172 
174 {
175  setValue(value, OSSIM_FEET);
176 }
177 
179 {
181 }
182 
184 {
185  setValue(value, OSSIM_MILES);
186 }
187 
189 {
190  setValue(value, OSSIM_MILLIMETERS);
191 }
192 
194 {
195  setValue(value, OSSIM_MICRONS);
196 }
197 
199 {
200  setValue(value, OSSIM_CENTIMETERS);
201 }
202 
204 {
205  setValue(value, OSSIM_YARDS);
206 }
207 
209 {
210  setValue(value, OSSIM_INCHES);
211 }
212 
214 {
215  setValue(value, OSSIM_KILOMETERS);
216 }
217 
219 {
221  {
222  return theValue;
223  }
224 
225  return computeMeters();
226 }
227 
229 {
231  {
232  return theValue;
233  }
234  return getDegrees()*RAD_PER_DEG;
235 }
236 
238 {
239  switch (theUnitType)
240  {
241  case OSSIM_DEGREES:
242  {
243  return theValue;
244  }
245  case OSSIM_MINUTES:
246  {
247  return (theValue / 60.0);
248  }
249  case OSSIM_SECONDS:
250  {
251  return (theValue / 3600.0);
252  }
253  case OSSIM_RADIANS:
254  {
255  return (theValue * DEG_PER_RAD);
256  }
257  default:
258  break;
259  }
260 
262  return (computeMeters() /((pt.x+pt.y)*.5));
263 }
264 
266 {
268  {
269  return theValue;
270  }
271  return (getDegrees()*60.0);
272 }
273 
275 {
277  {
278  return theValue;
279  }
280  return (getDegrees()*3600.0);
281 }
282 
284 {
286  {
287  return theValue;
288  }
289  return (computeMeters()/US_METERS_PER_FT);
290 }
291 
293 {
294  if(theUnitType == OSSIM_FEET)
295  {
296  return theValue;
297  }
298  return (computeMeters()*FT_PER_MTRS);
299 }
300 
302 {
304  {
305  return theValue;
306  }
307 
308  return (computeMeters()/(theOrigin.metersPerDegree().y/60.0));
309 }
310 
312 {
313  if(theUnitType == OSSIM_MILES)
314  {
315  return theValue;
316  }
318 }
319 
321 {
323  {
324  return theValue;
325  }
326  return ((computeMeters()*1e3));
327 }
328 
330 {
332  {
333  return theValue;
334  }
335  return ((computeMeters()*1e6));
336 }
337 
339 {
341  {
342  return theValue;
343  }
344 
345  return ((computeMeters()*1e2));
346 }
347 
349 {
351  {
352  return theValue;
353  }
354 
355  return ((computeMeters()/0.914));
356 }
357 
359 {
361  {
362  return theValue;
363  }
364 
365  return ((getFeet()*12.0));
366 }
367 
369 {
371  {
372  return theValue;
373  }
374  return ((computeMeters()*1e-3));
375 }
376 
378 {
379  switch(theUnitType)
380  {
381  case OSSIM_METERS:
382  {
383  return theValue;
384  break;
385  }
386  case OSSIM_RADIANS:
387  {
389  return (theValue*DEG_PER_RAD)*((pt.x+pt.y)*.5);
390  }
391  case OSSIM_DEGREES:
392  {
394  return theValue*((pt.x+pt.y)*.5);
395  }
397  {
398  return US_METERS_PER_FT*theValue;
399  }
400  case OSSIM_FEET:
401  {
402  return MTRS_PER_FT*theValue;
403  }
404  case OSSIM_SECONDS:
405  {
407  return (theValue/3600.0)*((pt.x+pt.y)*.5);
408  }
409  case OSSIM_MINUTES:
410  {
412  return (theValue/60.0)*((pt.x+pt.y)*.5);
413  }
415  {
416  return (theOrigin.metersPerDegree().y/60.0)*theValue;
417  }
418  case OSSIM_MILES:
419  {
421  }
422  case OSSIM_MILLIMETERS:
423  {
424  return (theValue/(1e3));
425  }
426  case OSSIM_MICRONS:
427  {
428  return (theValue/(1e6));
429  }
430  default:
431  break;
432  }
433 
434  return ossim::nan();
435 }
double getValue(ossimUnitType unitType=OSSIM_METERS) const
#define DEG_PER_RAD
ossimUnitType
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
void setValue(double value, ossimUnitType unitType=OSSIM_METERS)
double y
Definition: ossimDpt.h:165
#define FT_PER_MTRS
#define US_METERS_PER_FT
#define FT_PER_MILE
void setOrigin(const ossimGpt &gpt)
#define MTRS_PER_FT
double x
Definition: ossimDpt.h:164
ossimDpt metersPerDegree() const
Definition: ossimGpt.cpp:498
ossimUnitConversionTool(double value=1.0, ossimUnitType unitType=OSSIM_METERS)
#define RAD_PER_DEG
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
std::ostream & operator<<(std::ostream &out, const ossimUnitConversionTool &data)