OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Macros | Functions
ossimGeoref.cpp File Reference
#include <ossim/base/ossimGeoref.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

Go to the source code of this file.

Macros

#define GEOREF_NO_ERROR   0x0000
 
#define GEOREF_LAT_ERROR   0x0001
 
#define GEOREF_LON_ERROR   0x0002
 
#define GEOREF_STR_ERROR   0x0004
 
#define GEOREF_STR_LAT_ERROR   0x0008
 
#define GEOREF_STR_LON_ERROR   0x0010
 
#define GEOREF_STR_LAT_MIN_ERROR   0x0020
 
#define GEOREF_STR_LON_MIN_ERROR   0x0040
 
#define GEOREF_PRECISION_ERROR   0x0080
 
#define TRUE   1
 
#define FALSE   0
 
#define LATITUDE_LOW   -90 /* Minimum latitude */
 
#define LATITUDE_HIGH   90 /* Maximum latitude */
 
#define LONGITUDE_LOW   -180 /* Minimum longitude */
 
#define LONGITUDE_HIGH   360 /* Maximum longitude */
 
#define MIN_PER_DEG   60 /* Number of minutes per degree */
 
#define GEOREF_MINIMUM   4 /* Minimum number of chars for GEOREF */
 
#define GEOREF_MAXIMUM   14 /* Maximum number of chars for GEOREF */
 
#define GEOREF_LETTERS   4 /* Number of letters in GEOREF string */
 
#define MAX_PRECISION   5 /* Maximum precision of minutes part */
 
#define LETTER_I   8 /* Index for letter I */
 
#define LETTER_M   12 /* Index for letter M */
 
#define LETTER_O   14 /* Index for letter O */
 
#define LETTER_Q   16 /* Index for letter Q */
 
#define LETTER_Z   25 /* Index for letter Z */
 
#define LETTER_A_OFFSET   65 /* Letter A offset in character set */
 
#define ZERO_OFFSET   48 /* Number zero offset in character set */
 
#define PI   3.14159265358979323e0 /* PI */
 
#define DEGREE_TO_RADIAN   (PI / 180.0)
 
#define RADIAN_TO_DEGREE   (180.0 / PI)
 
#define QUAD   15 /* Degrees per grid square */
 
#define ROUND_ERROR   0.0000005 /* Rounding factor */
 

Functions

long Extract_Degrees (char *georef, double *latitude, double *longitude)
 
long Extract_Minutes (char *georef, long start, long length, long ERROR_TYPE, double *minutes)
 
long Round_GEOREF (double value)
 
void Convert_Minutes_To_String (double minutes, long precision, char *str)
 

Macro Definition Documentation

◆ DEGREE_TO_RADIAN

#define DEGREE_TO_RADIAN   (PI / 180.0)

Definition at line 89 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

◆ FALSE

#define FALSE   0

Definition at line 71 of file ossimGeoref.cpp.

◆ GEOREF_LAT_ERROR

#define GEOREF_LAT_ERROR   0x0001

Definition at line 15 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ GEOREF_LETTERS

#define GEOREF_LETTERS   4 /* Number of letters in GEOREF string */

◆ GEOREF_LON_ERROR

#define GEOREF_LON_ERROR   0x0002

Definition at line 16 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ GEOREF_MAXIMUM

#define GEOREF_MAXIMUM   14 /* Maximum number of chars for GEOREF */

Definition at line 78 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic(), and Extract_Minutes().

◆ GEOREF_MINIMUM

#define GEOREF_MINIMUM   4 /* Minimum number of chars for GEOREF */

Definition at line 77 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

◆ GEOREF_NO_ERROR

#define GEOREF_NO_ERROR   0x0000

◆ GEOREF_PRECISION_ERROR

#define GEOREF_PRECISION_ERROR   0x0080

Definition at line 22 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ GEOREF_STR_ERROR

#define GEOREF_STR_ERROR   0x0004

Definition at line 17 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

◆ GEOREF_STR_LAT_ERROR

#define GEOREF_STR_LAT_ERROR   0x0008

Definition at line 18 of file ossimGeoref.cpp.

Referenced by Extract_Degrees().

◆ GEOREF_STR_LAT_MIN_ERROR

#define GEOREF_STR_LAT_MIN_ERROR   0x0020

Definition at line 20 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

◆ GEOREF_STR_LON_ERROR

#define GEOREF_STR_LON_ERROR   0x0010

Definition at line 19 of file ossimGeoref.cpp.

Referenced by Extract_Degrees().

◆ GEOREF_STR_LON_MIN_ERROR

