OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ossimDms Class Reference

#include <ossimDms.h>

Public Member Functions

 ossimDms ()
 Default constructor. More...
 
 ossimDms (double someDegrees, bool latFlag=true)
 Constructor ossimDms(double, bool) More...
 
 ossimDms (const std::string &value)
 ` Constructor. More...
 
ossimString toString (const ossimString &formatString=ossimString("")) const
 You can specify a number of different formats. More...
 
double getDegrees () const
 
bool getLatFlag () const
 
bool setDegrees (const std::string &value)
 setDegrees(char*). More...
 
ossimDmssetDegrees (double degrees)
 
ossimDmssetLatFlag (bool latFlag)
 

Static Public Attributes

static const ossim_uint8 theDegreeSign = 176
 

Private Member Functions

ossimString degree_to_string (double degrees, char format[], bool lat_flag) const
 char * function degree_to_string More...
 
void calc_mins_or_secs (double *dd, std::string::const_iterator &formatIter, std::string &result) const
 
int calc_mins_or_secs (double *dd, const char *format, char *res) const
 integer function calc_mins_or_secs * calculates minutes from degrees, seconds from minutes,
based on "format", returning the resultant string in "res". More...
 
void setup_printf (int ival, char *fmt) const
 function setup_printf the C library function sprintf takes as its second argument, a format specifier. More...
 
void set_default (char *fp, char *rp) const
 function set_default * assigns a default format to be used as the template for
the conversion of the double precision value, degrees. More...
 
void init_values (double d) const
 function init_values initializes the global values used throughout the function. More...
 
double string_to_degree (const std::string &cdegrees)
 double function string_to_degree More...
 

Private Attributes

double theDegrees
 
bool theLatFlag
 
double theDecDegs
 
bool theAfterDot
 
bool theDoingSeconds
 
int theIntDegs
 
int theSign
 
double theWorking
 

Static Private Attributes

static const char * DEFAULT_FORMAT = "ddd mm.mmC"
 
static const char * SPACES = " "
 

Detailed Description

Definition at line 19 of file ossimDms.h.

Constructor & Destructor Documentation

◆ ossimDms() [1/3]

ossimDms::ossimDms ( )

Default constructor.

Initializes to 0.0 degrees latitude.

Definition at line 27 of file ossimDms.cpp.

28  : theDegrees(0.0),
29  theLatFlag(true),
30  theDecDegs(0.0),
31  theAfterDot(false),
32  theDoingSeconds(true),
33  theIntDegs(0),
34  theSign(1),
35  theWorking(0.0)
36 {
37 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
double theDegrees
Definition: ossimDms.h:96
double theWorking
Definition: ossimDms.h:107
bool theLatFlag
Definition: ossimDms.h:97
double theDecDegs
Definition: ossimDms.h:102
int theSign
Definition: ossimDms.h:106
bool theDoingSeconds
Definition: ossimDms.h:104

◆ ossimDms() [2/3]

ossimDms::ossimDms ( double  someDegrees,
bool  latFlag = true 
)

Constructor ossimDms(double, bool)

You can construct a DMS class with a decimal degree and specify if its for the lat or lon.

latFlag true its for the lat false its for the lon

Definition at line 39 of file ossimDms.cpp.

40  : theDegrees(someDegrees),
41  theLatFlag(latFlag),
42  theDecDegs(0.0),
43  theAfterDot(false),
44  theDoingSeconds(true),
45  theIntDegs(0),
46  theSign(1),
47  theWorking(0.0)
48 {
49 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
double theDegrees
Definition: ossimDms.h:96
double theWorking
Definition: ossimDms.h:107
bool theLatFlag
Definition: ossimDms.h:97
double theDecDegs
Definition: ossimDms.h:102
int theSign
Definition: ossimDms.h:106
bool theDoingSeconds
Definition: ossimDms.h:104

◆ ossimDms() [3/3]

ossimDms::ossimDms ( const std::string &  value)

` Constructor.

You can specify the value in a formated string. Example: "45N" will set the decimal degree to 45 and will set the lat flag to true

"45W" will set the internal degree to negative and set the lat flag to false.

Definition at line 51 of file ossimDms.cpp.

References string_to_degree(), and theDegrees.

