1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
|
// Classification : UNCLASSIFIED
/******************************************************************************
* Filename : testCoordinateConversionSample.h
*
* Copyright 2007 BAE Systems National Security Solutions Inc. 1989-2006
* ALL RIGHTS RESERVED
*
* MODIFICATION HISTORY:
*
* DATE NAME DR# DESCRIPTION
*
* 05/12/10 S Gillis BAEts26542 MSP TS MSL-HAE conversion
* should use CCS
* 06/11/10 S. Gillis BAEts26724 Fixed memory error problem
* when MSPCCS_DATA is not set
* 08/26/11 K Ou BAEts27716 Improved CCS sample code
*
******************************************************************************/
#include <iostream>
#include <string>
#include "CoordinateConversionService.h"
#include "CoordinateSystemParameters.h"
#include "GeodeticParameters.h"
#include "CoordinateTuple.h"
#include "GeodeticCoordinates.h"
#include "CartesianCoordinates.h"
#include "Accuracy.h"
#include "MGRSorUSNGCoordinates.h"
#include "UTMParameters.h"
#include "UTMCoordinates.h"
#include "CoordinateType.h"
#include "HeightType.h"
#include "CoordinateConversionException.h"
/**
* Sample code to demontrate how to use the MSP Coordinate Conversion Service.
*
* Includes the following conversions:
*
* |=============================|=============================|
* | Source | Target |
* |=============================+=============================|
* | Geodetic (Ellipsoid Height) | Geocentric |
* | Geocentric | Geodetic (Ellipsoid Height) |
* |-----------------------------+-----------------------------|
* | Geocentric | Geodetic (MSL EGM 96 15M) |
* |-----------------------------+-----------------------------|
* | Geodetic (Ellipsoid Height) | Geodetic (MSL EGM 96 15M) |
* | Geodetic (MSL EGM 96 15M) | Geodetic (Ellipsoid Height) |
* |-----------------------------+-----------------------------|
* | Geocentric | UTM |
* |-----------------------------+-----------------------------|
* | Geocentric | MGRS |
* |-----------------------------+-----------------------------|
*
**/
/**
* Function which uses the given Geodetic (Ellipsoid Height) to Geocentric
* Coordinate Conversion Service, 'ccsGeodeticEllipsoidToGeocentric', to
* convert the given lat, lon, and height to x, y, z coordinates.
**/
void convertGeodeticEllipsoidToGeocentric(
MSP::CCS::CoordinateConversionService& ccsGeodeticEllipsoidToGeocentric,
double lat,
double lon,
double height,
double& x,
double& y,
double& z)
{
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::GeodeticCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geodetic, lon, lat, height);
MSP::CCS::CartesianCoordinates targetCoordinates(
MSP::CCS::CoordinateType::geocentric);
ccsGeodeticEllipsoidToGeocentric.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy);
x = targetCoordinates.x();
y = targetCoordinates.y();
z = targetCoordinates.z();
}
/**
* Function which uses the given Geodetic (Ellipsoid Height) to Geocentric
* Coordinate Conversion Service, 'ccsGeodeticEllipsoidToGeocentric', to
* convert the given x, y, z coordinates to a lat, lon, and height.
**/
void convertGeocentricToGeodeticEllipsoid(
MSP::CCS::CoordinateConversionService& ccsGeodeticEllipsoidToGeocentric,
double x,
double y,
double z,
double& lat,
double& lon,
double& height)
{
MSP::CCS::Accuracy geocentricAccuracy;
MSP::CCS::Accuracy geodeticAccuracy;
MSP::CCS::CartesianCoordinates geocentricCoordinates(
MSP::CCS::CoordinateType::geocentric, x, y, z);
MSP::CCS::GeodeticCoordinates geodeticCoordinates;
// Note that the Geodetic (Ellipsoid Height) to Geocentric Coordinate
// Conversion Service is used here in conjunction with the
// convertTargetToSource() method (as opposed to a Geocentric to
// Geodetic (Ellipsoid Height) Coordinate Conversion Service in
// conjunction with the convertSourceToTarget() method)
ccsGeodeticEllipsoidToGeocentric.convertTargetToSource(
&geocentricCoordinates,
&geocentricAccuracy,
geodeticCoordinates,
geodeticAccuracy);
lat = geodeticCoordinates.latitude();
lon = geodeticCoordinates.longitude();
height = geodeticCoordinates.height();
}
/**
* Function which uses the given Geocentric to Geodetic (MSL EGM 96 15M)
* Coordinate Conversion Service, 'ccsGeocentricToGeodeticMslEgm96', to
* convert the given x, y, z coordinates to a lat, lon, and height.
**/
void convertGeocentricToGeodeticMslEgm96(
MSP::CCS::CoordinateConversionService& ccsGeocentricToGeodeticMslEgm96,
double x,
double y,
double z,
double& lat,
double& lon,
double& height)
{
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::CartesianCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geocentric, x, y, z);
MSP::CCS::GeodeticCoordinates targetCoordinates(
MSP::CCS::CoordinateType::geodetic, lon, lat, height);
ccsGeocentricToGeodeticMslEgm96.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy );
lat = targetCoordinates.latitude();
lon = targetCoordinates.longitude();
height = targetCoordinates.height();
}
/**
* Function which uses the given Geodetic (MSL EGM 96 15M) to Geodetic
* (Ellipsoid Height) Coordinate Conversion Service,
* 'ccsMslEgm96ToEllipsoidHeight', to convert the given MSL height at the
* given lat, lon, to an Ellipsoid height.
**/
void convertMslEgm96ToEllipsoidHeight(
MSP::CCS::CoordinateConversionService& ccsMslEgm96ToEllipsoidHeight,
double lat,
double lon,
double mslHeight,
double& ellipsoidHeight)
{
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::GeodeticCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geodetic, lon, lat, mslHeight);
MSP::CCS::GeodeticCoordinates targetCoordinates;
ccsMslEgm96ToEllipsoidHeight.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy);
ellipsoidHeight = targetCoordinates.height();
}
/**
* Function which uses the given Geodetic (Ellipsoid Height) to Geodetic
* (MSL EGM 96 15M) Coordinate Conversion Service,
* 'ccsEllipsoidHeightToMslEgm96', to convert the given Ellipsoid height at
* the given lat, lon, to an MSL height.
**/
void convertEllipsoidHeightToMslEgm96(
MSP::CCS::CoordinateConversionService& ccsEllipsoidHeightToMslEgm96,
double lat,
double lon,
double ellipsoidHeight,
double& mslHeight)
{
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::GeodeticCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geodetic, lon, lat, ellipsoidHeight);
MSP::CCS::GeodeticCoordinates targetCoordinates;
ccsEllipsoidHeightToMslEgm96.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy);
mslHeight = targetCoordinates.height();
}
/**
* Function which uses the given Geocentric to UTM Coordinate Conversion
* Service, 'ccsGeocentricToUtm', to convert the given x, y, z coordinates
* a UTM zone, hemisphere, Easting and Northing.
**/
void convertGeocentricToUtm(
MSP::CCS::CoordinateConversionService& ccsGeocentricToUtm,
double x,
double y,
double z,
long& zone,
char& hemisphere,
double& easting,
double& northing)
{
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::CartesianCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geocentric, x, y, z);
MSP::CCS::UTMCoordinates targetCoordinates;
ccsGeocentricToUtm.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy);
zone = targetCoordinates.zone();
hemisphere = targetCoordinates.hemisphere();
easting = targetCoordinates.easting();
northing = targetCoordinates.northing();
}
/**
* Function which uses the given Geocentric to MGRS Coordinate Conversion
* Service, 'ccsGeocentricToMgrs', to convert the given x, y, z coordinates
* to an MGRS string and precision.
**/
std::string convertGeocentricToMgrs(
MSP::CCS::CoordinateConversionService& ccsGeocentricToMgrs,
double x,
double y,
double z,
MSP::CCS::Precision::Enum& precision)
{
char* p;
std::string mgrsString;
MSP::CCS::Accuracy sourceAccuracy;
MSP::CCS::Accuracy targetAccuracy;
MSP::CCS::CartesianCoordinates sourceCoordinates(
MSP::CCS::CoordinateType::geocentric, x, y, z);
MSP::CCS::MGRSorUSNGCoordinates targetCoordinates;
ccsGeocentricToMgrs.convertSourceToTarget(
&sourceCoordinates,
&sourceAccuracy,
targetCoordinates,
targetAccuracy );
// Returned value, 'p', points to targetCoordinate's internal character
// array so assign/copy the character array to mgrsString to avoid
// introducing memory management issues
p = targetCoordinates.MGRSString();
mgrsString = p;
precision = targetCoordinates.precision();
return mgrsString;
}
/******************************************************************************
* Main function
******************************************************************************/
int main(int argc, char **argv)
{
const char* WGE = "WGE";
// initialize status value to one, indicating an error condition
int status = 1;
std::cout << "Coordinate Conversion Service Sample Test Driver" << std::endl;
std::cout << std::endl;
//
// Coordinate System Parameters
//
MSP::CCS::GeodeticParameters ellipsoidParameters(
MSP::CCS::CoordinateType::geodetic,
MSP::CCS::HeightType::ellipsoidHeight);
MSP::CCS::CoordinateSystemParameters geocentricParameters(
MSP::CCS::CoordinateType::geocentric);
MSP::CCS::GeodeticParameters mslEgm96Parameters(
MSP::CCS::CoordinateType::geodetic,
MSP::CCS::HeightType::EGM96FifteenMinBilinear);
MSP::CCS::UTMParameters utmParameters(
MSP::CCS::CoordinateType::universalTransverseMercator,
1,
0);
MSP::CCS::CoordinateSystemParameters mgrsParameters(
MSP::CCS::CoordinateType::militaryGridReferenceSystem);
//
// Coordinate Conversion Services
//
MSP::CCS::CoordinateConversionService ccsGeodeticEllipsoidToGeocentric(
WGE, &ellipsoidParameters,
WGE, &geocentricParameters);
MSP::CCS::CoordinateConversionService ccsGeocentricToGeodeticMslEgm96(
WGE, &geocentricParameters,
WGE, &mslEgm96Parameters);
MSP::CCS::CoordinateConversionService ccsMslEgm96ToEllipsoidHeight(
WGE, &mslEgm96Parameters,
WGE, &ellipsoidParameters);
MSP::CCS::CoordinateConversionService ccsEllipsoidHeightToMslEgm96(
WGE, &ellipsoidParameters,
WGE, &mslEgm96Parameters);
MSP::CCS::CoordinateConversionService ccsGeocentricToUtm(
WGE, &geocentricParameters,
WGE, &utmParameters);
MSP::CCS::CoordinateConversionService ccsGeocentricToMgrs(
WGE, &geocentricParameters,
WGE, &mgrsParameters);
try {
//
// Geodetic (Ellipsoid Height) to Geocentric
//
double lat = 0.56932;
double lon = -2.04552;
double height = 0.0;
double x, y, z;
convertGeodeticEllipsoidToGeocentric(
ccsGeodeticEllipsoidToGeocentric,
lat, lon, height,
x, y, z);
std::cout << "Convert Geodetic (Ellipsoid Height) to Geocentric" << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "Height(m): " << height << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl;
//
// Geocentric to Geodetic (Ellipsoid Height)
//
// function convertGeocentricToGeodeticEllipsoid() reuses the
// ccsGeodeticEllipsoidToGeocentric instance to perform the reverse
// conversion
convertGeocentricToGeodeticEllipsoid(
ccsGeodeticEllipsoidToGeocentric,
x, y, z,
lat, lon, height);
std::cout << "Revert Geocentric To Geodetic (Ellipsoid Height): " << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "Height(m): " << height << std::endl
<< std::endl;
// reuse ccsGeodeticEllipsoidToGeocentric instance to perform another
// Geodetic (Ellipsoid Height) to Geocentric conversions
lat = 0.76388;
lon = 0.60566;
height = 11.0;
convertGeodeticEllipsoidToGeocentric(
ccsGeodeticEllipsoidToGeocentric,
lat, lon, height,
x, y, z);
std::cout << "Convert Geodetic (Ellipsoid Height) to Geocentric" << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "Height(m): " << height << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl;
// reuse ccsGeodeticEllipsoidToGeocentric instance to perform another
// Geodetic (Ellipsoid Height) to Geocentric conversions
lat = 0.71458;
lon = 0.88791;
height = 22.0;
convertGeodeticEllipsoidToGeocentric(
ccsGeodeticEllipsoidToGeocentric,
lat, lon, height,
x, y, z);
std::cout << "Convert Geodetic (Ellipsoid Height) to Geocentric" << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "Height(m): " << height << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl;
//
// Geocentric to Geodetic (MSL EGM96 15M)
//
x = 3851747;
y = 3719589;
z = 3454013;
double mslHeight;
convertGeocentricToGeodeticMslEgm96(
ccsGeocentricToGeodeticMslEgm96,
x, y, z,
lat, lon, mslHeight);
std::cout << "Convert Geocentric To Geodetic MSL EGM96: " << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "MSL EGM96 15M Height: " << mslHeight << std::endl
<< std::endl;
//
// Geodetic (MSL EGM96 15M) to Geodetic (Ellipsoid Height)
//
convertMslEgm96ToEllipsoidHeight(
ccsMslEgm96ToEllipsoidHeight,
lat, lon, mslHeight,
height);
std::cout << "Convert Geodetic (MSL EMG96 15M Height) To Geodetic (Ellipsoid Height)" << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "MSL EGM96 15M Height: " << mslHeight << std::endl
<< std::endl
<< "Ellipsoid Height: " << height << std::endl
<< std::endl;
//
// Geodetic (Ellipsoid Height) to Geodetic (MSL EMG96 15M)
//
convertEllipsoidHeightToMslEgm96(
ccsEllipsoidHeightToMslEgm96,
lat, lon, height,
mslHeight);
std::cout << "Revert Geodetic (Ellipsoid Height) To Geodetic (MSL EGM96 15M) Height" << std::endl
<< std::endl
<< "Lat (radians): " << lat << std::endl
<< "Lon (radians): " << lon << std::endl
<< "Height(m): " << height << std::endl
<< std::endl
<< "MSL EGM96 15M Height: " << mslHeight << std::endl
<< std::endl;
//
// Geocentric to UTM
//
long zone;
char hemi;
double easting, northing;
convertGeocentricToUtm(
ccsGeocentricToUtm,
x, y, z,
zone, hemi, easting, northing);
std::cout << "Convert Geocentric To UTM: " << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl
<< "Zone: " << zone << std::endl
<< "Hemisphere: " << hemi << std::endl
<< "Easting: " << easting << std::endl
<< "Northing: " << northing<< std::endl
<< std::endl;
//
// Geocentric to MGRS
//
std::string mgrsString;
MSP::CCS::Precision::Enum precision;
mgrsString = convertGeocentricToMgrs(
ccsGeocentricToMgrs,
x, y, z,
precision);
std::cout << "Convert Geocentric To MGRS: " << std::endl
<< std::endl
<< "x: " << x << std::endl
<< "y: " << y << std::endl
<< "z: " << z << std::endl
<< std::endl
<< "MGRS: " << mgrsString << std::endl
<< "Precision: " << precision << std::endl
<< std::endl;
// set status value to zero to indicate successful completion
status = 0;
} catch(MSP::CCS::CoordinateConversionException& e) {
// catch and report any exceptions thrown by the Coordinate
// Conversion Service
std::cerr
<< "ERROR: Coordinate Conversion Service exception encountered - "
<< e.getMessage()
<< std::endl;
} catch(std::exception& e) {
// catch and report any unexpected exceptions thrown
std::cerr << "ERROR: Unexpected exception encountered - "
<< e.what() << std::endl;
}
return status;
}
// Classification : UNCLASSIFIED
|