#define GEOREF_STR_LON_MIN_ERROR   0x0040

Definition at line 21 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

◆ LATITUDE_HIGH

#define LATITUDE_HIGH   90 /* Maximum latitude */

Definition at line 73 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ LATITUDE_LOW

#define LATITUDE_LOW   -90 /* Minimum latitude */

◆ LETTER_A_OFFSET

#define LETTER_A_OFFSET   65 /* Letter A offset in character set */

Definition at line 86 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF(), and Extract_Degrees().

◆ LETTER_I

#define LETTER_I   8 /* Index for letter I */

Definition at line 81 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF(), and Extract_Degrees().

◆ LETTER_M

#define LETTER_M   12 /* Index for letter M */

Definition at line 82 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ LETTER_O

#define LETTER_O   14 /* Index for letter O */

Definition at line 83 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF(), and Extract_Degrees().

◆ LETTER_Q

#define LETTER_Q   16 /* Index for letter Q */

Definition at line 84 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ LETTER_Z

#define LETTER_Z   25 /* Index for letter Z */

Definition at line 85 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ LONGITUDE_HIGH

#define LONGITUDE_HIGH   360 /* Maximum longitude */

Definition at line 75 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ LONGITUDE_LOW

#define LONGITUDE_LOW   -180 /* Minimum longitude */

◆ MAX_PRECISION

#define MAX_PRECISION   5 /* Maximum precision of minutes part */

Definition at line 80 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ MIN_PER_DEG

#define MIN_PER_DEG   60 /* Number of minutes per degree */

◆ PI

#define PI   3.14159265358979323e0 /* PI */

◆ QUAD

#define QUAD   15 /* Degrees per grid square */

Definition at line 91 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF(), and Extract_Degrees().

◆ RADIAN_TO_DEGREE

#define RADIAN_TO_DEGREE   (180.0 / PI)

Definition at line 90 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ ROUND_ERROR

#define ROUND_ERROR   0.0000005 /* Rounding factor */

Definition at line 92 of file ossimGeoref.cpp.

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

◆ TRUE

#define TRUE   1

Definition at line 70 of file ossimGeoref.cpp.

◆ ZERO_OFFSET

#define ZERO_OFFSET   48 /* Number zero offset in character set */

Definition at line 87 of file ossimGeoref.cpp.

Function Documentation

◆ Convert_Minutes_To_String()

void Convert_Minutes_To_String ( double  minutes,
long  precision,
char *  str 
)

Definition at line 206 of file ossimGeoref.cpp.

References min, and Round_GEOREF().

Referenced by ossimGeoref::Convert_Geodetic_To_GEOREF().

209 { /* BEGIN Convert_Minutes_To_String */
210 /*
211  * This function converts minutes to a string of length precision.
212  *
213  * minutes : Minutes to be converted (input)
214  * precision : Length of resulting string (input)
215  * str : String to hold converted minutes (output)
216  */
217  double divisor;
218  long min;
219  divisor = pow ((double)10.0, (int)(5 - precision));
220  if (minutes == 60.0)
221  minutes = 59.999;
222  minutes = minutes * 1000;
223  min = Round_GEOREF (minutes/divisor);
224  sprintf (str, "%*.*ld", (int)precision, (int)precision, min);
225  if (precision == 1)
226  strcat (str, "0");
227 } /* END Convert_Minutes_To_String */
long Round_GEOREF(double value)
#define min(a, b)
Definition: auxiliary.h:75

◆ Extract_Degrees()

long Extract_Degrees ( char *  georef,
double *  latitude,
double *  longitude 
)

Definition at line 101 of file ossimGeoref.cpp.

References GEOREF_LETTERS, GEOREF_NO_ERROR, GEOREF_STR_LAT_ERROR, GEOREF_STR_LON_ERROR, LETTER_A_OFFSET, LETTER_I, LETTER_O, and QUAD.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

104 { /* BEGIN Extract_Degrees */
105 /*
106  * This function extracts the latitude and longitude degree parts of the
107  * GEOREF string. The latitude and longitude degree parts are the first four
108  * characters.
109  *
110  * georef : GEOREF string (input)
111  * latitude : Latitude in degrees (output)
112  * longitude : Longitude in degrees (output)
113  */
114  long i; /* counter in for loops */
115  long temp_char; /* temporary character */
116  long letter_number[GEOREF_LETTERS]; /* number corresponding to letter */
117  long error_code = GEOREF_NO_ERROR;
118 
119  for (i=0;i<GEOREF_LETTERS;i++)
120  {
121  temp_char = toupper(georef[i]);
122  temp_char = temp_char - LETTER_A_OFFSET;
123  if ((!isalpha(georef[i]))
124  || (temp_char == LETTER_I)
125  || (temp_char == LETTER_O))
126  {
127  if ((i == 0) || (i == 2))
128  error_code |= GEOREF_STR_LON_ERROR;
129  else
130  error_code |= GEOREF_STR_LAT_ERROR;
131  }
132  letter_number[i] = temp_char;
133  }
134  for (i=0;i<4;i++)
135  {
136  if (letter_number[i] > LETTER_O)
137  letter_number[i] -= 2;
138  else if (letter_number[i] > LETTER_I)
139  letter_number[i] -= 1;
140  }
141  if ((letter_number[0] > 23) || (letter_number[2] > 14))
142  error_code |= GEOREF_STR_LON_ERROR;
143  if ((letter_number[1] > 11) || (letter_number[3] > 14))
144  error_code |= GEOREF_STR_LAT_ERROR;
145  *latitude = (double)(letter_number[1]) * QUAD + (double)(letter_number[3]);
146  *longitude = (double)(letter_number[0]) * QUAD + (double)(letter_number[2]);
147  return (error_code);
148 } /* END Extract_Degrees */
#define LETTER_O
Definition: ossimGeoref.cpp:83
#define GEOREF_LETTERS
Definition: ossimGeoref.cpp:79
#define LETTER_I
Definition: ossimGeoref.cpp:81
#define LETTER_A_OFFSET
Definition: ossimGeoref.cpp:86
#define QUAD
Definition: ossimGeoref.cpp:91
#define GEOREF_STR_LAT_ERROR
Definition: ossimGeoref.cpp:18
#define GEOREF_STR_LON_ERROR
Definition: ossimGeoref.cpp:19
#define GEOREF_NO_ERROR
Definition: ossimGeoref.cpp:14

◆ Extract_Minutes()

long Extract_Minutes ( char *  georef,
long  start,
long  length,
long  ERROR_TYPE,
double *  minutes 
)

Definition at line 151 of file ossimGeoref.cpp.

References GEOREF_LETTERS, GEOREF_MAXIMUM, GEOREF_NO_ERROR, and MIN_PER_DEG.

Referenced by ossimGeoref::Convert_GEOREF_To_Geodetic().

156 { /* BEGIN Extract_Minutes */
157 /*
158  * This function extracts the minutes from the GEOREF string. The minutes
159  * part begins at position start and has length length. The ERROR_TYPE is
160  * to allow this function to work with both latitude and longitude minutes.
161  *
162  * georef : GEOREF string (input)
163  * start : Start position in the GEOREF string (input)
164  * length : length of minutes in the GEOREF string (input)
165  * ERROR_TYPE : has a value of either GEOREF_STR_LAT_MIN_ERROR (input)
166  * or GEOREF_STR_LON_MIN_ERROR
167  * minutes: minute part (output)
168  */
169  long i; /* counter in for loop */
170  long error_code = GEOREF_NO_ERROR;
171  char temp_str[(GEOREF_MAXIMUM-GEOREF_LETTERS)/2 + 1];
172 
173  for (i=0;i<length;i++)
174  {
175  if (isdigit(georef[start+i]))
176  temp_str[i] = georef[start+i];
177  else
178  error_code |= ERROR_TYPE;
179  }
180  temp_str[length] = 0;
181  *minutes = (double)atof(temp_str); /* need atof, atoi can't handle 59999 */
182  while (length > 2)
183  {
184  *minutes = *minutes / 10;
185  length = length - 1;
186  }
187  if (*minutes > (double)MIN_PER_DEG)
188  error_code |= ERROR_TYPE;
189  return (error_code);
190 } /* END OF Extract_Minutes */
#define GEOREF_LETTERS
Definition: ossimGeoref.cpp:79
#define MIN_PER_DEG
Definition: ossimGeoref.cpp:76
#define GEOREF_MAXIMUM
Definition: ossimGeoref.cpp:78
#define GEOREF_NO_ERROR
Definition: ossimGeoref.cpp:14

◆ Round_GEOREF()

long Round_GEOREF ( double  value)

Definition at line 193 of file ossimGeoref.cpp.

Referenced by Convert_Minutes_To_String().

195 { /* Round_GEOREF */
196  double ivalue;
197  long ival;
198  double fraction = modf (value, &ivalue);
199  ival = (long)(ivalue);
200  if ((fraction > 0.5) || ((fraction == 0.5) && (ival%2 == 1)))
201  ival++;
202  return (ival);
203 } /* Round_GEOREF */