52  : theDegrees(0.0),
53  theLatFlag(false),
54  theDecDegs(0.0),
55  theAfterDot(false),
56  theDoingSeconds(true),
57  theIntDegs(0),
58  theSign(1),
59  theWorking(0.0)
60 {
61  if (value != "")
62  {
64  }
65  else
66  {
67  theDegrees = 0.0;
68  }
69 
70 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
double theDegrees
Definition: ossimDms.h:96
double theWorking
Definition: ossimDms.h:107
bool theLatFlag
Definition: ossimDms.h:97
double theDecDegs
Definition: ossimDms.h:102
double string_to_degree(const std::string &cdegrees)
double function string_to_degree
Definition: ossimDms.cpp:807
int theSign
Definition: ossimDms.h:106
bool theDoingSeconds
Definition: ossimDms.h:104

Member Function Documentation

◆ calc_mins_or_secs() [1/2]

void ossimDms::calc_mins_or_secs ( double *  dd,
std::string::const_iterator &  formatIter,
std::string &  result 
) const
private

Definition at line 615 of file ossimDms.cpp.

References theAfterDot.

Referenced by degree_to_string(), and toString().

618 {
619  double du;
620  int ufactor, ires, numunits;
621  char unit;
622 
623  unit = *formatIter; /* set to 'm' or 's' */
624 
625  ufactor = 1, numunits = 0;
626 
627 /* count minutes (or seconds) desired in this part of format */
628 
629  while (*formatIter == unit)
630  {
631  numunits++;
632  formatIter++, ufactor *= 10;
633  }
634 
635 /* different calc based on beyond decimal pt or not */
636 
637  if (theAfterDot == true)
638  {
639  du = *dd * (double)ufactor;
640 // ires = (int)(du + 0.5);
641  ires = (int)(du);
642  *dd = (du - ires);
643  if(*dd < 0.0) *dd = 0.0;
644  }
645  else
646  {
647  du = (*dd * 60.0) * (double)ufactor;
648 // ires = (int)(du + 0.5) / ufactor;
649  ires = (int)(du) / ufactor;
650  *dd = (du - (ires * ufactor)) / (double)ufactor;
651  if(*dd < 0.0) *dd = 0.0;
652  }
653  std::ostringstream out;
654 
655  out << std::setw(numunits)
656  << std::setfill('0')
657  << std::setiosflags(std::ios::right)
658  << std::setprecision(numunits)
659  << ires
660  << std::ends;
661  result+=out.str().c_str();
662 
663 
664 // result += ossimString::toString(ires);
665 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
bool theAfterDot
Definition: ossimDms.h:103

◆ calc_mins_or_secs() [2/2]

int ossimDms::calc_mins_or_secs ( double *  dd,
const char *  format,
char *  res 
) const
private

integer function calc_mins_or_secs * calculates minutes from degrees, seconds from minutes,
based on "format", returning the resultant string in "res".

"dd" is the part of 'degrees' that provides
the value to manipulate. the integer returned as the
value of this function is the number of places in the
format that have been parsed here, to be used in the
main function to advance the format-parsing pointer.

Definition at line 679 of file ossimDms.cpp.

References setup_printf(), and theAfterDot.

682 {
683  double du;
684  int ufactor, ires, numunits;
685  char unit, str_fmt[8];
686 
687  unit = *format; /* set to 'm' or 's' */
688 
689  ufactor = 1, numunits = 0;
690 
691 /* count minutes (or seconds) desired in this part of format */
692 
693  while (*format == unit) {
694  numunits++;
695  format++, ufactor *= 10;
696  }
697 
698 /* different calc based on beyond decimal pt or not */
699 
700  if (theAfterDot == true) {
701  du = *dd * (double)ufactor;
702 // ires = (int)(du + 0.5);
703  ires = (int)(du + 0.5);
704  *dd = (du - ires);
705  }
706  else {
707  du = (*dd * 60.0) * (double)ufactor;
708 // ires = (int)(du + 0.5) / ufactor;
709  ires = (int)(du) / ufactor;
710  *dd = (du - (ires * ufactor)) / (double)ufactor;
711  }
712  setup_printf(numunits, str_fmt);
713  sprintf(res, str_fmt, ires);
714 
715  return(numunits);
716 }
bool theAfterDot
Definition: ossimDms.h:103
void setup_printf(int ival, char *fmt) const
function setup_printf the C library function sprintf takes as its second argument, a format specifier.
Definition: ossimDms.cpp:727

◆ degree_to_string()

ossimString ossimDms::degree_to_string ( double  degrees,
char  format[],
bool  lat_flag 
) const
private

char * function degree_to_string

requires: dts.h
input: double precision, string, integer params returns: pointer to a string

purpose: to convert a double precision number "degrees" to a character string based on the input "format" and a flag indicating whether or not the degrees are latitude. If 'lat_flag' is TRUE, then degrees are latitude, otherwise they are longitude. default format: ddd mm.mmC
returns: a pointer to a string which contains the formatted degree value.
written as part of the DIAL facility, G&G, WHOI April 1992
Christine L. Hammond

Definition at line 475 of file ossimDms.cpp.

References calc_mins_or_secs(), init_values(), set_default(), setup_printf(), theAfterDot, theDecDegs, theDegreeSign, theIntDegs, and theWorking.

478 {
479  char cdegrees[64];
480  char str_fmt[10];
481  char *rptr, *fptr, *sptr;
482  int i, d_s;
483 
484 /* assign a default format if none is given */
485 
486  if (format[0] == '\0')
487  {
488  set_default(format, cdegrees);
489  }
490  else
491  {
492  memset(cdegrees, ' ', 64);
493 // strcpy(cdegrees, SPACES);
494  }
495 
496  init_values(degrees);
497 
498  rptr = cdegrees;
499  fptr = format;
500  sptr = str_fmt;
501 
502 /* cycle through characters of the format and plug in values */
503 
504  while (*fptr != '\0') {
505 
506  switch (*fptr) {
507 
508  case '-': {
509  (theWorking < 0.0) ? (*rptr = '-') : (*rptr = ' ');
510  rptr++, fptr++;
511  break;
512  }
513 
514  case 'c':
515  case 'C': {
516  if (theWorking < 0.0)
517  (lat_flag == true) ? (*rptr = 'S') : (*rptr = 'W');
518  else
519  (lat_flag == true) ? (*rptr = 'N') : (*rptr = 'E');
520 
521  rptr++, fptr++;
522  break;
523  }
524 
525  case 'd':
526  case 'D': { /* how many 'd's until not 'd' */
527  d_s = 1, fptr++;
528  while (*fptr == 'd') {
529  d_s++, fptr++;
530  }
531  setup_printf(d_s, sptr); /* printf's fmt will be %x.xd */
532 
533  if (theAfterDot == true) { /* beyond the decimal point */
534  i = d_s;
535  while (i-- > 0)
536  theDecDegs = theDecDegs * 10.0;
537 // theIntDegs = (int)(theDecDegs + 0.5);
538  theIntDegs = (int)(theDecDegs);
539  }
540 
541  sprintf(rptr, str_fmt, theIntDegs);
542 
543  if (*rptr == '0' && !theAfterDot) /* remove leading zero */
544  *rptr = ' ';
545  rptr += d_s;
546  break;
547  }
548 
549  case ' ': { /* compress multiple spaces in format */
550  *rptr = *fptr;
551  while (*fptr == ' ')
552  fptr++;
553  rptr++;
554  break;
555  }
556 
557  case '.': {
558  if (theAfterDot == true) { /* a second decimal point? */
559  set_default(format, cdegrees);
560  fptr = format;
561  rptr = cdegrees;
562  init_values(degrees);
563  }
564  else {
565  *rptr = *fptr;
566  rptr++, fptr++;
567  theAfterDot = true;
568  }
569  break;
570  }
571 
572  case 'm':
573  case 'M':
574  case 's':
575  case 'S':
576  {
577  i = calc_mins_or_secs(&theDecDegs, fptr, rptr);
578  fptr += i, rptr += i; /* i == num to advance format */
579  break;
580  }
581 
582  // This is code that I added so you can do additional
583  // formatting.
584  //
585  case '\'':
586  case '"':
587  {
588  *rptr = *fptr;
589  rptr++;
590  fptr++;
591  break;
592  }
593  case '@':
594  {
595  *rptr = (char)theDegreeSign;
596  rptr++;
597  fptr++;
598  break;
599  }
600  default: {
601  set_default(format, cdegrees);
602  fptr = format;
603  rptr = cdegrees;
604  init_values(degrees);
605  }
606  } /* end switch statement */
607 
608  } /* end while loop */
609 
610  *rptr = '\0';
611  return(cdegrees);
612 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
void calc_mins_or_secs(double *dd, std::string::const_iterator &formatIter, std::string &result) const
Definition: ossimDms.cpp:615
void set_default(char *fp, char *rp) const
function set_default * assigns a default format to be used as the template for the conversion of th...
Definition: ossimDms.cpp:750
void init_values(double d) const
function init_values initializes the global values used throughout the function.
Definition: ossimDms.cpp:763
double theWorking
Definition: ossimDms.h:107
double theDecDegs
Definition: ossimDms.h:102
static const ossim_uint8 theDegreeSign
Definition: ossimDms.h:90
void setup_printf(int ival, char *fmt) const
function setup_printf the C library function sprintf takes as its second argument, a format specifier.
Definition: ossimDms.cpp:727

◆ getDegrees()

double ossimDms::getDegrees ( ) const
inline

◆ getLatFlag()

bool ossimDms::getLatFlag ( ) const
inline

Definition at line 72 of file ossimDms.h.

72 { return theLatFlag; }
bool theLatFlag
Definition: ossimDms.h:97

◆ init_values()

void ossimDms::init_values ( double  d) const
private

function init_values initializes the global values used throughout the function.

see notes in header file.

Definition at line 763 of file ossimDms.cpp.

References theAfterDot, theDecDegs, theDoingSeconds, theIntDegs, theSign, and theWorking.

Referenced by degree_to_string(), and toString().

764 {
765 
766  theAfterDot = false;
767  theDoingSeconds = false;
768  theSign = 1;
769  if (d < 0.0)
770  theSign = -1;
771 
772  theWorking = d;
773  theIntDegs = (int)theWorking * theSign;
775 
776  return;
777 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
double theWorking
Definition: ossimDms.h:107
double theDecDegs
Definition: ossimDms.h:102
int theSign
Definition: ossimDms.h:106
bool theDoingSeconds
Definition: ossimDms.h:104

◆ set_default()

void ossimDms::set_default ( char *  fp,
char *  rp 
) const
private

function set_default * assigns a default format to be used as the template for
the conversion of the double precision value, degrees.

either an error was detected in parsing the format that
the user entered, or no format was entered at all.
also, clears the result string of any characters which
may have been placed therein prior to the call here.

Definition at line 750 of file ossimDms.cpp.

References DEFAULT_FORMAT, and SPACES.

Referenced by degree_to_string().

751 {
752  strcpy(fp, DEFAULT_FORMAT); /* assign default format */
753  strcpy(rp, SPACES);
754 
755 }
static const char * DEFAULT_FORMAT
Definition: ossimDms.h:93
static const char * SPACES
Definition: ossimDms.h:94

◆ setDegrees() [1/2]

bool ossimDms::setDegrees ( const std::string &  value)

setDegrees(char*).

Will allow you to set the internal paramters through a string. examples:

"45 5 6" will assume degrees minutes seconds "45" will assume degrees. "-45" "45W"

Returns
true on success, false if unhandled characters are found.

Definition at line 79 of file ossimDms.cpp.

References ossimString::c_str(), status, theAfterDot, theDegrees, theDegreeSign, theLatFlag, and theSign.

Referenced by ossimNitfBlockaTag::converLocStringToPt(), and ossimNitfProjectionFactory::parseGeographicString().

80 {
81  bool status = true;
82 
83  ossimString copy = cdegrees;
84 
85  double degrees, factor, dividend, units;
86  int i;
87  bool afterdelim;
88  char* cptr = const_cast<char*>(copy.c_str());
89  char c;
90 
91  theAfterDot = false;
92  afterdelim = false;
93  degrees = 0.0;
94  units = 0.0;
95  factor = 1.0;
96  dividend = 60.0;
97  theSign = 1;
98 
99  /* get rid of leading spaces */
100 
101  while (*cptr == ' ')
102  {
103  cptr++;
104  }
105 
106  while(*cptr != '\0')
107  {
108  switch (*cptr)
109  {
110 
111  // north, west and + values will change sign of degrees to plus.
112 
113  case '+':
114  {
115  theSign = 1;
116  cptr++;
117  }
118  case 'n':
119  case 'N':
120  {
121  theSign = 1;
122  theLatFlag = true;
123  cptr++;
124  break;
125  }
126  case 'e':
127  case 'E':
128  {
129  theLatFlag = false;
130  theSign = 1;
131  cptr++;
132  break;
133  }
134 
135  // south, east and - values will change sign of degrees to minus
136 
137  case '-':
138  {
139  theSign = -1;
140  cptr++;
141  break;
142  }
143  case 's':
144  case 'S':
145  {
146  theSign = -1;
147  cptr++;
148  theLatFlag = true;
149  break;
150  }
151  case 'w':
152  case 'W':
153  {
154  theSign = -1;
155  cptr++;
156  theLatFlag = false;
157  break;
158  }
159 
160  case '0':
161  case '1':
162  case '2':
163  case '3':
164  case '4':
165  case '5':
166  case '6':
167  case '7':
168  case '8':
169  case '9':
170  {
171  c = *cptr;
172  i = (c - '0');
173 
174  if (afterdelim == true)
175  {
176  if (theAfterDot == true)
177  {
178  units = units + (((double)i * factor) / dividend);
179  }
180  else
181  {
182  units = (units * factor) + ((double)i / dividend);
183  }
184  }
185  else
186  {
187  if (theAfterDot == true)
188  {
189  degrees = degrees + ((double)i * factor);
190  }
191  else
192  {
193  degrees = (degrees * factor) + (double)i;
194  }
195  }
196  if (theAfterDot == true)
197  {
198  factor = factor * .10;
199  }
200  else
201  {
202  factor = 10.;
203  }
204 
205  cptr++;
206  break;
207  }
208 
209  //---
210  // a decimal point indicates a change in the factor used
211  // to calculate degrees or units (minutes or seconds)
212  //---
213  case '.':
214  {
215  factor = .10;
216  theAfterDot = true;
217  cptr++;
218  break;
219  }
220 
221  // after a delimiter the value contains minutes, first time through
222  case ' ':
223  case '\"':
224  case '\'':
225  {
226  while (*(cptr + 1) == ' ')
227  {
228  cptr++;
229  }
230 
231  degrees = degrees + units;
232  units = 0.0;
233 
234  if (afterdelim == true) /* must be seconds */
235  {
236  dividend = dividend * dividend;
237  }
238  else
239  {
240  afterdelim = true;
241  }
242 
243  factor = 1.;
244 
245  cptr++;
246 
247  // skip any leading zeroes after delimiter */
248 
249  while (*cptr == '0')
250  {
251  cptr++;
252  }
253 
254  break;
255  }
256 
257  //---
258  // check for a delimiter that is allowable:
259  // isspace allows: space, tab, cr, nl, vt, ff
260  // ispunct allows: punctuation char != space or control or letter
261  //---
262  default:
263  {
264  if(isspace(*cptr) ||
265  ispunct(*cptr) ||
266  ((ossim_uint8)(*cptr) == theDegreeSign))
267  {
268  *cptr = ' ';
269  }
270  else
271  {
272  status = false;
273  ++cptr;
274  }
275  }
276 
277  } // end switch
278 
279  if (status == false)
280  {
281  break;
282  }
283 
284  } // end while loop
285 
286  // add any units that may have been calculated (minutes or seconds)
287  degrees = degrees + units;
288 
289  theDegrees = (degrees * (double)theSign);
290 
291  return status;
292 }
bool theAfterDot
Definition: ossimDms.h:103
double theDegrees
Definition: ossimDms.h:96
return status
bool theLatFlag
Definition: ossimDms.h:97
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static const ossim_uint8 theDegreeSign
Definition: ossimDms.h:90
int theSign
Definition: ossimDms.h:106
unsigned char ossim_uint8

◆ setDegrees() [2/2]

ossimDms & ossimDms::setDegrees ( double  degrees)

Definition at line 72 of file ossimDms.cpp.

References theDegrees.

73 {
74  theDegrees = degrees;
75 
76  return *this;
77 }
double theDegrees
Definition: ossimDms.h:96

◆ setLatFlag()

ossimDms& ossimDms::setLatFlag ( bool  latFlag)
inline

Definition at line 89 of file ossimDms.h.

Referenced by ossimNitfProjectionFactory::parseGeographicString().

89 {theLatFlag = latFlag;return *this;}
bool theLatFlag
Definition: ossimDms.h:97

◆ setup_printf()

void ossimDms::setup_printf ( int  ival,
char *  fmt 
) const
private

function setup_printf the C library function sprintf takes as its second argument, a format specifier.

this function constructs that specifier based on 'ival', an integer indicating the number of d's or m's or s's seen in the group just parsed.

Definition at line 727 of file ossimDms.cpp.

Referenced by calc_mins_or_secs(), and degree_to_string().

728 {
729  char precis[3];
730 
731  strcpy(fmt, "%");
732  sprintf(precis, "%d", ival);
733  strcat(fmt,precis);
734  strcat(fmt,".");
735  strcat(fmt,precis);
736  strcat(fmt,"d");
737 }

◆ string_to_degree()

double ossimDms::string_to_degree ( const std::string &  cdegrees)
private

double function string_to_degree

requires: dts.h input: string variable parameter returns: double precision number

purpose: to calculate a double precision number, representing degrees latitude or longitude, given a string "cdegrees". valid input consists of the following characters:

+, -, N, n, S, s, E, e, W, w – direction indicators
any digit [0-9]
a decimal point, '.' – says decimal degrees follow an ascii delimiter, for example ' ', TAB, '/' to indicate that either minutes or seconds follow.

output is a double precision number, which will be either latitude or longitude degrees and decimal degree

written as part of the DIAL facility, G&G, WHOI April 1992 Christine L. Hammond

Definition at line 807 of file ossimDms.cpp.

References theAfterDot, theLatFlag, and theSign.

Referenced by ossimDms().

808 {
809  if (cdegrees.size() == 0) return 0.0;
810 
811  // We must make a non-const copy of "cdegrees".
812  char* copy = new char[cdegrees.size()+1];
813 
814  //---
815  // Since where going to play with the "copy" pointer we must keep the
816  // original pointer so we can delete it at the bottom.
817  //---
818  char* cptr = copy;
819 
820  strcpy(cptr, cdegrees.c_str());
821 
822  double degrees, factor, dividend, units;
823  int i;
824  bool afterdelim;
825  char c;
826 
827  theAfterDot = false;
828  afterdelim = false;
829  degrees = 0.0;
830  units = 0.0;
831  factor = 1.0;
832  dividend = 60.0;
833  theSign = 1;
834 
835  /* get rid of leading spaces */
836 
837  while (*cptr == ' ')
838  cptr++;
839 
840  while(*cptr != '\0')
841  {
842  switch (*cptr)
843  {
844 
845  /* north, west and + values will change sign of degrees to plus */
846  case '+':
847  case 'n':
848  case 'N':
849  case 'e':
850  case 'E':
851  {
852  if(toupper(*cptr) == 'N')
853  {
854  theLatFlag = true;
855  }
856  else if(toupper(*cptr) == 'E')
857  {
858  theLatFlag = false;
859  }
860  theSign = 1;
861  cptr++;
862  break;
863  }
864 
865  /* south, east and - values will change sign of degrees to minus */
866 
867  case '-':
868  case 's':
869  case 'S':
870  case 'w':
871  case 'W':
872  {
873  if(toupper(*cptr) == 'S')
874  {
875  theLatFlag = true;
876  }
877  else if(toupper(*cptr) == 'W')
878  {
879  theLatFlag = false;
880  }
881  theSign = -1;
882  cptr++;
883  break;
884  }
885 
886  case '0':
887  case '1':
888  case '2':
889  case '3':
890  case '4':
891  case '5':
892  case '6':
893  case '7':
894  case '8':
895  case '9':
896  {
897  c = *cptr;
898  i = (c - '0');
899 
900  if (afterdelim == true) {
901 
902  if (theAfterDot == true)
903  units = units + (((double)i * factor) / dividend);
904  else
905  units = (units * factor) + ((double)i / dividend);
906  }
907  else {
908 
909  if (theAfterDot == true)
910  degrees = degrees + ((double)i * factor);
911  else
912  degrees = (degrees * factor) + (double)i;
913  }
914 
915  if (theAfterDot == true)
916  factor = factor * .10;
917  else
918  factor = 10.;
919 
920  cptr++;
921  break;
922  }
923 
924  /* a decimal point indicates a change in the factor used */
925  /* to calculate degrees or units (minutes or seconds) */
926 
927  case '.':
928  {
929  factor = .10;
930  theAfterDot = true;
931  cptr++;
932  break;
933  }
934 
935  /* after a delimiter the value contains minutes, first time through */
936 
937  case ' ':
938  {
939 
940  while (*(cptr + 1) == ' ')
941  cptr++;
942 
943  degrees = degrees + units;
944  units = 0.0;
945 
946  if (afterdelim == true) /* must be seconds */
947  dividend = dividend * dividend;
948  else
949  afterdelim = true;
950 
951  factor = 1.;
952 
953  cptr++;
954 
955  /* skip any leading zeroes after delimiter */
956 
957  while (*cptr == '0')
958  cptr++;
959 
960  break;
961  }
962 
963  /* check for a delimiter that is allowable:
964  isspace allows: space, tab, cr, nl, vt, ff
965  ispunct allows: punctuation char != space or control or letter */
966 
967  default:
968  {
969  if (isspace(*cptr) || ispunct(*cptr))
970  *cptr = ' ';
971  }
972 
973  } /* end switch */
974 
975  } /* end while loop */
976 
977  /* add any units that may have been calculated (minutes or seconds) */
978 
979  degrees = degrees + units;
980 
981  //---
982  // NOTE: local variable "cptr" has been moved so do not delete "cptr"
983  // delete "copy" which points to the original allocated memory...
984  //---
985  delete [] copy;
986  copy = 0;
987 
988  return(degrees * (double)theSign);
989 }
bool theAfterDot
Definition: ossimDms.h:103
bool theLatFlag
Definition: ossimDms.h:97
int theSign
Definition: ossimDms.h:106

◆ toString()

ossimString ossimDms::toString ( const ossimString formatString = ossimString("")) const

You can specify a number of different formats.

special characters:

@    is replaced with a degree character.
'    minutes character
"    seconds character
d    replaced with degree portion
m    replaced with minute portion
s    replaced with second portion
c or C replaces with N/S or E/W

examples for format string

Definition at line 294 of file ossimDms.cpp.

References abs, ossimString::begin(), calc_mins_or_secs(), DEFAULT_FORMAT, ossimString::end(), init_values(), ossimString::length(), theAfterDot, theDecDegs, theDegrees, theDegreeSign, theDoingSeconds, theIntDegs, theLatFlag, theWorking, and ossimString::toString().

Referenced by ossimMapCompositionSource::addMeterGridLabels(), ossimNitfCommon::encodeGeographicDms(), and ossimGpt::toDmsString().

295 {
296  ossimString result="";
297  std::string::const_iterator stringIter;
298  ossimString tempFormatString = formatString;
299  if(formatString == ossimString(""))
300  {
301  tempFormatString = ossimDms::DEFAULT_FORMAT;
302  }
303 
304  stringIter = tempFormatString.begin();
305  int i, d_s;
306 
307 /* assign a default format if none is given */
308 
310 
311  while(stringIter != tempFormatString.end())
312  {
313  switch(*stringIter)
314  {
315  case '-':
316  {
317  result +=(theWorking < 0.0) ? ('-') : (' ');
318  stringIter++;
319  break;
320  }
321 
322  case 'c':
323  case 'C':
324  {
325  char temp;
326  if (theWorking < 0.0)
327  {
328  temp = (theLatFlag == true) ? ('S') : ('W');
329  }
330  else
331  {
332  temp= (theLatFlag == true) ? ('N') : ('E');
333  }
334 
335  if(*stringIter == 'c')
336  {
337  temp = tolower(temp);
338  }
339  result += temp;
340  stringIter++;
341  break;
342  }
343 
344  case 'd':
345  case 'D':
346  { /* how many 'd's until not 'd' */
347  d_s = 1;
348  ++stringIter;
349  while (*stringIter == 'd' || *stringIter == 'D')
350  {
351  ++d_s;
352  ++stringIter;
353  }
354  if (theAfterDot == true)
355  { /* beyond the decimal point */
356  double fractionalDegrees = std::abs(theDegrees-(int)theDegrees);
357  i = d_s;
358  while (i > 0)
359  {
360  fractionalDegrees = fractionalDegrees * 10.0;
361  result += ossimString::toString((int)fractionalDegrees);
362  fractionalDegrees = fractionalDegrees - (int)fractionalDegrees;
363  --i;
364  }
365  theIntDegs = (int)(theDecDegs);
366  }
367  else
368  {
369  theIntDegs = static_cast<int>( std::abs(theDegrees) );
371  ossimString prefix;
372  d_s -= (int)temp.length();
373  while(d_s > 0)
374  {
375  prefix += '0';
376  --d_s;
377  }
378  temp = prefix + temp;
379  result += temp;
380  }
381 // // fill the rest with blanks
382 // ossimString temp = ossimString::toString(theIntDegs);
383 // d_s -= temp.length();
384 // if(d_s>0)
385 // {
386 // if(theAfterDot)
387 // {
388 
389 // while(d_s > 0)
390 // {
391 // temp+='0';
392 // --d_s;
393 // }
394 // }
395 // else
396 // {
397 // ossimString prefix;
398 // while(d_s > 0)
399 // {
400 // prefix += '0';
401 // --d_s;
402 // }
403 // temp = prefix + temp;
404 // }
405 // }
406 
407  break;
408  }
409 
410  case ' ':
411  {
412  result += *stringIter;
413 
414  while (*stringIter == ' ')
415  {
416  result += *stringIter;
417  stringIter++;
418  }
419  break;
420  }
421 
422  case '.':
423  {
424  theAfterDot = true;
425  result += *stringIter++;
426  break;
427  }
428 
429  case 'm':
430  case 'M':
431  case 's':
432  case 'S':
433  {
434  if((*stringIter == 's') ||
435  (*stringIter == 'S'))
436  {
437  theDoingSeconds = true;
438  }
439 
440  calc_mins_or_secs(&theDecDegs, stringIter, result);
441  break;
442  }
443 
444  // This is code that I added so you can do additional
445  // formatting.
446  //
447  case '\'':
448  case '"':
449  {
450  result += *stringIter++;
451  break;
452  }
453  case '@':
454  {
455  result += (char)theDegreeSign;
456  stringIter++;
457  break;
458  }
459  default:
460  {
461  if(theDoingSeconds)
462  {
463  theAfterDot = true;
464  }
465  result += *stringIter++;
466  }
467  } /* end switch statement */
468  } /* end while loop */
469 
470  return result;
471 }
int theIntDegs
Definition: ossimDms.h:105
bool theAfterDot
Definition: ossimDms.h:103
double theDegrees
Definition: ossimDms.h:96
static ossimString toString(bool aValue)
Numeric to string methods.
void calc_mins_or_secs(double *dd, std::string::const_iterator &formatIter, std::string &result) const
Definition: ossimDms.cpp:615
#define abs(a)
Definition: auxiliary.h:74
std::string::iterator end()
Definition: ossimString.h:423
void init_values(double d) const
function init_values initializes the global values used throughout the function.
Definition: ossimDms.cpp:763
static const char * DEFAULT_FORMAT
Definition: ossimDms.h:93
std::string::size_type length() const
Definition: ossimString.h:408
std::string::iterator begin()
Definition: ossimString.h:420
double theWorking
Definition: ossimDms.h:107
bool theLatFlag
Definition: ossimDms.h:97
double theDecDegs
Definition: ossimDms.h:102
static const ossim_uint8 theDegreeSign
Definition: ossimDms.h:90
bool theDoingSeconds
Definition: ossimDms.h:104

Member Data Documentation

◆ DEFAULT_FORMAT

const char * ossimDms::DEFAULT_FORMAT = "ddd mm.mmC"
staticprivate

Definition at line 93 of file ossimDms.h.

Referenced by set_default(), and toString().

◆ SPACES

const char * ossimDms::SPACES = " "
staticprivate

Definition at line 94 of file ossimDms.h.

Referenced by set_default().

◆ theAfterDot

bool ossimDms::theAfterDot
mutableprivate

◆ theDecDegs

double ossimDms::theDecDegs
mutableprivate

Definition at line 102 of file ossimDms.h.

Referenced by degree_to_string(), init_values(), and toString().

◆ theDegrees

double ossimDms::theDegrees
private

Definition at line 96 of file ossimDms.h.

Referenced by ossimDms(), setDegrees(), and toString().

◆ theDegreeSign

const ossim_uint8 ossimDms::theDegreeSign = 176
static

Definition at line 90 of file ossimDms.h.

Referenced by degree_to_string(), setDegrees(), and toString().

◆ theDoingSeconds

bool ossimDms::theDoingSeconds
mutableprivate

Definition at line 104 of file ossimDms.h.

Referenced by init_values(), and toString().

◆ theIntDegs

int ossimDms::theIntDegs
mutableprivate

Definition at line 105 of file ossimDms.h.

Referenced by degree_to_string(), init_values(), and toString().

◆ theLatFlag

bool ossimDms::theLatFlag
private

Definition at line 97 of file ossimDms.h.

Referenced by setDegrees(), string_to_degree(), and toString().

◆ theSign

int ossimDms::theSign
mutableprivate

Definition at line 106 of file ossimDms.h.

Referenced by init_values(), setDegrees(), and string_to_degree().

◆ theWorking

double ossimDms::theWorking
mutableprivate

Definition at line 107 of file ossimDms.h.

Referenced by degree_to_string(), init_values(), and toString().


The documentation for this class was generated from the following files: