20 #define BNG_NO_ERROR 0x0000 21 #define BNG_LAT_ERROR 0x0001 22 #define BNG_LON_ERROR 0x0002 23 #define BNG_EASTING_ERROR 0x0004 24 #define BNG_NORTHING_ERROR 0x0008 25 #define BNG_INVALID_AREA_ERROR 0x0010 26 #define BNG_STRING_ERROR 0x0020 27 #define BNG_ELLIPSOID_ERROR 0x0040 29 #define PI_OVER_2 (M_PI / 2.0e0) 30 #define MAX_LAT (61.5 * M_PI / 180.0) 31 #define MIN_LAT (49.5 * M_PI / 180.0) 32 #define MAX_LON (3.5 * M_PI / 180.0) 33 #define MIN_LON (-10.0 * M_PI / 180.0) 34 #define BNG500GRID "STNOHJ" 35 #define BNG100GRID "VWXYZQRSTULMNOPFGHJKABCDE" 36 static double BNG_Max_Easting = 759961.0;
37 static double BNG_Max_Northing = 1257875.0;
38 static double BNG_Min_Easting = -133134.0;
39 static double BNG_Min_Northing = -14829.0;
41 static char BNG_Letters[3] =
"SV";
42 static double BNG_Easting = 0.0;
43 static double BNG_Northing = 0.0;
44 static const char* Airy =
"AA";
45 static char BNG_Ellipsoid_Code[3] =
"AA";
116 BNG_f = 1 / 299.324964600;
140 const char* prefix)
const 172 const char* letter_Array,
190 while ((i < length) && (not_Found))
192 if (letter == letter_Array[i])
210 double fraction = modf (value, &ivalue);
211 ival = (long)(ivalue);
212 if ((fraction > 0.5) || ((fraction == 0.5) && (ival%2 == 1)))
235 for (j = 0; j < 3; j++)
237 BNG[i++] = ltrnum[j];
240 divisor = pow ((
double)10.0,(
double) (5 - Precision));
241 unitInterval = pow ((
double)10.0, (
double)Precision);
243 if (east == unitInterval)
245 if ((Precision == 0) && (east == 1))
247 i += sprintf (BNG + i,
"%*.*ld",(
int) Precision,(
int) Precision, east);
250 if (north == unitInterval)
252 if ((Precision == 0) && (north == 1))
254 i += sprintf (BNG + i,
"%*.*ld",(
int) Precision,(
int) Precision, north);
263 long* Precision)
const 271 long length = (long)strlen(BNG);
275 while (BNG[i] ==
' ')
278 while (isalpha(BNG[i]))
281 if (num_letters == 2)
284 Letters[0] = (char)toupper(BNG[j]);
285 Letters[1] = (char)toupper(BNG[j+1]);
292 error_code |= Check_Out_Of_Area(Letters[0], Letters[1]);
293 while (BNG[i] ==
' ')
296 if (BNG[length-1] ==
' ')
298 while ((i < length) && (!temp_error))
308 error_code |= temp_error;
312 if ((num_digits <= 10) && (num_digits%2 == 0))
316 char north_string[6];
326 strncpy (east_string, BNG+j,
n);
328 sscanf (east_string,
"%ld", &east);
329 strncpy (north_string, BNG+j+
n,
n);
331 sscanf (north_string,
"%ld", &north);
332 multiplier = pow ((
double)10.0,(
double)( 5 -
n));
333 *Easting = east * multiplier;
334 *Northing = north * multiplier;
470 if (strcmp(Ellipsoid_Code, Airy) != 0)
477 strcpy(BNG_Ellipsoid_Code, Ellipsoid_Code);
497 strcpy(Ellipsoid_Code, BNG_Ellipsoid_Code);
520 double TMEasting, TMNorthing;
537 if ((TMEasting < 0.0) && (TMEasting > -2.0))
539 if ((TMNorthing < 0.0) && (TMNorthing > -2.0))
542 if ((TMEasting < BNG_Min_Easting) || (TMEasting > BNG_Max_Easting))
544 if ((TMNorthing < BNG_Min_Northing) || (TMNorthing > BNG_Max_Northing))
555 double *Longitude)
const 570 double TMEasting, TMNorthing;
575 Error_Code |=
Break_BNG_String(BNG, BNG_Letters, &BNG_Easting, &BNG_Northing, &in_Precision);
581 if ((TMEasting < BNG_Min_Easting) || (TMEasting > BNG_Max_Easting))
583 if ((TMNorthing < BNG_Min_Northing) || (TMNorthing > BNG_Max_Northing))
626 long temp_Easting, temp_Northing;
629 if ((Easting < BNG_Min_Easting) || (Easting > BNG_Max_Easting))
633 if ((Northing < BNG_Min_Northing) || (Northing > BNG_Max_Northing))
643 temp_Easting += 1000000;
644 temp_Northing += 500000;
646 x = temp_Easting / 500000;
647 y = temp_Northing / 500000;
650 if ((index >= 0) && (index < 25))
653 temp_Easting %= 500000;
654 temp_Northing %= 500000;
655 x = temp_Easting / 100000;
656 y = temp_Northing / 100000;
658 if ((index >= 0) && (index < 25))
666 temp_Easting %= 100000;
667 temp_Northing %= 100000;
674 if ((
x >= (25 - five_y)) || (
x < -five_y))
676 if ((five_y >= (25 -
x)) || (five_y < -
x))
683 if ((
x >= (25 - five_y)) || (
x < -five_y))
685 if ((five_y >= (25 -
x)) || (five_y < -
x))
695 double *Northing)
const 709 long northing_Offset, easting_Offset;
717 Error_Code |=
Break_BNG_String(BNG, BNG_Letters, &BNG_Easting, &BNG_Northing, &in_Precision);
724 northing_Offset = 500000 * (i / 2);
725 easting_Offset = 500000 * (i % 2);
730 northing_Offset += 100000 * (j / 5);
731 easting_Offset += 100000 * (j % 5);
733 *Easting = BNG_Easting + easting_Offset;
734 *Northing = BNG_Northing + northing_Offset;
virtual const ossimDatum * create(const ossimString &code) const
create method
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
long Round_BNG(double value) const
long Set_Transverse_Mercator_Parameters(double a, double f, double Origin_Latitude, double Central_Meridian, double False_Easting, double False_Northing, double Scale_Factor)
long Check_Out_Of_Area(char BNG500, char BNG100) const
long Convert_BNG_To_Transverse_Mercator(char *BNG, double *Easting, double *Northing) const
Represents serializable keyword/value map.
long Convert_Geodetic_To_BNG(double Latitude, double Longitude, long Precision, char *BNG) const
long Make_BNG_String(char ltrnum[4], long Easting, long Northing, char *BNG, long Precision) const
double nan()
Method to return ieee floating point double precision NAN.
This code was derived from https://gist.github.com/mshockwave.
#define BNG_INVALID_AREA_ERROR
virtual ossimString getClassName() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
static const char * TYPE_KW
#define BNG_ELLIPSOID_ERROR
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
#define BNG_EASTING_ERROR
os2<< "> n<< " > nendobj n
double lonr() const
Returns the longitude in radian measure.
unsigned int ossim_uint32
static ossimDatumFactory * instance()
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
long Set_BNG_Parameters(char *Ellipsoid_Code)
long Break_BNG_String(char *BNG, char Letters[3], double *Easting, double *Northing, long *Precision) const
#define BNG_NORTHING_ERROR
long Convert_BNG_To_Geodetic(char *BNG, double *Latitude, double *Longitude) const
#define TRANMERC_NORTHING_ERROR
void Get_BNG_Parameters(char *Ellipsoid_Code)
long Convert_Transverse_Mercator_To_BNG(double Easting, double Northing, long Precision, char *BNG) const
long Convert_Transverse_Mercator_To_Geodetic(double Easting, double Northing, double *Latitude, double *Longitude)
#define TRANMERC_EASTING_ERROR
long Find_Index(char letter, const char *letter_Array, long *index) const
virtual ossimDpt forward(const ossimGpt &latLon) const
All map projections will convert the world coordinate to an easting northing (Meters).
double latr() const
latr().
virtual ossimGpt inverse(const ossimDpt &eastingNorthing) const
Will take a point in meters and convert it to ground.
RTTI_DEF1(ossimBngProjection, "ossimBngProjection", ossimMapProjection)
static const char * SCALE_FACTOR_KW
ossimDpt theFalseEastingNorthing
Hold the false easting northing.
long Convert_Geodetic_To_Transverse_Mercator(double Latitude, double Longitude, double *Easting, double *Northing)
double BNG_False_Northing
const ossimDatum * theDatum
This is only set if we want to have built in datum shifting.