115 using namespace MSP::CCS;
 
  121 const double PI = 3.14159265358979323e0;              
 
  144 static const char* 
Airy = 
"AA";
 
  149 void findIndex( 
char letter, 
const char* letterArray, 
long *index )
 
  163   long length = strlen(letterArray);
 
  165   while ((i < length) && (not_Found))
 
  167     if (letter == letterArray[i])
 
  184   double fraction = modf (value, &ivalue);
 
  185   ival = (long)(ivalue);
 
  186   if ((fraction > 0.5) || ((fraction == 0.5) && (ival%2 == 1)))
 
  193 void makeBNGString( 
char ltrnum[4], 
long easting, 
long northing, 
char* BNGString, 
long precision )
 
  205   for (j = 0; j < 3; j++)
 
  206     BNGString[i++] = ltrnum[j];
 
  207   divisor = pow (10.0, (5.0 - precision));
 
  208   unitInterval = pow (10.0, (
double)precision);
 
  211   if (east == unitInterval)
 
  213   if ((precision == 0) && (east == 1))
 
  215   i += sprintf (BNGString + i, 
"%*.*ld", precision, precision, east);
 
  217   north = 
roundBNG (northing/divisor);
 
  218   if (north == unitInterval)
 
  220   if ((precision == 0) && (north == 1))
 
  222   i += sprintf (BNGString + i, 
"%*.*ld",  precision, precision, north);
 
  238   bool outOfArea = 
false;
 
  334 void breakBNGString( 
char* BNGString, 
char letters[3], 
double* easting, 
double* northing, 
long* precision )
 
  342   long length = strlen(BNGString);
 
  344   while (BNGString[i] == 
' ')
 
  347   while (isalpha(BNGString[i]))
 
  350   if (num_letters == 2)
 
  353     letters[0] = (char)toupper(BNGString[j]);
 
  354     letters[1] = (char)toupper(BNGString[j+1]);
 
  361   while (BNGString[i] == 
' ')
 
  364   if (BNGString[length-1] == 
' ')
 
  368     if (isdigit(BNGString[i]))
 
  375   if ((num_digits <= 10) && (num_digits%2 == 0))
 
  379     char north_string[6];
 
  389       strncpy (east_string, BNGString+j, n);
 
  391       sscanf (east_string, 
"%ld", &east);
 
  392       strncpy (north_string, BNGString+j+n, n);
 
  394       sscanf (north_string, 
"%ld", &north);
 
  395       multiplier = pow (10.0, 5.0 - n);
 
  396       *easting = east * multiplier;
 
  397       *northing = north * multiplier;
 
  417   transverseMercator( 0 ),
 
  429   strcpy( BNG_Letters, 
"SV" );
 
  430   strcpy( BNG_Ellipsoid_Code, 
"AA");
 
  432   if ( strcmp( ellipsoidCode, 
Airy ) != 0 )
 
  437   strcpy( BNG_Ellipsoid_Code, ellipsoidCode );
 
  449   BNG_Easting = bng.BNG_Easting;     
 
  450   BNG_Northing = bng.BNG_Northing; 
 
  456   delete transverseMercator;
 
  457   transverseMercator = 0;
 
  465     transverseMercator->operator=( *bng.transverseMercator );
 
  468     BNG_Easting = bng.BNG_Easting;     
 
  469     BNG_Northing = bng.BNG_Northing; 
 
  504   double TMEasting, TMNorthing;
 
  506   double longitude = geodeticCoordinates->
longitude();
 
  507   double latitude  = geodeticCoordinates->
latitude();
 
  521   TMEasting  = transverseMercatorCoordinates->
easting();
 
  522   TMNorthing = transverseMercatorCoordinates->
northing();
 
  524   if ((TMEasting < 0.0) && (TMEasting > -2.0))
 
  525     transverseMercatorCoordinates->
setEasting( 0.0 );
 
  526   if ((TMNorthing < 0.0) && (TMNorthing > -2.0))
 
  529   TMEasting  = transverseMercatorCoordinates->
easting();
 
  530   TMNorthing = transverseMercatorCoordinates->
northing();
 
  534     delete transverseMercatorCoordinates;
 
  539     delete transverseMercatorCoordinates;
 
  546     delete transverseMercatorCoordinates;
 
  549     delete transverseMercatorCoordinates;
 
  553   return bngCoordinates;
 
  571   double TMEasting, TMNorthing;
 
  574   char* BNGString = bngCoordinates->
BNGString();
 
  576   breakBNGString( BNGString, BNG_Letters, &BNG_Easting, &BNG_Northing, &in_Precision );
 
  579   TMEasting = transverseMercatorCoordinates->
easting();
 
  580   TMNorthing = transverseMercatorCoordinates->
northing();
 
  584     delete transverseMercatorCoordinates;
 
  589     delete transverseMercatorCoordinates;
 
  597     geodeticCoordinates = transverseMercator->
convertToGeodetic( transverseMercatorCoordinates );
 
  598     latitude = geodeticCoordinates->
latitude();
 
  599     longitude = geodeticCoordinates->
longitude();
 
  600     delete transverseMercatorCoordinates;
 
  603     delete transverseMercatorCoordinates;
 
  609     delete geodeticCoordinates;
 
  614     delete geodeticCoordinates;
 
  618   return geodeticCoordinates;
 
  639   long temp_Easting, temp_Northing;
 
  642   double easting = mapProjectionCoordinates->
easting();
 
  643   double northing = mapProjectionCoordinates->
northing();
 
  657   temp_Easting  += 1000000; 
 
  658   temp_Northing += 500000;
 
  660   x = temp_Easting / 500000;
 
  661   y = temp_Northing / 500000;
 
  664   if ((index >= 0) && (index < 25))
 
  667     temp_Easting %= 500000;
 
  668     temp_Northing %= 500000;
 
  669     x = temp_Easting / 100000;
 
  670     y = temp_Northing / 100000;
 
  672     if ((index >= 0) && (index < 25))
 
  683       temp_Easting %= 100000;
 
  684       temp_Northing %= 100000;
 
  685       makeBNGString(letters, temp_Easting, temp_Northing, BNGString, precision);
 
  690       if ((x >= (25 - five_y)) || (x < -five_y))
 
  692       if ((five_y >= (25 - x)) || (five_y < -x))
 
  701     if ((x >= (25 - five_y)) || (x < -five_y))
 
  703     if ((five_y >= (25 - x)) || (five_y < -x))
 
  727   long northing_Offset, easting_Offset;
 
  732   char* BNGString = bngCoordinates->
BNGString();
 
  734   breakBNGString( BNGString, BNG_Letters, &BNG_Easting, &BNG_Northing, &in_Precision );
 
  738   northing_Offset = 500000 * (i / 2);
 
  739   easting_Offset = 500000 * (i % 2);
 
  743   northing_Offset += 100000 * (j / 5);
 
  744   easting_Offset += 100000 * (j % 5);
 
  746   double easting = BNG_Easting + easting_Offset;
 
  747   double northing = BNG_Northing + northing_Offset;