00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #include <time.h>
00099 #include <stdio.h>
00100 #include "CoordinateConversionService.h"
00101 #include "CoordinateSystemParameters.h"
00102 #include "CoordinateTuple.h"
00103 #include "CoordinateType.h"
00104 #include "EllipsoidLibrary.h"
00105 #include "EllipsoidLibraryImplementation.h"
00106 #include "DatumLibrary.h"
00107 #include "DatumLibraryImplementation.h"
00108 #include "GeoidLibrary.h"
00109 #include "Accuracy.h"
00110 #include "EquidistantCylindricalParameters.h"
00111 #include "GeodeticParameters.h"
00112 #include "LocalCartesianParameters.h"
00113 #include "MercatorStandardParallelParameters.h"
00114 #include "MercatorScaleFactorParameters.h"
00115 #include "MapProjection3Parameters.h"
00116 #include "MapProjection4Parameters.h"
00117 #include "MapProjection5Parameters.h"
00118 #include "MapProjection6Parameters.h"
00119 #include "NeysParameters.h"
00120 #include "ObliqueMercatorParameters.h"
00121 #include "PolarStereographicStandardParallelParameters.h"
00122 #include "PolarStereographicScaleFactorParameters.h"
00123 #include "UTMParameters.h"
00124 #include "BNGCoordinates.h"
00125 #include "CartesianCoordinates.h"
00126 #include "GARSCoordinates.h"
00127 #include "GeodeticCoordinates.h"
00128 #include "GEOREFCoordinates.h"
00129 #include "MapProjectionCoordinates.h"
00130 #include "MGRSorUSNGCoordinates.h"
00131 #include "UPSCoordinates.h"
00132 #include "UTMCoordinates.h"
00133 #include "AlbersEqualAreaConic.h"
00134 #include "AzimuthalEquidistant.h"
00135 #include "Bonne.h"
00136 #include "BritishNationalGrid.h"
00137 #include "Cassini.h"
00138 #include "CylindricalEqualArea.h"
00139 #include "Eckert4.h"
00140 #include "Eckert6.h"
00141 #include "EquidistantCylindrical.h"
00142 #include "GARS.h"
00143 #include "Geocentric.h"
00144 #include "GEOREF.h"
00145 #include "Gnomonic.h"
00146 #include "LambertConformalConic.h"
00147 #include "LocalCartesian.h"
00148 #include "Mercator.h"
00149 #include "MGRS.h"
00150 #include "MillerCylindrical.h"
00151 #include "Mollweide.h"
00152 #include "Neys.h"
00153 #include "NZMG.h"
00154 #include "ObliqueMercator.h"
00155 #include "Orthographic.h"
00156 #include "PolarStereographic.h"
00157 #include "Polyconic.h"
00158 #include "Sinusoidal.h"
00159 #include "Stereographic.h"
00160 #include "TransverseCylindricalEqualArea.h"
00161 #include "TransverseMercator.h"
00162 #include "UPS.h"
00163 #include "USNG.h"
00164 #include "UTM.h"
00165 #include "VanDerGrinten.h"
00166 #include "CoordinateConversionException.h"
00167 #include "ErrorMessages.h"
00168 #include "WarningMessages.h"
00169 #include "CCSThreadMutex.h"
00170 #include "CCSThreadLock.h"
00171
00172 using namespace MSP::CCS;
00173 using MSP::CCSThreadMutex;
00174 using MSP::CCSThreadLock;
00175
00176
00177
00178
00179
00180
00181
00182 const double PI = 3.14159265358979323e0;
00183 CCSThreadMutex CoordinateConversionService::mutex;
00184
00185
00186
00187
00188 CoordinateConversionService::CCSData::CCSData() :
00189 refCount( 1 )
00190 {
00191 ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
00192 ellipsoidLibrary = new EllipsoidLibrary( ellipsoidLibraryImplementation );
00193 datumLibraryImplementation = DatumLibraryImplementation::getInstance();
00194 datumLibrary = new DatumLibrary( datumLibraryImplementation );
00195 geoidLibrary = GeoidLibrary::getInstance();
00196 }
00197
00198
00199 CoordinateConversionService::CCSData::~CCSData()
00200 {
00201 delete ellipsoidLibrary;
00202 ellipsoidLibrary = 0;
00203
00204 EllipsoidLibraryImplementation::removeInstance();
00205 ellipsoidLibraryImplementation = 0;
00206
00207 delete datumLibrary;
00208 datumLibrary = 0;
00209
00210 DatumLibraryImplementation::removeInstance();
00211 datumLibraryImplementation = 0;
00212
00213 GeoidLibrary::removeInstance();
00214 geoidLibrary = 0;
00215
00216 refCount = 0;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 CoordinateConversionService::CoordinateConversionService(
00226 const char* sourceDatumCode,
00227 MSP::CCS::CoordinateSystemParameters* sourceParameters,
00228 const char* targetDatumCode,
00229 MSP::CCS::CoordinateSystemParameters* targetParameters ) :
00230 WGS84_datum_index( 0 )
00231 {
00232
00233 try
00234 {
00235 ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
00236 datumLibraryImplementation = DatumLibraryImplementation::getInstance();
00237 geoidLibrary = GeoidLibrary::getInstance();
00238 ccsData = new CCSData();
00239 }
00240 catch(CoordinateConversionException e)
00241 {
00242
00243 EllipsoidLibraryImplementation::removeInstance();
00244 ellipsoidLibraryImplementation = 0;
00245
00246 DatumLibraryImplementation::removeInstance();
00247 datumLibraryImplementation = 0;
00248
00249 GeoidLibrary::removeInstance();
00250 geoidLibrary = 0;
00251
00252 throw e;
00253 }
00254
00255 ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
00256 datumLibraryImplementation = ccsData->datumLibraryImplementation;
00257 geoidLibrary = ccsData->geoidLibrary;
00258
00259 initCoordinateSystemState( SourceOrTarget::source );
00260 initCoordinateSystemState( SourceOrTarget::target );
00261
00262
00263 strcpy(Coordinate_System_Table[0].Name, "Albers Equal Area Conic");
00264 strcpy(Coordinate_System_Table[0].Code, "AC");
00265 Coordinate_System_Table[0].coordinateSystem = CoordinateType::albersEqualAreaConic;
00266
00267 strcpy(Coordinate_System_Table[1].Name, "Azimuthal Equidistant (S)");
00268 strcpy(Coordinate_System_Table[1].Code, "AL");
00269 Coordinate_System_Table[1].coordinateSystem = CoordinateType::azimuthalEquidistant;
00270
00271 strcpy(Coordinate_System_Table[2].Name, "Bonne");
00272 strcpy(Coordinate_System_Table[2].Code, "BF");
00273 Coordinate_System_Table[2].coordinateSystem = CoordinateType::bonne;
00274
00275 strcpy(Coordinate_System_Table[3].Name, "British National Grid (BNG)");
00276 strcpy(Coordinate_System_Table[3].Code, "BN");
00277 Coordinate_System_Table[3].coordinateSystem = CoordinateType::britishNationalGrid;
00278
00279 strcpy(Coordinate_System_Table[4].Name, "Cassini");
00280 strcpy(Coordinate_System_Table[4].Code, "CS");
00281 Coordinate_System_Table[4].coordinateSystem = CoordinateType::cassini;
00282
00283 strcpy(Coordinate_System_Table[5].Name, "Cylindrical Equal Area");
00284 strcpy(Coordinate_System_Table[5].Code, "LI");
00285 Coordinate_System_Table[5].coordinateSystem = CoordinateType::cylindricalEqualArea;
00286
00287 strcpy(Coordinate_System_Table[6].Name, "Eckert IV (S)");
00288 strcpy(Coordinate_System_Table[6].Code, "EF");
00289 Coordinate_System_Table[6].coordinateSystem = CoordinateType::eckert4;
00290
00291 strcpy(Coordinate_System_Table[7].Name, "Eckert VI (S)");
00292 strcpy(Coordinate_System_Table[7].Code, "ED");
00293 Coordinate_System_Table[7].coordinateSystem = CoordinateType::eckert6;
00294
00295 strcpy(Coordinate_System_Table[8].Name, "Equidistant Cylindrical (S)");
00296 strcpy(Coordinate_System_Table[8].Code, "CP");
00297 Coordinate_System_Table[8].coordinateSystem = CoordinateType::equidistantCylindrical;
00298
00299 strcpy(Coordinate_System_Table[9].Name, "Geocentric");
00300 strcpy(Coordinate_System_Table[9].Code, "GC");
00301 Coordinate_System_Table[9].coordinateSystem = CoordinateType::geocentric;
00302
00303 strcpy(Coordinate_System_Table[10].Name, "Geodetic");
00304 strcpy(Coordinate_System_Table[10].Code, "GD");
00305 Coordinate_System_Table[10].coordinateSystem = CoordinateType::geodetic;
00306
00307 strcpy(Coordinate_System_Table[11].Name, "GEOREF");
00308 strcpy(Coordinate_System_Table[11].Code, "GE");
00309 Coordinate_System_Table[11].coordinateSystem = CoordinateType::georef;
00310
00311 strcpy(Coordinate_System_Table[12].Name, "Global Area Reference System (GARS)");
00312 strcpy(Coordinate_System_Table[12].Code, "GA");
00313 Coordinate_System_Table[12].coordinateSystem = CoordinateType::globalAreaReferenceSystem;
00314
00315 strcpy(Coordinate_System_Table[13].Name, "Gnomonic (S)");
00316 strcpy(Coordinate_System_Table[13].Code, "GN");
00317 Coordinate_System_Table[13].coordinateSystem = CoordinateType::gnomonic;
00318
00319 strcpy(Coordinate_System_Table[14].Name, "Lambert Conformal Conic (1 Standard Parallel)");
00320 strcpy(Coordinate_System_Table[14].Code, "L1");
00321 Coordinate_System_Table[14].coordinateSystem = CoordinateType::lambertConformalConic1Parallel;
00322
00323 strcpy(Coordinate_System_Table[15].Name, "Lambert Conformal Conic (2 Standard Parallel)");
00324 strcpy(Coordinate_System_Table[15].Code, "L2");
00325 Coordinate_System_Table[15].coordinateSystem = CoordinateType::lambertConformalConic2Parallels;
00326
00327 strcpy(Coordinate_System_Table[16].Name, "Local Cartesian");
00328 strcpy(Coordinate_System_Table[16].Code, "LC");
00329 Coordinate_System_Table[16].coordinateSystem = CoordinateType::localCartesian;
00330
00331 strcpy(Coordinate_System_Table[17].Name, "Mercator (Standard Parallel)");
00332 strcpy(Coordinate_System_Table[17].Code, "MC");
00333 Coordinate_System_Table[17].coordinateSystem = CoordinateType::mercatorStandardParallel;
00334
00335 strcpy(Coordinate_System_Table[18].Name, "Mercator (Scale Factor)");
00336 strcpy(Coordinate_System_Table[18].Code, "MF");
00337 Coordinate_System_Table[18].coordinateSystem = CoordinateType::mercatorScaleFactor;
00338
00339 strcpy(Coordinate_System_Table[19].Name, "Military Grid Reference System (MGRS)");
00340 strcpy(Coordinate_System_Table[19].Code, "MG");
00341 Coordinate_System_Table[19].coordinateSystem = CoordinateType::militaryGridReferenceSystem;
00342
00343 strcpy(Coordinate_System_Table[20].Name, "Miller Cylindrical (S)");
00344 strcpy(Coordinate_System_Table[20].Code, "MH");
00345 Coordinate_System_Table[20].coordinateSystem = CoordinateType::millerCylindrical;
00346
00347 strcpy(Coordinate_System_Table[21].Name, "Mollweide (S)");
00348 strcpy(Coordinate_System_Table[21].Code, "MP");
00349 Coordinate_System_Table[21].coordinateSystem = CoordinateType::mollweide;
00350
00351 strcpy(Coordinate_System_Table[22].Name, "New Zealand Map Grid (NZMG)");
00352 strcpy(Coordinate_System_Table[22].Code, "NT");
00353 Coordinate_System_Table[22].coordinateSystem = CoordinateType::newZealandMapGrid;
00354
00355 strcpy(Coordinate_System_Table[23].Name, "Ney's (Modified Lambert Conformal Conic)");
00356 strcpy(Coordinate_System_Table[23].Code, "NY");
00357 Coordinate_System_Table[23].coordinateSystem = CoordinateType::neys;
00358
00359 strcpy(Coordinate_System_Table[24].Name, "Oblique Mercator");
00360 strcpy(Coordinate_System_Table[24].Code, "OC");
00361 Coordinate_System_Table[24].coordinateSystem = CoordinateType::obliqueMercator;
00362
00363 strcpy(Coordinate_System_Table[25].Name, "Orthographic (S)");
00364 strcpy(Coordinate_System_Table[25].Code, "OD");
00365 Coordinate_System_Table[25].coordinateSystem = CoordinateType::orthographic;
00366
00367 strcpy(Coordinate_System_Table[26].Name, "Polar Stereographic (Standard Parallel)");
00368 strcpy(Coordinate_System_Table[26].Code, "PG");
00369 Coordinate_System_Table[26].coordinateSystem = CoordinateType::polarStereographicStandardParallel;
00370
00371 strcpy(Coordinate_System_Table[27].Name, "Polar Stereographic (Scale Factor)");
00372 strcpy(Coordinate_System_Table[27].Code, "PF");
00373 Coordinate_System_Table[27].coordinateSystem = CoordinateType::polarStereographicScaleFactor;
00374
00375 strcpy(Coordinate_System_Table[28].Name, "Polyconic");
00376 strcpy(Coordinate_System_Table[28].Code, "PH");
00377 Coordinate_System_Table[28].coordinateSystem = CoordinateType::polyconic;
00378
00379 strcpy(Coordinate_System_Table[29].Name, "Sinusoidal");
00380 strcpy(Coordinate_System_Table[29].Code, "SA");
00381 Coordinate_System_Table[20].coordinateSystem = CoordinateType::sinusoidal;
00382
00383 strcpy(Coordinate_System_Table[30].Name, "Stereographic (S)");
00384 strcpy(Coordinate_System_Table[30].Code, "SD");
00385 Coordinate_System_Table[30].coordinateSystem = CoordinateType::stereographic;
00386
00387 strcpy(Coordinate_System_Table[31].Name, "Transverse Cylindrical Equal Area");
00388 strcpy(Coordinate_System_Table[31].Code, "TX");
00389 Coordinate_System_Table[31].coordinateSystem = CoordinateType::transverseCylindricalEqualArea;
00390
00391 strcpy(Coordinate_System_Table[32].Name, "Transverse Mercator");
00392 strcpy(Coordinate_System_Table[32].Code, "TC");
00393 Coordinate_System_Table[32].coordinateSystem = CoordinateType::transverseMercator;
00394
00395 strcpy(Coordinate_System_Table[33].Name, "Universal Polar Stereographic (UPS)");
00396 strcpy(Coordinate_System_Table[33].Code, "UP");
00397 Coordinate_System_Table[33].coordinateSystem = CoordinateType::universalPolarStereographic;
00398
00399 strcpy(Coordinate_System_Table[34].Name, "Universal Transverse Mercator (UTM)");
00400 strcpy(Coordinate_System_Table[34].Code, "UT");
00401 Coordinate_System_Table[34].coordinateSystem = CoordinateType::universalTransverseMercator;
00402
00403 strcpy(Coordinate_System_Table[35].Name, "United States National Grid (USNG)");
00404 strcpy(Coordinate_System_Table[35].Code, "US");
00405 Coordinate_System_Table[35].coordinateSystem = CoordinateType::usNationalGrid;
00406
00407 strcpy(Coordinate_System_Table[36].Name, "Van der Grinten");
00408 strcpy(Coordinate_System_Table[36].Code, "VA");
00409 Coordinate_System_Table[36].coordinateSystem = CoordinateType::vanDerGrinten;
00410
00411 setDataLibraries();
00412
00413 setDatum(SourceOrTarget::source, sourceDatumCode);
00414 try
00415 {
00416 setCoordinateSystem(SourceOrTarget::source, sourceParameters);
00417 }
00418 catch( CoordinateConversionException e )
00419 {
00420 throw CoordinateConversionException( "Input ", Coordinate_System_Table[sourceParameters->coordinateType()].Name, ": \n", e.getMessage() );
00421 }
00422
00423 setDatum(SourceOrTarget::target, targetDatumCode);
00424
00425 try
00426 {
00427 setCoordinateSystem(SourceOrTarget::target, targetParameters);
00428 }
00429 catch( CoordinateConversionException e )
00430 {
00431 throw CoordinateConversionException( "Output ", Coordinate_System_Table[targetParameters->coordinateType()].Name, ": \n", e.getMessage() );
00432 }
00433
00434 datumLibraryImplementation->datumIndex( "WGE", &WGS84_datum_index );
00435 }
00436
00437
00438 CoordinateConversionService::CoordinateConversionService( const CoordinateConversionService &ccs ) :
00439 ccsData( ccs.ccsData )
00440 {
00441 CCSThreadLock lock(&mutex);
00442
00443 ++ccsData->refCount;
00444
00445 ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
00446 datumLibraryImplementation = ccsData->datumLibraryImplementation;
00447 geoidLibrary = ccsData->geoidLibrary;
00448
00449 coordinateSystemState[SourceOrTarget::source].coordinateType = ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
00450 coordinateSystemState[SourceOrTarget::target].coordinateType = ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
00451
00452 copyParameters( SourceOrTarget::source, ccs.coordinateSystemState[SourceOrTarget::source].coordinateType, ccs.coordinateSystemState[SourceOrTarget::source].parameters );
00453 copyParameters( SourceOrTarget::target, ccs.coordinateSystemState[SourceOrTarget::target].coordinateType, ccs.coordinateSystemState[SourceOrTarget::target].parameters );
00454
00455 coordinateSystemState[SourceOrTarget::source].datumIndex = ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
00456 coordinateSystemState[SourceOrTarget::target].datumIndex = ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
00457
00458 WGS84_datum_index = ccs.WGS84_datum_index;
00459 }
00460
00461
00462 CoordinateConversionService::~CoordinateConversionService()
00463 {
00464 CCSThreadLock lock(&mutex);
00465
00466 if( --ccsData->refCount == 0 )
00467 {
00468 delete ccsData;
00469 ccsData = 0;
00470
00471 EllipsoidLibraryImplementation::removeInstance();
00472 ellipsoidLibraryImplementation = 0;
00473
00474 DatumLibraryImplementation::removeInstance();
00475 datumLibraryImplementation = 0;
00476
00477 GeoidLibrary::removeInstance();
00478 geoidLibrary = 0;
00479 }
00480
00481 deleteCoordinateSystem( SourceOrTarget::source );
00482 deleteCoordinateSystem( SourceOrTarget::target );
00483 }
00484
00485
00486 CoordinateConversionService& CoordinateConversionService::operator=( const CoordinateConversionService &ccs )
00487 {
00488 CCSThreadLock lock(&mutex);
00489
00490 if( ccsData == ccs.ccsData )
00491 return *this;
00492
00493 if( --ccsData->refCount == 0 )
00494 delete ccsData;
00495
00496 ccsData = ccs.ccsData;
00497 ++ccsData->refCount;
00498
00499 ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
00500 datumLibraryImplementation = ccsData->datumLibraryImplementation;
00501 geoidLibrary = ccsData->geoidLibrary;
00502
00503 coordinateSystemState[SourceOrTarget::source].coordinateType = ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
00504 coordinateSystemState[SourceOrTarget::target].coordinateType = ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
00505
00506 copyParameters( SourceOrTarget::source, ccs.coordinateSystemState[SourceOrTarget::source].coordinateType, ccs.coordinateSystemState[SourceOrTarget::source].parameters );
00507 copyParameters( SourceOrTarget::target, ccs.coordinateSystemState[SourceOrTarget::target].coordinateType, ccs.coordinateSystemState[SourceOrTarget::target].parameters );
00508
00509 coordinateSystemState[SourceOrTarget::source].datumIndex = ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
00510 coordinateSystemState[SourceOrTarget::target].datumIndex = ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
00511
00512 WGS84_datum_index = ccs.WGS84_datum_index;
00513
00514 return *this;
00515 }
00516
00517
00518 void CoordinateConversionService::convertSourceToTarget(
00519 CoordinateTuple* sourceCoordinates,
00520 Accuracy* sourceAccuracy,
00521 CoordinateTuple& targetCoordinates,
00522 Accuracy& targetAccuracy )
00523 {
00524
00525
00526
00527
00528
00529
00530
00531 convert( SourceOrTarget::source, SourceOrTarget::target,
00532 sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
00533 }
00534
00535
00536 void CoordinateConversionService::convertTargetToSource(
00537 CoordinateTuple* targetCoordinates,
00538 Accuracy* targetAccuracy,
00539 CoordinateTuple& sourceCoordinates,
00540 Accuracy& sourceAccuracy )
00541 {
00542
00543
00544
00545
00546
00547
00548
00549 convert( SourceOrTarget::target, SourceOrTarget::source, targetCoordinates, targetAccuracy, sourceCoordinates, sourceAccuracy );
00550 }
00551
00552
00553 void CoordinateConversionService::convertSourceToTargetCollection(
00554 const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
00555 const std::vector<MSP::CCS::Accuracy*>& sourceAccuracy,
00556 std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
00557 std::vector<MSP::CCS::Accuracy*>& targetAccuracy )
00558 {
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 convertCollection( sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
00570 }
00571
00572
00573 void CoordinateConversionService::convertTargetToSourceCollection(
00574 const std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
00575 const std::vector<MSP::CCS::Accuracy*>& targetAccuracy,
00576 std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
00577 std::vector<MSP::CCS::Accuracy*>& sourceAccuracy )
00578 {
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 convertCollection( targetCoordinates, targetAccuracy, sourceCoordinates, sourceAccuracy );
00590 }
00591
00592
00593 EllipsoidLibrary* CoordinateConversionService::getEllipsoidLibrary()
00594 {
00595
00596
00597
00598
00599
00600
00601 return ccsData->ellipsoidLibrary;
00602 }
00603
00604
00605 DatumLibrary* CoordinateConversionService::getDatumLibrary()
00606 {
00607
00608
00609
00610
00611
00612
00613 return ccsData->datumLibrary;
00614 }
00615
00616
00617 int CoordinateConversionService::getServiceVersion()
00618 {
00619
00620
00621
00622
00623 return 320;
00624 }
00625
00626
00627 const char* CoordinateConversionService::getDatum( const SourceOrTarget::Enum direction ) const
00628 {
00629
00630
00631
00632
00633
00634
00635
00636
00637 return coordinateSystemState[direction].datumCode;
00638 }
00639
00640
00641 MSP::CCS::CoordinateSystemParameters* CoordinateConversionService::getCoordinateSystem(
00642 const SourceOrTarget::Enum direction ) const
00643 {
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 switch( coordinateSystemState[direction].coordinateType )
00654 {
00655 case CoordinateType::albersEqualAreaConic:
00656 case CoordinateType::lambertConformalConic2Parallels:
00657 return coordinateSystemState[direction].parameters.mapProjection6Parameters;
00658 case CoordinateType::azimuthalEquidistant:
00659 case CoordinateType::bonne:
00660 case CoordinateType::cassini:
00661 case CoordinateType::cylindricalEqualArea:
00662 case CoordinateType::gnomonic:
00663 case CoordinateType::orthographic:
00664 case CoordinateType::polyconic:
00665 case CoordinateType::stereographic:
00666 return coordinateSystemState[direction].parameters.mapProjection4Parameters;
00667 case CoordinateType::eckert4:
00668 case CoordinateType::eckert6:
00669 case CoordinateType::millerCylindrical:
00670 case CoordinateType::mollweide:
00671 case CoordinateType::sinusoidal:
00672 case CoordinateType::vanDerGrinten:
00673 return coordinateSystemState[direction].parameters.mapProjection3Parameters;
00674 case CoordinateType::equidistantCylindrical:
00675 return coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
00676 case CoordinateType::geodetic:
00677 return coordinateSystemState[direction].parameters.geodeticParameters;
00678 case CoordinateType::lambertConformalConic1Parallel:
00679 case CoordinateType::transverseMercator:
00680 case CoordinateType::transverseCylindricalEqualArea:
00681 return coordinateSystemState[direction].parameters.mapProjection5Parameters;
00682 case CoordinateType::localCartesian:
00683 return coordinateSystemState[direction].parameters.localCartesianParameters;
00684 case CoordinateType::mercatorStandardParallel:
00686 return ((Mercator*)(coordinateSystemState[direction].coordinateSystem))->getStandardParallelParameters();
00687 case CoordinateType::mercatorScaleFactor:
00688 return coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
00689 case CoordinateType::neys:
00690 return coordinateSystemState[direction].parameters.neysParameters;
00691 case CoordinateType::obliqueMercator:
00692 return coordinateSystemState[direction].parameters.obliqueMercatorParameters;
00693 case CoordinateType::polarStereographicStandardParallel:
00694 return coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
00695 case CoordinateType::polarStereographicScaleFactor:
00696 return coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
00697 case CoordinateType::universalTransverseMercator:
00698 return coordinateSystemState[direction].parameters.utmParameters;
00699 case CoordinateType::britishNationalGrid:
00700 case CoordinateType::geocentric:
00701 case CoordinateType::georef:
00702 case CoordinateType::globalAreaReferenceSystem:
00703 case CoordinateType::militaryGridReferenceSystem:
00704 case CoordinateType::newZealandMapGrid:
00705 case CoordinateType::universalPolarStereographic:
00706 case CoordinateType::usNationalGrid:
00707 return coordinateSystemState[direction].parameters.coordinateSystemParameters;
00708 default:
00709 throw CoordinateConversionException(ErrorMessages::invalidType);
00710 }
00711 }
00712
00713
00714
00715
00716
00717
00718
00719 void CoordinateConversionService::initCoordinateSystemState( const SourceOrTarget::Enum direction )
00720 {
00721
00722
00723
00724
00725
00726
00727
00728 CCSThreadLock lock(&mutex);
00729
00730 coordinateSystemState[direction].datumIndex = 0;
00731 coordinateSystemState[direction].coordinateType = CoordinateType::geodetic;
00732 coordinateSystemState[direction].coordinateSystem = 0;
00733
00734 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
00735 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
00736 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
00737 coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
00738 coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
00739 coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
00740 coordinateSystemState[direction].parameters.geodeticParameters = 0;
00741 coordinateSystemState[direction].parameters.localCartesianParameters = 0;
00742 coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
00743 coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
00744 coordinateSystemState[direction].parameters.neysParameters = 0;
00745 coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
00746 coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
00747 coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
00748 coordinateSystemState[direction].parameters.utmParameters = 0;
00749
00750 }
00751
00752
00753 void CoordinateConversionService::setDataLibraries()
00754 {
00755
00756
00757
00758
00759
00760
00761 try
00762 {
00763 datumLibraryImplementation->setEllipsoidLibraryImplementation( ellipsoidLibraryImplementation );
00764 ellipsoidLibraryImplementation->setDatumLibraryImplementation( datumLibraryImplementation );
00765 }
00766 catch(CoordinateConversionException e)
00767 {
00768 char message[256] = "Error initializing MSP CCS data: ";
00769 strcpy( message, e.getMessage() );
00770 throw CoordinateConversionException( message );
00771 }
00772 }
00773
00774
00775 void CoordinateConversionService::setDatum(
00776 const SourceOrTarget::Enum direction,
00777 const char* datumCode )
00778 {
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788 CCSThreadLock lock(&mutex);
00789
00790 if( !datumCode )
00791 throw CoordinateConversionException( ErrorMessages::invalidDatumCode );
00792
00793 strcpy( coordinateSystemState[direction].datumCode, datumCode );
00794
00795 long datumIndex = 0;
00796 datumLibraryImplementation->datumIndex( datumCode, &datumIndex );
00797 coordinateSystemState[direction].datumIndex = datumIndex;
00798
00799 }
00800
00801
00802 void CoordinateConversionService::setCoordinateSystem(
00803 const SourceOrTarget::Enum direction,
00804 MSP::CCS::CoordinateSystemParameters* parameters )
00805 {
00806
00807
00808
00809
00810
00811
00812
00813
00814 CCSThreadLock lock(&mutex);
00815
00816 coordinateSystemState[direction].coordinateSystem = 0;
00817
00818 switch( parameters->coordinateType() )
00819 {
00820 case CoordinateType::albersEqualAreaConic:
00821 coordinateSystemState[direction].coordinateType = CoordinateType::albersEqualAreaConic;
00822 coordinateSystemState[direction].parameters.mapProjection6Parameters =
00823 new MapProjection6Parameters( *dynamic_cast< MapProjection6Parameters* >( parameters ) );
00824 break;
00825 case CoordinateType::azimuthalEquidistant:
00826 coordinateSystemState[direction].coordinateType = CoordinateType::azimuthalEquidistant;
00827 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00828 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00829 break;
00830 case CoordinateType::bonne:
00831 coordinateSystemState[direction].coordinateType = CoordinateType::bonne;
00832 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00833 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00834 break;
00835 case CoordinateType::britishNationalGrid:
00836 coordinateSystemState[direction].coordinateType = CoordinateType::britishNationalGrid;
00837 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00838 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00839 break;
00840 case CoordinateType::cassini:
00841 coordinateSystemState[direction].coordinateType = CoordinateType::cassini;
00842 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00843 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00844 break;
00845 case CoordinateType::cylindricalEqualArea:
00846 coordinateSystemState[direction].coordinateType = CoordinateType::cylindricalEqualArea;
00847 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00848 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00849 break;
00850 case CoordinateType::eckert4:
00851 coordinateSystemState[direction].coordinateType = CoordinateType::eckert4;
00852 coordinateSystemState[direction].parameters.mapProjection3Parameters =
00853 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
00854 break;
00855 case CoordinateType::eckert6:
00856 coordinateSystemState[direction].coordinateType = CoordinateType::eckert6;
00857 coordinateSystemState[direction].parameters.mapProjection3Parameters =
00858 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
00859 break;
00860 case CoordinateType::equidistantCylindrical:
00861 coordinateSystemState[direction].coordinateType = CoordinateType::equidistantCylindrical;
00862 coordinateSystemState[direction].parameters.equidistantCylindricalParameters =
00863 new EquidistantCylindricalParameters( *dynamic_cast< EquidistantCylindricalParameters* >( parameters ) );
00864 break;
00865 case CoordinateType::geocentric:
00866 coordinateSystemState[direction].coordinateType = CoordinateType::geocentric;
00867 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00868 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00869 break;
00870 case CoordinateType::geodetic:
00871 coordinateSystemState[direction].coordinateType = CoordinateType::geodetic;
00872 coordinateSystemState[direction].parameters.geodeticParameters =
00873 new GeodeticParameters( *dynamic_cast< GeodeticParameters* >( parameters ) );
00874 break;
00875 case CoordinateType::georef:
00876 coordinateSystemState[direction].coordinateType = CoordinateType::georef;
00877 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00878 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00879 break;
00880 case CoordinateType::globalAreaReferenceSystem:
00881 coordinateSystemState[direction].coordinateType = CoordinateType::globalAreaReferenceSystem;
00882 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00883 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00884 break;
00885 case CoordinateType::gnomonic:
00886 coordinateSystemState[direction].coordinateType = CoordinateType::gnomonic;
00887 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00888 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00889 break;
00890 case CoordinateType::lambertConformalConic1Parallel:
00891 coordinateSystemState[direction].coordinateType = CoordinateType::lambertConformalConic1Parallel;
00892 coordinateSystemState[direction].parameters.mapProjection5Parameters =
00893 new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
00894 break;
00895 case CoordinateType::lambertConformalConic2Parallels:
00896 coordinateSystemState[direction].coordinateType = CoordinateType::lambertConformalConic2Parallels;
00897 coordinateSystemState[direction].parameters.mapProjection6Parameters =
00898 new MapProjection6Parameters( *dynamic_cast< MapProjection6Parameters* >( parameters ) );
00899 break;
00900 case CoordinateType::localCartesian:
00901 coordinateSystemState[direction].coordinateType = CoordinateType::localCartesian;
00902 coordinateSystemState[direction].parameters.localCartesianParameters =
00903 new LocalCartesianParameters( *dynamic_cast< LocalCartesianParameters* >( parameters ) );
00904 break;
00905 case CoordinateType::mercatorStandardParallel:
00906 coordinateSystemState[direction].coordinateType = CoordinateType::mercatorStandardParallel;
00907 coordinateSystemState[direction].parameters.mercatorStandardParallelParameters =
00908 new MercatorStandardParallelParameters( *dynamic_cast< MercatorStandardParallelParameters* >( parameters ) );
00909 break;
00910 case CoordinateType::mercatorScaleFactor:
00911 coordinateSystemState[direction].coordinateType = CoordinateType::mercatorScaleFactor;
00912 coordinateSystemState[direction].parameters.mercatorScaleFactorParameters =
00913 new MercatorScaleFactorParameters( *dynamic_cast< MercatorScaleFactorParameters* >( parameters ) );
00914 break;
00915 case CoordinateType::militaryGridReferenceSystem:
00916 coordinateSystemState[direction].coordinateType = CoordinateType::militaryGridReferenceSystem;
00917 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00918 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00919 break;
00920 case CoordinateType::millerCylindrical:
00921 coordinateSystemState[direction].coordinateType = CoordinateType::millerCylindrical;
00922 coordinateSystemState[direction].parameters.mapProjection3Parameters =
00923 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
00924 break;
00925 case CoordinateType::mollweide:
00926 coordinateSystemState[direction].coordinateType = CoordinateType::mollweide;
00927 coordinateSystemState[direction].parameters.mapProjection3Parameters =
00928 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
00929 break;
00930 case CoordinateType::newZealandMapGrid:
00931 coordinateSystemState[direction].coordinateType = CoordinateType::newZealandMapGrid;
00932 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00933 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00934 break;
00935 case CoordinateType::neys:
00936 coordinateSystemState[direction].coordinateType = CoordinateType::neys;
00937 coordinateSystemState[direction].parameters.neysParameters =
00938 new NeysParameters( *dynamic_cast< NeysParameters* >( parameters ) );
00939 break;
00940 case CoordinateType::obliqueMercator:
00941 coordinateSystemState[direction].coordinateType = CoordinateType::obliqueMercator;
00942 coordinateSystemState[direction].parameters.obliqueMercatorParameters =
00943 new ObliqueMercatorParameters( *dynamic_cast< ObliqueMercatorParameters* >( parameters ) );
00944 break;
00945 case CoordinateType::orthographic:
00946 coordinateSystemState[direction].coordinateType = CoordinateType::orthographic;
00947 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00948 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00949 break;
00950 case CoordinateType::polarStereographicStandardParallel:
00951 coordinateSystemState[direction].coordinateType = CoordinateType::polarStereographicStandardParallel;
00952 coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = new PolarStereographicStandardParallelParameters( *dynamic_cast< PolarStereographicStandardParallelParameters* >( parameters ) );
00953 break;
00954 case CoordinateType::polarStereographicScaleFactor:
00955 coordinateSystemState[direction].coordinateType = CoordinateType::polarStereographicScaleFactor;
00956 coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters =
00957 new PolarStereographicScaleFactorParameters( *dynamic_cast< PolarStereographicScaleFactorParameters* >( parameters ) );
00958 break;
00959 case CoordinateType::polyconic:
00960 coordinateSystemState[direction].coordinateType = CoordinateType::polyconic;
00961 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00962 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00963 break;
00964 case CoordinateType::sinusoidal:
00965 coordinateSystemState[direction].coordinateType = CoordinateType::sinusoidal;
00966 coordinateSystemState[direction].parameters.mapProjection3Parameters =
00967 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
00968 break;
00969 case CoordinateType::stereographic:
00970 coordinateSystemState[direction].coordinateType = CoordinateType::stereographic;
00971 coordinateSystemState[direction].parameters.mapProjection4Parameters =
00972 new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
00973 break;
00974 case CoordinateType::transverseCylindricalEqualArea:
00975 coordinateSystemState[direction].coordinateType = CoordinateType::transverseCylindricalEqualArea;
00976 coordinateSystemState[direction].parameters.mapProjection5Parameters =
00977 new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
00978 break;
00979 case CoordinateType::transverseMercator:
00980 coordinateSystemState[direction].coordinateType = CoordinateType::transverseMercator;
00981 coordinateSystemState[direction].parameters.mapProjection5Parameters =
00982 new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
00983 break;
00984 case CoordinateType::universalPolarStereographic:
00985 coordinateSystemState[direction].coordinateType = CoordinateType::universalPolarStereographic;
00986 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00987 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00988 break;
00989 case CoordinateType::universalTransverseMercator:
00990 coordinateSystemState[direction].coordinateType = CoordinateType::universalTransverseMercator;
00991 coordinateSystemState[direction].parameters.utmParameters =
00992 new UTMParameters( *dynamic_cast< UTMParameters* >( parameters ) );
00993 break;
00994 case CoordinateType::usNationalGrid:
00995 coordinateSystemState[direction].coordinateType = CoordinateType::usNationalGrid;
00996 coordinateSystemState[direction].parameters.coordinateSystemParameters =
00997 new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
00998 break;
00999 case CoordinateType::vanDerGrinten:
01000 coordinateSystemState[direction].coordinateType = CoordinateType::vanDerGrinten;
01001 coordinateSystemState[direction].parameters.mapProjection3Parameters =
01002 new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
01003 break;
01004 default:
01005 throw CoordinateConversionException(ErrorMessages::invalidType);
01006 }
01007
01008 setParameters( direction );
01009
01010 }
01011
01012
01013 void CoordinateConversionService::setParameters( const SourceOrTarget::Enum direction )
01014 {
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024 Coordinate_State_Row* row = &coordinateSystemState[direction];
01025
01026 char ellipsoidCode[3];
01027 long ellipsoidIndex;
01028 double semiMajorAxis;
01029 double flattening;
01030
01031 datumLibraryImplementation->datumEllipsoidCode( row->datumIndex, ellipsoidCode );
01032
01033 ellipsoidLibraryImplementation->ellipsoidIndex( ellipsoidCode, &ellipsoidIndex );
01034
01035 ellipsoidLibraryImplementation->ellipsoidParameters( ellipsoidIndex, &semiMajorAxis, &flattening );
01036
01037 switch( coordinateSystemState[direction].coordinateType )
01038 {
01039 case CoordinateType::albersEqualAreaConic:
01040 {
01041 MapProjection6Parameters* param = row->parameters.mapProjection6Parameters;
01042
01043 coordinateSystemState[direction].coordinateSystem = new AlbersEqualAreaConic(
01044 semiMajorAxis, flattening,
01045 param->centralMeridian(),
01046 param->originLatitude(),
01047 param->standardParallel1(),
01048 param->standardParallel2(),
01049 param->falseEasting(),
01050 param->falseNorthing() );
01051 break;
01052 }
01053 case CoordinateType::azimuthalEquidistant:
01054 {
01055 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01056
01057 coordinateSystemState[direction].coordinateSystem = new AzimuthalEquidistant(
01058 semiMajorAxis, flattening,
01059 param->centralMeridian(),
01060 param->originLatitude(),
01061 param->falseEasting(),
01062 param->falseNorthing() );
01063 break;
01064 }
01065 case CoordinateType::bonne:
01066 {
01067 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01068
01069 coordinateSystemState[direction].coordinateSystem = new Bonne(
01070 semiMajorAxis, flattening,
01071 param->centralMeridian(),
01072 param->originLatitude(),
01073 param->falseEasting(),
01074 param->falseNorthing() );
01075 break;
01076 }
01077 case CoordinateType::britishNationalGrid:
01078 {
01079 coordinateSystemState[direction].coordinateSystem = new BritishNationalGrid( ellipsoidCode );
01080
01081 break;
01082 }
01083 case CoordinateType::cassini:
01084 {
01085 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01086
01087 coordinateSystemState[direction].coordinateSystem = new Cassini(
01088 semiMajorAxis, flattening,
01089 param->centralMeridian(),
01090 param->originLatitude(),
01091 param->falseEasting(),
01092 param->falseNorthing() );
01093 break;
01094 }
01095 case CoordinateType::cylindricalEqualArea:
01096 {
01097 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01098
01099 coordinateSystemState[direction].coordinateSystem = new CylindricalEqualArea(
01100 semiMajorAxis, flattening,
01101 param->centralMeridian(),
01102 param->originLatitude(),
01103 param->falseEasting(),
01104 param->falseNorthing() );
01105 break;
01106 }
01107 case CoordinateType::eckert4:
01108 {
01109 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01110
01111 coordinateSystemState[direction].coordinateSystem = new Eckert4(
01112 semiMajorAxis, flattening,
01113 param->centralMeridian(),
01114 param->falseEasting(),
01115 param->falseNorthing() );
01116 break;
01117 }
01118 case CoordinateType::eckert6:
01119 {
01120 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01121
01122 coordinateSystemState[direction].coordinateSystem = new Eckert6(
01123 semiMajorAxis, flattening,
01124 param->centralMeridian(),
01125 param->falseEasting(),
01126 param->falseNorthing() );
01127 break;
01128 }
01129 case CoordinateType::equidistantCylindrical:
01130 {
01131 EquidistantCylindricalParameters* param = row->parameters.equidistantCylindricalParameters;
01132
01133 coordinateSystemState[direction].coordinateSystem = new EquidistantCylindrical(
01134 semiMajorAxis,flattening,
01135 param->centralMeridian(),
01136 param->standardParallel(),
01137 param->falseEasting(),
01138 param->falseNorthing() );
01139 break;
01140 }
01141 case CoordinateType::geocentric:
01142 {
01143 coordinateSystemState[direction].coordinateSystem = new Geocentric( semiMajorAxis, flattening );
01144 break;
01145 }
01146 case CoordinateType::geodetic:
01147 coordinateSystemState[direction].coordinateSystem = 0;
01148 break;
01149 case CoordinateType::georef:
01150 coordinateSystemState[direction].coordinateSystem = new GEOREF();
01151 break;
01152 case CoordinateType::globalAreaReferenceSystem:
01153 coordinateSystemState[direction].coordinateSystem = new GARS();
01154 break;
01155 case CoordinateType::gnomonic:
01156 {
01157 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01158
01159 coordinateSystemState[direction].coordinateSystem = new Gnomonic(
01160 semiMajorAxis, flattening,
01161 param->centralMeridian(),
01162 param->originLatitude(),
01163 param->falseEasting(),
01164 param->falseNorthing() );
01165 break;
01166 }
01167 case CoordinateType::lambertConformalConic1Parallel:
01168 {
01169 MapProjection5Parameters* param = row->parameters.mapProjection5Parameters;
01170
01171 coordinateSystemState[direction].coordinateSystem = new LambertConformalConic(
01172 semiMajorAxis, flattening,
01173 param->centralMeridian(),
01174 param->originLatitude(),
01175 param->falseEasting(),
01176 param->falseNorthing(),
01177 param->scaleFactor() );
01178 break;
01179 }
01180 case CoordinateType::lambertConformalConic2Parallels:
01181 {
01182 MapProjection6Parameters* param = row->parameters.mapProjection6Parameters;
01183
01184 coordinateSystemState[direction].coordinateSystem = new LambertConformalConic(
01185 semiMajorAxis, flattening,
01186 param->centralMeridian(),
01187 param->originLatitude(),
01188 param->standardParallel1(),
01189 param->standardParallel2(),
01190 param->falseEasting(),
01191 param->falseNorthing() );
01192 break;
01193 }
01194 case CoordinateType::localCartesian:
01195 {
01196 LocalCartesianParameters* param = row->parameters.localCartesianParameters;
01197
01198 coordinateSystemState[direction].coordinateSystem = new LocalCartesian(
01199 semiMajorAxis, flattening,
01200 param->longitude(),
01201 param->latitude(),
01202 param->height(),
01203 param->orientation() );
01204 break;
01205 }
01206 case CoordinateType::mercatorStandardParallel:
01207 {
01208 MercatorStandardParallelParameters* param = row->parameters.mercatorStandardParallelParameters;
01209 double scaleFactor;
01210 coordinateSystemState[direction].coordinateSystem = new Mercator(
01211 semiMajorAxis, flattening,
01212 param->centralMeridian(),
01213 param->standardParallel(),
01214 param->falseEasting(),
01215 param->falseNorthing(),
01216 &scaleFactor );
01217
01218 param->setScaleFactor( scaleFactor );
01219
01220 break;
01221 }
01222 case CoordinateType::mercatorScaleFactor:
01223 {
01224 MercatorScaleFactorParameters* param = row->parameters.mercatorScaleFactorParameters;
01225
01226 coordinateSystemState[direction].coordinateSystem = new Mercator(
01227 semiMajorAxis, flattening,
01228 param->centralMeridian(),
01229 param->falseEasting(),
01230 param->falseNorthing(),
01231 param->scaleFactor() );
01232
01233 break;
01234 }
01235 case CoordinateType::militaryGridReferenceSystem:
01236 {
01237 coordinateSystemState[direction].coordinateSystem = new MGRS(
01238 semiMajorAxis, flattening, ellipsoidCode );
01239
01240 break;
01241 }
01242 case CoordinateType::millerCylindrical:
01243 {
01244 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01245
01246 coordinateSystemState[direction].coordinateSystem = new MillerCylindrical(
01247 semiMajorAxis, flattening,
01248 param->centralMeridian(),
01249 param->falseEasting(),
01250 param->falseNorthing() );
01251 break;
01252 }
01253 case CoordinateType::mollweide:
01254 {
01255 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01256
01257 coordinateSystemState[direction].coordinateSystem = new Mollweide(
01258 semiMajorAxis,flattening,
01259 param->centralMeridian(),
01260 param->falseEasting(),
01261 param->falseNorthing() );
01262 break;
01263 }
01264 case CoordinateType::newZealandMapGrid:
01265 {
01266 coordinateSystemState[direction].coordinateSystem = new NZMG( ellipsoidCode );
01267
01268 break;
01269 }
01270 case CoordinateType::neys:
01271 {
01272 NeysParameters* param = row->parameters.neysParameters;
01273
01274 coordinateSystemState[direction].coordinateSystem = new Neys(
01275 semiMajorAxis, flattening,
01276 param->centralMeridian(),
01277 param->originLatitude(),
01278 param->standardParallel1(),
01279 param->falseEasting(),
01280 param->falseNorthing() );
01281 break;
01282 }
01283 case CoordinateType::obliqueMercator:
01284 {
01285 ObliqueMercatorParameters* param = row->parameters.obliqueMercatorParameters;
01286
01287 coordinateSystemState[direction].coordinateSystem = new ObliqueMercator(
01288 semiMajorAxis, flattening,
01289 param->originLatitude(),
01290 param->longitude1(),
01291 param->latitude1(),
01292 param->longitude2(),
01293 param->latitude2(),
01294 param->falseEasting(),
01295 param->falseNorthing(),
01296 param->scaleFactor() );
01297 break;
01298 }
01299 case CoordinateType::orthographic:
01300 {
01301 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01302
01303 coordinateSystemState[direction].coordinateSystem = new Orthographic(
01304 semiMajorAxis, flattening,
01305 param->centralMeridian(),
01306 param->originLatitude(),
01307 param->falseEasting(),
01308 param->falseNorthing() );
01309 break;
01310 }
01311 case CoordinateType::polarStereographicStandardParallel:
01312 {
01313 PolarStereographicStandardParallelParameters* param = row->parameters.polarStereographicStandardParallelParameters;
01314
01315 coordinateSystemState[direction].coordinateSystem = new PolarStereographic(
01316 semiMajorAxis, flattening,
01317 param->centralMeridian(),
01318 param->standardParallel(),
01319 param->falseEasting(),
01320 param->falseNorthing() );
01321
01322 break;
01323 }
01324 case CoordinateType::polarStereographicScaleFactor:
01325 {
01326 PolarStereographicScaleFactorParameters* param = row->parameters.polarStereographicScaleFactorParameters;
01327
01328 coordinateSystemState[direction].coordinateSystem = new PolarStereographic(
01329 semiMajorAxis, flattening,
01330 param->centralMeridian(),
01331 param->scaleFactor(),
01332 param->hemisphere(),
01333 param->falseEasting(),
01334 param->falseNorthing() );
01335 break;
01336 }
01337 case CoordinateType::polyconic:
01338 {
01339 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01340
01341 coordinateSystemState[direction].coordinateSystem = new Polyconic(
01342 semiMajorAxis, flattening,
01343 param->centralMeridian(),
01344 param->originLatitude(),
01345 param->falseEasting(),
01346 param->falseNorthing() );
01347 break;
01348 }
01349 case CoordinateType::sinusoidal:
01350 {
01351 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01352
01353 coordinateSystemState[direction].coordinateSystem = new Sinusoidal(
01354 semiMajorAxis, flattening,
01355 param->centralMeridian(),
01356 param->falseEasting(),
01357 param->falseNorthing() );
01358 break;
01359 }
01360 case CoordinateType::stereographic:
01361 {
01362 MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
01363
01364 coordinateSystemState[direction].coordinateSystem = new Stereographic(
01365 semiMajorAxis, flattening,
01366 param->centralMeridian(),
01367 param->originLatitude(),
01368 param->falseEasting(),
01369 param->falseNorthing() );
01370 break;
01371 }
01372 case CoordinateType::transverseCylindricalEqualArea:
01373 {
01374 MapProjection5Parameters* param = row->parameters.mapProjection5Parameters;
01375
01376 coordinateSystemState[direction].coordinateSystem = new TransverseCylindricalEqualArea(
01377 semiMajorAxis, flattening,
01378 param->centralMeridian(),
01379 param->originLatitude(),
01380 param->falseEasting(),
01381 param->falseNorthing(),
01382 param->scaleFactor() );
01383 break;
01384 }
01385 case CoordinateType::transverseMercator:
01386 {
01387 MapProjection5Parameters* param = row->parameters.mapProjection5Parameters;
01388
01389 coordinateSystemState[direction].coordinateSystem = new TransverseMercator(
01390 semiMajorAxis, flattening,
01391 param->centralMeridian(),
01392 param->originLatitude(),
01393 param->falseEasting(),
01394 param->falseNorthing(),
01395 param->scaleFactor() );
01396 break;
01397 }
01398 case CoordinateType::universalPolarStereographic:
01399 {
01400 coordinateSystemState[direction].coordinateSystem = new UPS(
01401 semiMajorAxis, flattening );
01402
01403 break;
01404 }
01405 case CoordinateType::universalTransverseMercator:
01406 {
01407 if( direction == SourceOrTarget::target )
01408 {
01409 UTMParameters* param = row->parameters.utmParameters;
01410
01411 if((param->override() != 0) && (param->zone() == 0))
01412 throw CoordinateConversionException( ErrorMessages::zone );
01413 else
01414 {
01415 if(param->override() == 0)
01416 param->setZone( 0 );
01417 }
01418
01419
01420
01421
01422
01423
01424
01425
01426 coordinateSystemState[direction].coordinateSystem = new UTM(
01427 semiMajorAxis, flattening, param->zone() );
01428 }
01429 else
01430 coordinateSystemState[direction].coordinateSystem = new UTM( semiMajorAxis, flattening, 0 );
01431
01432 break;
01433 }
01434 case CoordinateType::usNationalGrid:
01435 {
01436 coordinateSystemState[direction].coordinateSystem = new USNG( semiMajorAxis, flattening, ellipsoidCode );
01437
01438 break;
01439 }
01440 case CoordinateType::vanDerGrinten:
01441 {
01442 MapProjection3Parameters* param = row->parameters.mapProjection3Parameters;
01443
01444 coordinateSystemState[direction].coordinateSystem = new VanDerGrinten(
01445 semiMajorAxis, flattening,
01446 param->centralMeridian(),
01447 param->falseEasting(),
01448 param->falseNorthing() );
01449 break;
01450 }
01451 default:
01452 break;
01453 }
01454 }
01455
01456
01457 void CoordinateConversionService::deleteCoordinateSystem( const SourceOrTarget::Enum direction )
01458 {
01459
01460
01461
01462
01463
01464
01465
01466 switch( coordinateSystemState[direction].coordinateType )
01467 {
01468 case CoordinateType::albersEqualAreaConic:
01469 if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
01470 {
01471 delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
01472 coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
01473 }
01474 if( coordinateSystemState[direction].coordinateSystem )
01475 {
01476 delete ((AlbersEqualAreaConic*)(coordinateSystemState[direction].coordinateSystem));
01477 coordinateSystemState[direction].coordinateSystem = 0;
01478 }
01479 break;
01480 case CoordinateType::lambertConformalConic2Parallels:
01481 if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
01482 {
01483 delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
01484 coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
01485 }
01486 if( coordinateSystemState[direction].coordinateSystem )
01487 {
01488 delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
01489 coordinateSystemState[direction].coordinateSystem = 0;
01490 }
01491 break;
01492 case CoordinateType::azimuthalEquidistant:
01493 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01494 {
01495 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01496 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01497 }
01498 if( coordinateSystemState[direction].coordinateSystem )
01499 {
01500 delete ((AzimuthalEquidistant*)(coordinateSystemState[direction].coordinateSystem));
01501 coordinateSystemState[direction].coordinateSystem = 0;
01502 }
01503 break;
01504 case CoordinateType::bonne:
01505 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01506 {
01507 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01508 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01509 }
01510 if( coordinateSystemState[direction].coordinateSystem )
01511 {
01512 delete ((Bonne*)(coordinateSystemState[direction].coordinateSystem));
01513 coordinateSystemState[direction].coordinateSystem = 0;
01514 }
01515 break;
01516 case CoordinateType::cassini:
01517 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01518 {
01519 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01520 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01521 }
01522 if( coordinateSystemState[direction].coordinateSystem )
01523 {
01524 delete ((Cassini*)(coordinateSystemState[direction].coordinateSystem));
01525 coordinateSystemState[direction].coordinateSystem = 0;
01526 }
01527 break;
01528 case CoordinateType::cylindricalEqualArea:
01529 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01530 {
01531 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01532 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01533 }
01534 if( coordinateSystemState[direction].coordinateSystem )
01535 {
01536 delete ((CylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
01537 coordinateSystemState[direction].coordinateSystem = 0;
01538 }
01539 break;
01540 case CoordinateType::gnomonic:
01541 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01542 {
01543 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01544 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01545 }
01546 if( coordinateSystemState[direction].coordinateSystem )
01547 {
01548 delete ((Gnomonic*)(coordinateSystemState[direction].coordinateSystem));
01549 coordinateSystemState[direction].coordinateSystem = 0;
01550 }
01551 break;
01552 case CoordinateType::orthographic:
01553 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01554 {
01555 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01556 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01557 }
01558 if( coordinateSystemState[direction].coordinateSystem )
01559 {
01560 delete ((Orthographic*)(coordinateSystemState[direction].coordinateSystem));
01561 coordinateSystemState[direction].coordinateSystem = 0;
01562 }
01563 break;
01564 case CoordinateType::polyconic:
01565 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01566 {
01567 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01568 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01569 }
01570 if( coordinateSystemState[direction].coordinateSystem )
01571 {
01572 delete ((Polyconic*)(coordinateSystemState[direction].coordinateSystem));
01573 coordinateSystemState[direction].coordinateSystem = 0;
01574 }
01575 break;
01576 case CoordinateType::stereographic:
01577 if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
01578 {
01579 delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
01580 coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
01581 }
01582 if( coordinateSystemState[direction].coordinateSystem )
01583 {
01584 delete ((Stereographic*)(coordinateSystemState[direction].coordinateSystem));
01585 coordinateSystemState[direction].coordinateSystem = 0;
01586 }
01587 break;
01588 case CoordinateType::britishNationalGrid:
01589 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01590 {
01591 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01592 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01593 }
01594 if( coordinateSystemState[direction].coordinateSystem )
01595 {
01596 delete ((BritishNationalGrid*)(coordinateSystemState[direction].coordinateSystem));
01597 coordinateSystemState[direction].coordinateSystem = 0;
01598 }
01599 break;
01600 case CoordinateType::eckert4:
01601 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01602 {
01603 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01604 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01605 }
01606 if( coordinateSystemState[direction].coordinateSystem )
01607 {
01608 delete ((Eckert4*)(coordinateSystemState[direction].coordinateSystem));
01609 coordinateSystemState[direction].coordinateSystem = 0;
01610 }
01611 break;
01612 case CoordinateType::eckert6:
01613 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01614 {
01615 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01616 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01617 }
01618 if( coordinateSystemState[direction].coordinateSystem )
01619 {
01620 delete ((Eckert6*)(coordinateSystemState[direction].coordinateSystem));
01621 coordinateSystemState[direction].coordinateSystem = 0;
01622 }
01623 break;
01624 case CoordinateType::millerCylindrical:
01625 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01626 {
01627 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01628 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01629 }
01630 if( coordinateSystemState[direction].coordinateSystem )
01631 {
01632 delete ((MillerCylindrical*)(coordinateSystemState[direction].coordinateSystem));
01633 coordinateSystemState[direction].coordinateSystem = 0;
01634 }
01635 break;
01636 case CoordinateType::mollweide:
01637 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01638 {
01639 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01640 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01641 }
01642 if( coordinateSystemState[direction].coordinateSystem )
01643 {
01644 delete ((Mollweide*)(coordinateSystemState[direction].coordinateSystem));
01645 coordinateSystemState[direction].coordinateSystem = 0;
01646 }
01647 break;
01648 case CoordinateType::sinusoidal:
01649 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01650 {
01651 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01652 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01653 }
01654 if( coordinateSystemState[direction].coordinateSystem )
01655 {
01656 delete ((Sinusoidal*)(coordinateSystemState[direction].coordinateSystem));
01657 coordinateSystemState[direction].coordinateSystem = 0;
01658 }
01659 break;
01660 case CoordinateType::vanDerGrinten:
01661 if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
01662 {
01663 delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
01664 coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
01665 }
01666 if( coordinateSystemState[direction].coordinateSystem )
01667 {
01668 delete ((VanDerGrinten*)(coordinateSystemState[direction].coordinateSystem));
01669 coordinateSystemState[direction].coordinateSystem = 0;
01670 }
01671 break;
01672 case CoordinateType::equidistantCylindrical:
01673 if( coordinateSystemState[direction].parameters.equidistantCylindricalParameters )
01674 {
01675 delete coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
01676 coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
01677 }
01678 if( coordinateSystemState[direction].coordinateSystem )
01679 {
01680 delete ((EquidistantCylindrical*)(coordinateSystemState[direction].coordinateSystem));
01681 coordinateSystemState[direction].coordinateSystem = 0;
01682 }
01683 break;
01684 case CoordinateType::geocentric:
01685 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01686 {
01687 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01688 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01689 }
01690 if( coordinateSystemState[direction].coordinateSystem )
01691 {
01692 delete ((Geocentric*)(coordinateSystemState[direction].coordinateSystem));
01693 coordinateSystemState[direction].coordinateSystem = 0;
01694 }
01695 break;
01696 case CoordinateType::geodetic:
01697 if( coordinateSystemState[direction].parameters.geodeticParameters )
01698 {
01699 delete coordinateSystemState[direction].parameters.geodeticParameters;
01700 coordinateSystemState[direction].parameters.geodeticParameters = 0;
01701 }
01702 break;
01703 case CoordinateType::georef:
01704 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01705 {
01706 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01707 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01708 }
01709 if( coordinateSystemState[direction].coordinateSystem )
01710 {
01711 delete ((GEOREF*)(coordinateSystemState[direction].coordinateSystem));
01712 coordinateSystemState[direction].coordinateSystem = 0;
01713 }
01714 break;
01715 case CoordinateType::globalAreaReferenceSystem:
01716 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01717 {
01718 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01719 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01720 }
01721 if( coordinateSystemState[direction].coordinateSystem )
01722 {
01723 delete ((GARS*)(coordinateSystemState[direction].coordinateSystem));
01724 coordinateSystemState[direction].coordinateSystem = 0;
01725 }
01726 break;
01727 case CoordinateType::lambertConformalConic1Parallel:
01728 if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
01729 {
01730 delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
01731 coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
01732 }
01733 if( coordinateSystemState[direction].coordinateSystem )
01734 {
01735 delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
01736 coordinateSystemState[direction].coordinateSystem = 0;
01737 }
01738 break;
01739 case CoordinateType::transverseCylindricalEqualArea:
01740 if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
01741 {
01742 delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
01743 coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
01744 }
01745 if( coordinateSystemState[direction].coordinateSystem )
01746 {
01747 delete ((TransverseCylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
01748 coordinateSystemState[direction].coordinateSystem = 0;
01749 }
01750 break;
01751 case CoordinateType::transverseMercator:
01752 if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
01753 {
01754 delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
01755 coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
01756 }
01757 if( coordinateSystemState[direction].coordinateSystem )
01758 {
01759 delete ((TransverseMercator*)(coordinateSystemState[direction].coordinateSystem));
01760 coordinateSystemState[direction].coordinateSystem = 0;
01761 }
01762 break;
01763 case CoordinateType::localCartesian:
01764 if( coordinateSystemState[direction].parameters.localCartesianParameters )
01765 {
01766 delete coordinateSystemState[direction].parameters.localCartesianParameters;
01767 coordinateSystemState[direction].parameters.localCartesianParameters = 0;
01768 }
01769 if( coordinateSystemState[direction].coordinateSystem )
01770 {
01771 delete ((LocalCartesian*)(coordinateSystemState[direction].coordinateSystem));
01772 coordinateSystemState[direction].coordinateSystem = 0;
01773 }
01774 break;
01775 case CoordinateType::mercatorStandardParallel:
01776 if( coordinateSystemState[direction].parameters.mercatorStandardParallelParameters )
01777 {
01778 delete coordinateSystemState[direction].parameters.mercatorStandardParallelParameters;
01779 coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
01780 }
01781 if( coordinateSystemState[direction].coordinateSystem )
01782 {
01783 delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
01784 coordinateSystemState[direction].coordinateSystem = 0;
01785 }
01786 break;
01787 case CoordinateType::mercatorScaleFactor:
01788 if( coordinateSystemState[direction].parameters.mercatorScaleFactorParameters )
01789 {
01790 delete coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
01791 coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
01792 }
01793 if( coordinateSystemState[direction].coordinateSystem )
01794 {
01795 delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
01796 coordinateSystemState[direction].coordinateSystem = 0;
01797 }
01798 break;
01799 case CoordinateType::militaryGridReferenceSystem:
01800 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01801 {
01802 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01803 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01804 }
01805 if( coordinateSystemState[direction].coordinateSystem )
01806 {
01807 delete ((MGRS*)(coordinateSystemState[direction].coordinateSystem));
01808 coordinateSystemState[direction].coordinateSystem = 0;
01809 }
01810 break;
01811 case CoordinateType::usNationalGrid:
01812 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01813 {
01814 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01815 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01816 }
01817 if( coordinateSystemState[direction].coordinateSystem )
01818 {
01819 delete ((USNG*)(coordinateSystemState[direction].coordinateSystem));
01820 coordinateSystemState[direction].coordinateSystem = 0;
01821 }
01822 break;
01823 case CoordinateType::newZealandMapGrid:
01824 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01825 {
01826 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01827 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01828 }
01829 if( coordinateSystemState[direction].coordinateSystem )
01830 {
01831 delete ((NZMG*)(coordinateSystemState[direction].coordinateSystem));
01832 coordinateSystemState[direction].coordinateSystem = 0;
01833 }
01834 break;
01835 case CoordinateType::neys:
01836 if( coordinateSystemState[direction].parameters.neysParameters )
01837 {
01838 delete coordinateSystemState[direction].parameters.neysParameters;
01839 coordinateSystemState[direction].parameters.neysParameters = 0;
01840 }
01841 if( coordinateSystemState[direction].coordinateSystem )
01842 {
01843 delete ((Neys*)(coordinateSystemState[direction].coordinateSystem));
01844 coordinateSystemState[direction].coordinateSystem = 0;
01845 }
01846 break;
01847 case CoordinateType::obliqueMercator:
01848 if( coordinateSystemState[direction].parameters.obliqueMercatorParameters )
01849 {
01850 delete coordinateSystemState[direction].parameters.obliqueMercatorParameters;
01851 coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
01852 }
01853 if( coordinateSystemState[direction].coordinateSystem )
01854 {
01855 delete ((ObliqueMercator*)(coordinateSystemState[direction].coordinateSystem));
01856 coordinateSystemState[direction].coordinateSystem = 0;
01857 }
01858 break;
01859 case CoordinateType::polarStereographicStandardParallel:
01860 if( coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters )
01861 {
01862 delete coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
01863 coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
01864 }
01865 if( coordinateSystemState[direction].coordinateSystem )
01866 {
01867 delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
01868 coordinateSystemState[direction].coordinateSystem = 0;
01869 }
01870 break;
01871 case CoordinateType::polarStereographicScaleFactor:
01872 if( coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters )
01873 {
01874 delete coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
01875 coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
01876 }
01877 if( coordinateSystemState[direction].coordinateSystem )
01878 {
01879 delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
01880 coordinateSystemState[direction].coordinateSystem = 0;
01881 }
01882 break;
01883 case CoordinateType::universalPolarStereographic:
01884 if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
01885 {
01886 delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
01887 coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
01888 }
01889 if( coordinateSystemState[direction].coordinateSystem )
01890 {
01891 delete ((UPS*)(coordinateSystemState[direction].coordinateSystem));
01892 coordinateSystemState[direction].coordinateSystem = 0;
01893 }
01894 break;
01895 case CoordinateType::universalTransverseMercator:
01896 if( coordinateSystemState[direction].parameters.utmParameters )
01897 {
01898 delete coordinateSystemState[direction].parameters.utmParameters;
01899 coordinateSystemState[direction].parameters.utmParameters = 0;
01900 }
01901 if( coordinateSystemState[direction].coordinateSystem )
01902 {
01903 delete ((UTM*)(coordinateSystemState[direction].coordinateSystem));
01904 coordinateSystemState[direction].coordinateSystem = 0;
01905 }
01906 break;
01907 default:
01908 break;
01909 }
01910 }
01911
01912
01913 void CoordinateConversionService::copyParameters(
01914 SourceOrTarget::Enum direction,
01915 CoordinateType::Enum coordinateType,
01916 Parameters parameters )
01917 {
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928 initCoordinateSystemState( direction );
01929
01930 switch( coordinateType )
01931 {
01932 case CoordinateType::albersEqualAreaConic:
01933 case CoordinateType::lambertConformalConic2Parallels:
01934 setCoordinateSystem( direction, parameters.mapProjection6Parameters );
01935 break;
01936 case CoordinateType::azimuthalEquidistant:
01937 case CoordinateType::bonne:
01938 case CoordinateType::cassini:
01939 case CoordinateType::cylindricalEqualArea:
01940 case CoordinateType::gnomonic:
01941 case CoordinateType::orthographic:
01942 case CoordinateType::polyconic:
01943 case CoordinateType::stereographic:
01944 setCoordinateSystem( direction, parameters.mapProjection4Parameters );
01945 break;
01946 case CoordinateType::eckert4:
01947 case CoordinateType::eckert6:
01948 case CoordinateType::millerCylindrical:
01949 case CoordinateType::mollweide:
01950 case CoordinateType::sinusoidal:
01951 case CoordinateType::vanDerGrinten:
01952 setCoordinateSystem( direction, parameters.mapProjection3Parameters );
01953 break;
01954 case CoordinateType::equidistantCylindrical:
01955 setCoordinateSystem( direction, parameters.equidistantCylindricalParameters );
01956 break;
01957 case CoordinateType::geodetic:
01958 setCoordinateSystem( direction, parameters.geodeticParameters );
01959 break;
01960 case CoordinateType::lambertConformalConic1Parallel:
01961 case CoordinateType::transverseMercator:
01962 case CoordinateType::transverseCylindricalEqualArea:
01963 setCoordinateSystem( direction, parameters.mapProjection5Parameters );
01964 break;
01965 case CoordinateType::localCartesian:
01966 setCoordinateSystem( direction, parameters.localCartesianParameters );
01967 break;
01968 case CoordinateType::mercatorStandardParallel:
01969 setCoordinateSystem( direction, parameters.mercatorStandardParallelParameters );
01970 break;
01971 case CoordinateType::mercatorScaleFactor:
01972 setCoordinateSystem( direction, parameters.mercatorScaleFactorParameters );
01973 break;
01974 case CoordinateType::neys:
01975 setCoordinateSystem( direction, parameters.neysParameters );
01976 break;
01977 case CoordinateType::obliqueMercator:
01978 setCoordinateSystem( direction, parameters.obliqueMercatorParameters );
01979 break;
01980 case CoordinateType::polarStereographicStandardParallel:
01981 setCoordinateSystem( direction, parameters.polarStereographicStandardParallelParameters );
01982 break;
01983 case CoordinateType::polarStereographicScaleFactor:
01984 setCoordinateSystem( direction, parameters.polarStereographicScaleFactorParameters );
01985 break;
01986 case CoordinateType::universalTransverseMercator:
01987 setCoordinateSystem( direction, parameters.utmParameters );
01988 break;
01989 case CoordinateType::britishNationalGrid:
01990 case CoordinateType::geocentric:
01991 case CoordinateType::georef:
01992 case CoordinateType::globalAreaReferenceSystem:
01993 case CoordinateType::militaryGridReferenceSystem:
01994 case CoordinateType::newZealandMapGrid:
01995 case CoordinateType::universalPolarStereographic:
01996 case CoordinateType::usNationalGrid:
01997 setCoordinateSystem( direction, parameters.coordinateSystemParameters );
01998 break;
01999 default:
02000 break;
02001 }
02002 }
02003
02004
02005 void CoordinateConversionService::convert(
02006 SourceOrTarget::Enum sourceDirection,
02007 SourceOrTarget::Enum targetDirection,
02008 CoordinateTuple* sourceCoordinates,
02009 Accuracy* sourceAccuracy,
02010 CoordinateTuple& targetCoordinates,
02011 Accuracy& targetAccuracy )
02012 {
02013
02014
02015
02016
02017
02018
02019
02020
02021
02022
02023 CCSThreadLock lock(&mutex);
02024
02025 GeodeticCoordinates* _convertedGeodetic = 0;
02026 GeodeticCoordinates* _wgs84Geodetic = 0;
02027 GeodeticCoordinates* _shiftedGeodetic = 0;
02028
02029 bool special = false;
02030
02031 Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
02032 Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
02033
02034 char sourceWarningMessage[256] = "";
02035 char targetWarningMessage[256] = "";
02036
02037 try
02038 {
02039
02040
02041
02042 if (source->datumIndex == target->datumIndex)
02043 {
02044 if((source->coordinateType == CoordinateType::geocentric) &&
02045 (target->coordinateType == CoordinateType::localCartesian))
02046 {
02047 try
02048 {
02049 special = true;
02050
02051 CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
02052
02053 CartesianCoordinates* cartesianCoordinates =
02054 ((LocalCartesian*)(target->coordinateSystem))->convertFromGeocentric( coordinates );
02055 (dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ) =
02056 *dynamic_cast< CartesianCoordinates* >( cartesianCoordinates );
02057 delete cartesianCoordinates;
02058 }
02059 catch( CoordinateConversionException e )
02060 {
02061 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02062 }
02063 }
02064 else if((source->coordinateType == CoordinateType::localCartesian) &&
02065 (target->coordinateType == CoordinateType::geocentric))
02066 {
02067 try
02068 {
02069 special = true;
02070
02071 CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
02072
02073 CartesianCoordinates* cartesianCoordinates = ((LocalCartesian*)(source->coordinateSystem))->convertToGeocentric( coordinates );
02074 (dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ) = *dynamic_cast< CartesianCoordinates* >( cartesianCoordinates );
02075 delete cartesianCoordinates;
02076 }
02077 catch( CoordinateConversionException e )
02078 {
02079 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02080 }
02081 }
02082 else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
02083 (target->coordinateType == CoordinateType::universalTransverseMercator) &&
02084 (target->parameters.utmParameters->override() == 0))
02085 {
02086 try
02087 {
02088 special = true;
02089
02090 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
02091
02092
02093 UTMCoordinates* utmCoordinates = ((MGRS*)(source->coordinateSystem))->convertToUTM( coordinates );
02094 ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UTMCoordinates* >( utmCoordinates );
02095 delete utmCoordinates;
02096 }
02097 catch( CoordinateConversionException e )
02098 {
02099 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02100 }
02101 }
02102 else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
02103 (target->coordinateType == CoordinateType::universalPolarStereographic))
02104 {
02105 try
02106 {
02107 special = true;
02108
02109 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
02110
02111 UPSCoordinates* upsCoordinates = ((MGRS*)(source->coordinateSystem))->convertToUPS( coordinates );
02112 ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
02113 delete upsCoordinates;
02114 }
02115 catch( CoordinateConversionException e )
02116 {
02117 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02118 }
02119 }
02120 else if ((source->coordinateType == CoordinateType::universalTransverseMercator) &&
02121 (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
02122 {
02123 try
02124 {
02125 special = true;
02126
02127 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
02128 if (temp_precision < 0)
02129 temp_precision = Precision::degree;
02130 if (temp_precision > 5)
02131 temp_precision = Precision::tenthOfSecond;
02132
02133 UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
02134
02135 MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
02136 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
02137 delete mgrsOrUSNGCoordinates;
02138 }
02139 catch( CoordinateConversionException e )
02140 {
02141 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02142 }
02143 }
02144 else if ((source->coordinateType == CoordinateType::universalPolarStereographic) && (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
02145 {
02146 try
02147 {
02148 special = true;
02149
02150 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
02151 if (temp_precision < 0)
02152 temp_precision = Precision::degree;
02153 if (temp_precision > 5)
02154 temp_precision = Precision::tenthOfSecond;
02155
02156 UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
02157
02158 MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUPS( coordinates, temp_precision );
02159 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
02160 delete mgrsOrUSNGCoordinates;
02161
02162 }
02163 catch( CoordinateConversionException e )
02164 {
02165 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02166 }
02167 }
02168 else if ((source->coordinateType == CoordinateType::usNationalGrid) &&
02169 (target->coordinateType == CoordinateType::universalTransverseMercator) && (target->parameters.utmParameters->override() == 0))
02170 {
02171 try
02172 {
02173 special = true;
02174
02175 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
02176
02177 UTMCoordinates* utmCoordinates = ((USNG*)(source->coordinateSystem))->convertToUTM( coordinates );
02178 ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UTMCoordinates* >( utmCoordinates );
02179 delete utmCoordinates;
02180 }
02181 catch( CoordinateConversionException e )
02182 {
02183 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02184 }
02185 }
02186 else if ((source->coordinateType == CoordinateType::usNationalGrid) && (target->coordinateType == CoordinateType::universalPolarStereographic))
02187 {
02188 try
02189 {
02190 special = true;
02191
02192 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
02193
02194 UPSCoordinates* upsCoordinates = ((USNG*)(source->coordinateSystem))->convertToUPS( coordinates );
02195 ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
02196 delete upsCoordinates;
02197 }
02198 catch( CoordinateConversionException e )
02199 {
02200 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02201 }
02202 }
02203 else if ((source->coordinateType == CoordinateType::universalTransverseMercator) && (target->coordinateType == CoordinateType::usNationalGrid))
02204 {
02205 try
02206 {
02207 special = true;
02208
02209 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
02210 if (temp_precision < 0)
02211 temp_precision = Precision::degree;
02212 if (temp_precision > 5)
02213 temp_precision = Precision::tenthOfSecond;
02214
02215 UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
02216
02217 MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((USNG*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
02218 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
02219 delete mgrsOrUSNGCoordinates;
02220 }
02221 catch( CoordinateConversionException e )
02222 {
02223 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02224 }
02225 }
02226 else if ((source->coordinateType == CoordinateType::universalPolarStereographic) && (target->coordinateType == CoordinateType::usNationalGrid))
02227 {
02228 try
02229 {
02230 special = true;
02231
02232 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
02233 if (temp_precision < 0)
02234 temp_precision = Precision::degree;
02235 if (temp_precision > 5)
02236 temp_precision = Precision::tenthOfSecond;
02237
02238 UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
02239
02240 MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((USNG*)(target->coordinateSystem))->convertFromUPS( coordinates, temp_precision );
02241 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
02242 delete mgrsOrUSNGCoordinates;
02243 }
02244 catch( CoordinateConversionException e )
02245 {
02246 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02247 }
02248 }
02249 else if ((source->coordinateType == CoordinateType::transverseMercator) &&
02250 (target->coordinateType == CoordinateType::britishNationalGrid))
02251 {
02252 MapProjection5Parameters* param = source->parameters.mapProjection5Parameters;
02253
02254 if ((param->centralMeridian() == -2.0 * PI / 180) &&
02255 (param->originLatitude() == 49.0 * PI / 180) &&
02256 (param->scaleFactor() == .9996012717) &&
02257 (param->falseEasting() == 400000.0) &&
02258 (param->falseNorthing() == -100000.0))
02259 {
02260 try
02261 {
02262 special = true;
02263
02264 Precision::Enum temp_precision = ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).precision();
02265 if (temp_precision < 0)
02266 temp_precision = Precision::degree;
02267 if (temp_precision > 5)
02268 temp_precision = Precision::tenthOfSecond;
02269
02270 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02271
02272 BNGCoordinates* bngCoordinates = ((BritishNationalGrid*)(target->coordinateSystem))->
02273 convertFromTransverseMercator( coordinates, temp_precision );
02274 ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< BNGCoordinates* >( bngCoordinates );
02275 delete bngCoordinates;
02276 }
02277 catch( CoordinateConversionException e )
02278 {
02279 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02280 }
02281 }
02282 else
02283 special = false;
02284 }
02285 else if ((source->coordinateType == CoordinateType::britishNationalGrid) &&
02286 (target->coordinateType == CoordinateType::transverseMercator))
02287 {
02288 MapProjection5Parameters* param = target->parameters.mapProjection5Parameters;
02289
02290 if ((param->centralMeridian() == -2.0 * PI / 180) &&
02291 (param->originLatitude() == 49.0 * PI / 180) &&
02292 (param->scaleFactor() == .9996012717) &&
02293 (param->falseEasting() == 400000.0) &&
02294 (param->falseNorthing() == -100000.0))
02295 {
02296 try
02297 {
02298 special = true;
02299
02300 BNGCoordinates* coordinates = dynamic_cast< BNGCoordinates* >( sourceCoordinates );
02301
02302 MapProjectionCoordinates* mapProjectionCoordinates = ((BritishNationalGrid*)(source->coordinateSystem))->convertToTransverseMercator( coordinates );
02303 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MapProjectionCoordinates* >( mapProjectionCoordinates );
02304 delete mapProjectionCoordinates;
02305 }
02306 catch( CoordinateConversionException e )
02307 {
02308 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02309 }
02310 }
02311 else
02312 special = false;
02313 }
02314 }
02315
02316 if( !special )
02317 {
02318
02319
02320
02321
02322 _convertedGeodetic = convertSourceToGeodetic( sourceDirection, sourceCoordinates, sourceWarningMessage );
02323
02324
02325
02326
02327
02328
02329 HeightType::Enum input_height_type;
02330 HeightType::Enum output_height_type;
02331
02332 if (source->coordinateType == CoordinateType::geodetic)
02333 input_height_type = source->parameters.geodeticParameters->heightType();
02334 else if ((source->coordinateType == CoordinateType::geocentric) || (source->coordinateType == CoordinateType::localCartesian))
02335 input_height_type = HeightType::ellipsoidHeight;
02336 else
02337 input_height_type = HeightType::noHeight;
02338
02339 if (target->coordinateType == CoordinateType::geodetic)
02340 output_height_type = target->parameters.geodeticParameters->heightType();
02341 else if ((target->coordinateType == CoordinateType::geocentric) || (target->coordinateType == CoordinateType::localCartesian))
02342 output_height_type = HeightType::ellipsoidHeight;
02343 else
02344 output_height_type = HeightType::noHeight;
02345
02346 if ((source->datumIndex == target->datumIndex) &&
02347 ((input_height_type == output_height_type) ||
02348 (input_height_type == HeightType::noHeight) ||
02349 (output_height_type == HeightType::noHeight)))
02350 {
02351 _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
02352 _shiftedGeodetic = new GeodeticCoordinates( *_convertedGeodetic );
02353
02354 if ((input_height_type == HeightType::noHeight) || (output_height_type == HeightType::noHeight))
02355 {
02356 _shiftedGeodetic->setHeight( 0 );
02357 }
02358
02359 if(source->datumIndex != WGS84_datum_index && target->datumIndex != WGS84_datum_index)
02360 {
02361 long valid = 0;
02362
02363
02364 datumLibraryImplementation->validDatum( source->datumIndex, _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(), &valid );
02365 if( !valid )
02366 {
02367 strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
02368 }
02369
02370
02371 datumLibraryImplementation->validDatum( target->datumIndex, _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(), &valid );
02372 if( !valid )
02373 {
02374 strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
02375 }
02376 }
02377 }
02378 else
02379 {
02380 if (source->datumIndex != WGS84_datum_index)
02381 {
02382 _wgs84Geodetic = datumLibraryImplementation->geodeticShiftToWGS84( source->datumIndex, _convertedGeodetic );
02383
02384 switch(input_height_type)
02385 {
02386 case HeightType::EGM2008TwoPtFiveMinBicubicSpline:
02387 case HeightType::EGM96FifteenMinBilinear:
02388 case HeightType::EGM96VariableNaturalSpline:
02389 case HeightType::EGM84TenDegBilinear:
02390 case HeightType::EGM84TenDegNaturalSpline:
02391 case HeightType::EGM84ThirtyMinBiLinear:
02392 _wgs84Geodetic->setHeight( _convertedGeodetic->height() );
02393 break;
02394 case HeightType::noHeight:
02395 _wgs84Geodetic->setHeight( 0.0 );
02396 break;
02397 case HeightType::ellipsoidHeight:
02398 default:
02399 break;
02400 }
02401
02402
02403 long sourceValid = 0;
02404
02405 datumLibraryImplementation->validDatum( source->datumIndex, _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(), &sourceValid );
02406 if( !sourceValid )
02407 {
02408 strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
02409 }
02410 }
02411 else
02412 {
02413 _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
02414 if( input_height_type == HeightType::noHeight )
02415 _wgs84Geodetic->setHeight( 0.0 );
02416 }
02417
02418 if(input_height_type != output_height_type)
02419 {
02420 double tempHeight;
02421
02422
02423 switch(input_height_type)
02424 {
02425 case HeightType::EGM2008TwoPtFiveMinBicubicSpline:
02426 geoidLibrary->convertEGM2008GeoidHeightToEllipsoidHeight(
02427 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02428 _wgs84Geodetic->height(), &tempHeight);
02429 break;
02430 case HeightType::EGM96FifteenMinBilinear:
02431 geoidLibrary->convertEGM96FifteenMinBilinearGeoidToEllipsoidHeight(
02432 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02433 _wgs84Geodetic->height(), &tempHeight);
02434 break;
02435 case HeightType::EGM96VariableNaturalSpline:
02436 geoidLibrary->convertEGM96VariableNaturalSplineToEllipsoidHeight(
02437 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02438 _wgs84Geodetic->height(), &tempHeight );
02439 break;
02440 case HeightType::EGM84TenDegBilinear:
02441 geoidLibrary->convertEGM84TenDegBilinearToEllipsoidHeight(
02442 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02443 _wgs84Geodetic->height(), &tempHeight );
02444 break;
02445 case HeightType::EGM84TenDegNaturalSpline:
02446 geoidLibrary->convertEGM84TenDegNaturalSplineToEllipsoidHeight(
02447 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02448 _wgs84Geodetic->height(), &tempHeight );
02449 break;
02450 case HeightType::EGM84ThirtyMinBiLinear:
02451 geoidLibrary->convertEGM84ThirtyMinBiLinearToEllipsoidHeight(
02452 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02453 _wgs84Geodetic->height(), &tempHeight );
02454 break;
02455 case HeightType::ellipsoidHeight:
02456 default:
02457 tempHeight = _wgs84Geodetic->height();
02458 break;
02459 }
02460
02461 double correctedHeight;
02462
02463
02464 switch(output_height_type)
02465 {
02466 case HeightType::EGM2008TwoPtFiveMinBicubicSpline:
02467 geoidLibrary->convertEllipsoidHeightToEGM2008GeoidHeight(
02468 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02469 tempHeight, &correctedHeight );
02470 break;
02471 case HeightType::EGM96FifteenMinBilinear:
02472 geoidLibrary->convertEllipsoidToEGM96FifteenMinBilinearGeoidHeight(
02473 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02474 tempHeight, &correctedHeight );
02475 break;
02476 case HeightType::EGM96VariableNaturalSpline:
02477 geoidLibrary->convertEllipsoidToEGM96VariableNaturalSplineHeight(
02478 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02479 tempHeight, &correctedHeight );
02480 break;
02481 case HeightType::EGM84TenDegBilinear:
02482 geoidLibrary->convertEllipsoidToEGM84TenDegBilinearHeight(
02483 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02484 tempHeight, &correctedHeight );
02485 break;
02486 case HeightType::EGM84TenDegNaturalSpline:
02487 geoidLibrary->convertEllipsoidToEGM84TenDegNaturalSplineHeight(
02488 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02489 tempHeight, &correctedHeight );
02490 break;
02491 case HeightType::EGM84ThirtyMinBiLinear:
02492 geoidLibrary->convertEllipsoidToEGM84ThirtyMinBiLinearHeight(
02493 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02494 tempHeight, &correctedHeight );
02495 break;
02496 case HeightType::ellipsoidHeight:
02497 default:
02498 correctedHeight = tempHeight;
02499 break;
02500 }
02501
02502
02503 _wgs84Geodetic->setHeight( correctedHeight );
02504 }
02505
02506 if (target->datumIndex != WGS84_datum_index)
02507 {
02508 _shiftedGeodetic = datumLibraryImplementation->geodeticShiftFromWGS84( _wgs84Geodetic, target->datumIndex );
02509
02510 switch(output_height_type)
02511 {
02512 case HeightType::EGM2008TwoPtFiveMinBicubicSpline:
02513 case HeightType::EGM96FifteenMinBilinear:
02514 case HeightType::EGM96VariableNaturalSpline:
02515 case HeightType::EGM84TenDegBilinear:
02516 case HeightType::EGM84TenDegNaturalSpline:
02517 case HeightType::EGM84ThirtyMinBiLinear:
02518 _shiftedGeodetic->setHeight( _wgs84Geodetic->height() );
02519 break;
02520 case HeightType::noHeight:
02521 _shiftedGeodetic->setHeight( 0.0 );
02522 break;
02523 case HeightType::ellipsoidHeight:
02524 default:
02525 break;
02526 }
02527
02528
02529 long targetValid = 0;
02530
02531 datumLibraryImplementation->validDatum(
02532 target->datumIndex, _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
02533 &targetValid );
02534 if( !targetValid )
02535 {
02536 strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
02537 }
02538 }
02539 else
02540 {
02541 _shiftedGeodetic = new GeodeticCoordinates( *_wgs84Geodetic );
02542 if( output_height_type == HeightType::noHeight )
02543 _shiftedGeodetic->setHeight( 0.0 );
02544 }
02545 }
02546
02547
02548 if( strlen( sourceWarningMessage ) > 0 || strlen( targetWarningMessage ) > 0 )
02549 targetAccuracy.set(-1.0, -1.0, -1.0);
02550 else
02551 {
02552 Accuracy* _targetAccuracy = datumLibraryImplementation->datumShiftError(
02553 source->datumIndex, target->datumIndex,
02554 _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(), sourceAccuracy );
02555
02556 targetAccuracy.set(
02557 _targetAccuracy->circularError90(),
02558 _targetAccuracy->linearError90(),
02559 _targetAccuracy->sphericalError90() );
02560
02561 delete _targetAccuracy;
02562 }
02563
02564
02565
02566
02567
02568 convertGeodeticToTarget( targetDirection, _shiftedGeodetic, targetCoordinates, targetWarningMessage );
02569
02570
02571 char warningMessage[500] = "";
02572 bool warning = false;
02573 if( strlen( sourceWarningMessage ) > 0 )
02574 {
02575 strcpy( warningMessage, "Input " );
02576 strcat( warningMessage, Coordinate_System_Table[source->coordinateType].Name );
02577 strcat( warningMessage, ": \n" );
02578 strcat( warningMessage, sourceWarningMessage );
02579 warning = true;
02580 }
02581
02582 if( strlen( targetWarningMessage ) > 0 )
02583 {
02584 if( strlen( warningMessage ) > 0 )
02585 strcat( warningMessage, "\nOutput " );
02586 else
02587 strcpy( warningMessage, "Output " );
02588
02589 strcat( warningMessage, Coordinate_System_Table[target->coordinateType].Name );
02590 strcat( warningMessage, ": \n" );
02591 strcat( warningMessage, targetWarningMessage );
02592 warning = true;
02593 }
02594
02595 if( warning )
02596 {
02597 warningMessage[strlen( warningMessage )] = '\0';
02598 targetCoordinates.setWarningMessage(warningMessage);
02599 }
02600 }
02601 }
02602 catch(CoordinateConversionException e)
02603 {
02604 targetAccuracy.set(-1.0, -1.0, -1.0);
02605
02606
02607
02608 delete _convertedGeodetic;
02609 delete _shiftedGeodetic;
02610 delete _wgs84Geodetic;
02611
02612 throw CoordinateConversionException(e.getMessage());
02613 }
02614
02615
02616 delete _convertedGeodetic;
02617 delete _shiftedGeodetic;
02618 delete _wgs84Geodetic;
02619
02620 }
02621
02622
02623 GeodeticCoordinates* CoordinateConversionService::convertSourceToGeodetic(
02624 SourceOrTarget::Enum sourceDirection,
02625 CoordinateTuple* sourceCoordinates,
02626 char* sourceWarningMessage )
02627 {
02628 Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
02629
02630
02631
02632
02633 switch (source->coordinateType)
02634 {
02635 case CoordinateType::geocentric:
02636 {
02637 try
02638 {
02639 CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
02640
02641 return ((Geocentric*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02642 }
02643 catch( CoordinateConversionException e )
02644 {
02645 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02646 }
02647 }
02648 case CoordinateType::geodetic:
02649 {
02650 try
02651 {
02652 GeodeticCoordinates* _convertedGeodetic = new GeodeticCoordinates( *dynamic_cast< GeodeticCoordinates* >( sourceCoordinates ) );
02653
02654 if( source->parameters.geodeticParameters->heightType() == HeightType::noHeight )
02655 _convertedGeodetic->setHeight( 0.0 );
02656
02657 return _convertedGeodetic;
02658 }
02659 catch( CoordinateConversionException e )
02660 {
02661 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02662 }
02663 }
02664 case CoordinateType::georef:
02665 {
02666 try
02667 {
02668 GEOREFCoordinates* coordinates = dynamic_cast< GEOREFCoordinates* >( sourceCoordinates );
02669
02670 return ((GEOREF*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02671 }
02672 catch( CoordinateConversionException e )
02673 {
02674 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02675 }
02676 }
02677 case CoordinateType::albersEqualAreaConic:
02678 {
02679 try
02680 {
02681 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02682
02683 return ((AlbersEqualAreaConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02684 }
02685 catch( CoordinateConversionException e )
02686 {
02687 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02688 }
02689 }
02690 case CoordinateType::azimuthalEquidistant:
02691 {
02692 try
02693 {
02694 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02695
02696 return ((AzimuthalEquidistant*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02697 }
02698 catch( CoordinateConversionException e )
02699 {
02700 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02701 }
02702 }
02703 case CoordinateType::britishNationalGrid:
02704 {
02705 try
02706 {
02707 BNGCoordinates* coordinates = dynamic_cast< BNGCoordinates* >( sourceCoordinates );
02708
02709 return ((BritishNationalGrid*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02710 }
02711 catch( CoordinateConversionException e )
02712 {
02713 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02714 }
02715 }
02716 case CoordinateType::bonne:
02717 {
02718 try
02719 {
02720 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02721
02722 return ((Bonne*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02723 }
02724 catch( CoordinateConversionException e )
02725 {
02726 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02727 }
02728 }
02729 case CoordinateType::cassini:
02730 {
02731 try
02732 {
02733 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02734
02735 GeodeticCoordinates* _convertedGeodetic = ((Cassini*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02736
02737 if( strlen( _convertedGeodetic->warningMessage() ) > 0)
02738 strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
02739
02740 return _convertedGeodetic;
02741 }
02742 catch( CoordinateConversionException e )
02743 {
02744 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02745 }
02746 }
02747 case CoordinateType::cylindricalEqualArea:
02748 {
02749 try
02750 {
02751 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02752
02753 return ((CylindricalEqualArea*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02754 }
02755 catch( CoordinateConversionException e )
02756 {
02757 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02758 }
02759 }
02760 case CoordinateType::eckert4:
02761 {
02762 try
02763 {
02764 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02765
02766 return ((Eckert4*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02767 }
02768 catch( CoordinateConversionException e )
02769 {
02770 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02771 }
02772 }
02773 case CoordinateType::eckert6:
02774 {
02775 try
02776 {
02777 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02778
02779 return ((Eckert6*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02780 }
02781 catch( CoordinateConversionException e )
02782 {
02783 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02784 }
02785 }
02786 case CoordinateType::equidistantCylindrical:
02787 {
02788 try
02789 {
02790 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02791
02792 return ((EquidistantCylindrical*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02793 }
02794 catch( CoordinateConversionException e )
02795 {
02796 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02797 }
02798 }
02799 case CoordinateType::globalAreaReferenceSystem:
02800 {
02801 try
02802 {
02803 GARSCoordinates* coordinates = dynamic_cast< GARSCoordinates* >( sourceCoordinates );
02804
02805 return ((GARS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02806 }
02807 catch( CoordinateConversionException e )
02808 {
02809 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02810 }
02811 }
02812 case CoordinateType::gnomonic:
02813 {
02814 try
02815 {
02816 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02817
02818 return ((Gnomonic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02819 }
02820 catch( CoordinateConversionException e )
02821 {
02822 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02823 }
02824 }
02825 case CoordinateType::lambertConformalConic1Parallel:
02826 {
02827 try
02828 {
02829 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02830
02831 return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02832 }
02833 catch( CoordinateConversionException e )
02834 {
02835 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02836 }
02837 }
02838 case CoordinateType::lambertConformalConic2Parallels:
02839 {
02840 try
02841 {
02842 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02843
02844 return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02845 }
02846 catch( CoordinateConversionException e )
02847 {
02848 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02849 }
02850 }
02851 case CoordinateType::localCartesian:
02852 {
02853 try
02854 {
02855 CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
02856
02857 return ((LocalCartesian*)(source->coordinateSystem))->convertToGeodetic( coordinates);
02858 }
02859 catch( CoordinateConversionException e )
02860 {
02861 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02862 }
02863 }
02864 case CoordinateType::mercatorStandardParallel:
02865 case CoordinateType::mercatorScaleFactor:
02866 {
02867 try
02868 {
02869 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02870
02871 return ((Mercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02872 }
02873 catch( CoordinateConversionException e )
02874 {
02875 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02876 }
02877 }
02878 case CoordinateType::militaryGridReferenceSystem:
02879 {
02880 try
02881 {
02882 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
02883
02884 GeodeticCoordinates* _convertedGeodetic = ((MGRS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02885
02886 if( strlen( _convertedGeodetic->warningMessage() ) > 0)
02887 strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
02888
02889 return _convertedGeodetic;
02890 }
02891 catch( CoordinateConversionException e )
02892 {
02893 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02894 }
02895 }
02896 case CoordinateType::millerCylindrical:
02897 {
02898 try
02899 {
02900 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02901
02902 return ((MillerCylindrical*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02903 }
02904 catch( CoordinateConversionException e )
02905 {
02906 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02907 }
02908 }
02909 case CoordinateType::mollweide:
02910 {
02911 try
02912 {
02913 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02914
02915 return ((Mollweide*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02916 }
02917 catch( CoordinateConversionException e )
02918 {
02919 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02920 }
02921 }
02922 case CoordinateType::neys:
02923 {
02924 try
02925 {
02926 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02927
02928 return ((Neys*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02929 }
02930 catch( CoordinateConversionException e )
02931 {
02932 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02933 }
02934 }
02935 case CoordinateType::newZealandMapGrid:
02936 {
02937 try
02938 {
02939 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02940
02941 return ((NZMG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02942 }
02943 catch( CoordinateConversionException e )
02944 {
02945 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02946 }
02947 }
02948 case CoordinateType::obliqueMercator:
02949 {
02950 try
02951 {
02952 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02953
02954 GeodeticCoordinates* _convertedGeodetic = ((ObliqueMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02955
02956 if( strlen( _convertedGeodetic->warningMessage() ) > 0)
02957 strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
02958
02959 return _convertedGeodetic;
02960 }
02961 catch( CoordinateConversionException e )
02962 {
02963 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02964 }
02965 }
02966 case CoordinateType::orthographic:
02967 {
02968 try
02969 {
02970 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02971
02972 return ((Orthographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02973 }
02974 catch( CoordinateConversionException e )
02975 {
02976 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02977 }
02978 }
02979 case CoordinateType::polarStereographicStandardParallel:
02980 case CoordinateType::polarStereographicScaleFactor:
02981 {
02982 try
02983 {
02984 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02985
02986 return ((PolarStereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
02987 }
02988 catch( CoordinateConversionException e )
02989 {
02990 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
02991 }
02992 }
02993 case CoordinateType::polyconic:
02994 {
02995 try
02996 {
02997 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
02998
02999 return ((Polyconic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03000 }
03001 catch( CoordinateConversionException e )
03002 {
03003 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03004 }
03005 }
03006 case CoordinateType::sinusoidal:
03007 {
03008 try
03009 {
03010 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
03011
03012 return ((Sinusoidal*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03013 }
03014 catch( CoordinateConversionException e )
03015 {
03016 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03017 }
03018 }
03019 case CoordinateType::stereographic:
03020 {
03021 try
03022 {
03023 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
03024
03025 return ((Stereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03026 }
03027 catch( CoordinateConversionException e )
03028 {
03029 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03030 }
03031 }
03032 case CoordinateType::transverseCylindricalEqualArea:
03033 {
03034 try
03035 {
03036 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
03037
03038 return ((TransverseCylindricalEqualArea*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03039 }
03040 catch( CoordinateConversionException e )
03041 {
03042 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03043 }
03044 }
03045 case CoordinateType::transverseMercator:
03046 {
03047 try
03048 {
03049 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
03050
03051 GeodeticCoordinates* _convertedGeodetic = ((TransverseMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03052
03053 if( strlen( _convertedGeodetic->warningMessage() ) > 0)
03054 strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
03055
03056 return _convertedGeodetic;
03057 }
03058 catch( CoordinateConversionException e )
03059 {
03060 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03061 }
03062 }
03063 case CoordinateType::universalPolarStereographic:
03064 {
03065 try
03066 {
03067 UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
03068
03069 return ((UPS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03070 }
03071 catch( CoordinateConversionException e )
03072 {
03073 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03074 }
03075 }
03076 case CoordinateType::usNationalGrid:
03077 {
03078 try
03079 {
03080 MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
03081
03082 GeodeticCoordinates* _convertedGeodetic = ((USNG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03083
03084 if( strlen( _convertedGeodetic->warningMessage() ) > 0)
03085 strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
03086
03087 return _convertedGeodetic;
03088 }
03089 catch( CoordinateConversionException e )
03090 {
03091 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03092 }
03093 }
03094 case CoordinateType::universalTransverseMercator:
03095 {
03096 try
03097 {
03098 UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
03099
03100 return ((UTM*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03101 }
03102 catch( CoordinateConversionException e )
03103 {
03104 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03105 }
03106 }
03107 case CoordinateType::vanDerGrinten:
03108 {
03109 try
03110 {
03111 MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
03112
03113 return ((VanDerGrinten*)(source->coordinateSystem))->convertToGeodetic( coordinates );
03114 }
03115 catch( CoordinateConversionException e )
03116 {
03117 throw CoordinateConversionException( "Input ", Coordinate_System_Table[source->coordinateType].Name, ": \n", e.getMessage() );
03118 }
03119 }
03120 }
03121 }
03122
03123
03124 void CoordinateConversionService::convertGeodeticToTarget( SourceOrTarget::Enum targetDirection, GeodeticCoordinates* _shiftedGeodetic, CoordinateTuple& targetCoordinates, char* targetWarningMessage )
03125 {
03126 Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
03127
03128
03129
03130
03131 switch (target->coordinateType)
03132 {
03133 case CoordinateType::geocentric:
03134 {
03135 try
03136 {
03137 CartesianCoordinates* coordinates = ((Geocentric*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03138
03139 ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set( coordinates->x(), coordinates->y(), coordinates->z() );
03140
03141 delete coordinates;
03142 }
03143 catch( CoordinateConversionException e )
03144 {
03145 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03146 }
03147
03148 break;
03149 }
03150 case CoordinateType::geodetic:
03151 {
03152 if (target->parameters.geodeticParameters->heightType() == HeightType::noHeight)
03153 ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set( _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(), 0.0 );
03154 else
03155 ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set( _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(), _shiftedGeodetic->height() );
03156
03157 break;
03158 }
03159 case CoordinateType::georef:
03160 {
03161 try
03162 {
03163 Precision::Enum temp_precision = ( dynamic_cast< GEOREFCoordinates& >( targetCoordinates ) ).precision();
03164 if (temp_precision < 0)
03165 temp_precision = Precision::degree;
03166 if (temp_precision > 5)
03167 temp_precision = Precision::tenthOfSecond;
03168
03169 GEOREFCoordinates* coordinates = ((GEOREF*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic, temp_precision );
03170
03171 ( dynamic_cast< GEOREFCoordinates& >( targetCoordinates ) ).set( coordinates->GEOREFString() );
03172
03173 delete coordinates;
03174 }
03175 catch( CoordinateConversionException e )
03176 {
03177 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03178 }
03179
03180 break;
03181 }
03182 case CoordinateType::albersEqualAreaConic:
03183 {
03184 try
03185 {
03186 MapProjectionCoordinates* coordinates = ((AlbersEqualAreaConic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03187
03188 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03189
03190 delete coordinates;
03191 }
03192 catch( CoordinateConversionException e )
03193 {
03194 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03195 }
03196
03197 break;
03198 }
03199 case CoordinateType::azimuthalEquidistant:
03200 {
03201 try
03202 {
03203 MapProjectionCoordinates* coordinates = ((AzimuthalEquidistant*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03204
03205 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03206
03207 delete coordinates;
03208 }
03209 catch( CoordinateConversionException e )
03210 {
03211 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03212 }
03213
03214 break;
03215 }
03216 case CoordinateType::britishNationalGrid:
03217 {
03218 try
03219 {
03220 Precision::Enum temp_precision = ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).precision();
03221 if (temp_precision < 0)
03222 temp_precision = Precision::degree;
03223 if (temp_precision > 5)
03224 temp_precision = Precision::tenthOfSecond;
03225
03226 BNGCoordinates* coordinates = ((BritishNationalGrid*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic, temp_precision );
03227
03228 ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).set( coordinates->BNGString() );
03229
03230 delete coordinates;
03231 }
03232 catch( CoordinateConversionException e )
03233 {
03234 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03235 }
03236
03237 break;
03238 }
03239 case CoordinateType::bonne:
03240 {
03241 try
03242 {
03243 MapProjectionCoordinates* coordinates = ((Bonne*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03244
03245 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03246
03247 delete coordinates;
03248 }
03249 catch( CoordinateConversionException e )
03250 {
03251 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03252 }
03253
03254 break;
03255 }
03256 case CoordinateType::cassini:
03257 {
03258 try
03259 {
03260 MapProjectionCoordinates* coordinates = ((Cassini*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03261
03262 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03263
03264 if( strlen( coordinates->warningMessage() ) > 0)
03265 {
03266 targetCoordinates.setWarningMessage( coordinates->warningMessage() );
03267 strcat( targetWarningMessage, targetCoordinates.warningMessage() );
03268 }
03269
03270 delete coordinates;
03271 }
03272 catch( CoordinateConversionException e )
03273 {
03274 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03275 }
03276
03277 break;
03278 }
03279 case CoordinateType::cylindricalEqualArea:
03280 {
03281 try
03282 {
03283 MapProjectionCoordinates* coordinates = ((CylindricalEqualArea*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03284
03285 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03286
03287 delete coordinates;
03288 }
03289 catch( CoordinateConversionException e )
03290 {
03291 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03292 }
03293
03294 break;
03295 }
03296 case CoordinateType::eckert4:
03297 {
03298 try
03299 {
03300 MapProjectionCoordinates* coordinates = ((Eckert4*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03301
03302 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03303
03304 delete coordinates;
03305 }
03306 catch( CoordinateConversionException e )
03307 {
03308 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03309 }
03310
03311 break;
03312 }
03313 case CoordinateType::eckert6:
03314 {
03315 try
03316 {
03317 MapProjectionCoordinates* coordinates = ((Eckert6*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03318
03319 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03320
03321 delete coordinates;
03322 }
03323 catch( CoordinateConversionException e )
03324 {
03325 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03326 }
03327
03328 break;
03329 }
03330 case CoordinateType::equidistantCylindrical:
03331 {
03332 try
03333 {
03334 MapProjectionCoordinates* coordinates = ((EquidistantCylindrical*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03335
03336 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03337
03338 delete coordinates;
03339 }
03340 catch( CoordinateConversionException e )
03341 {
03342 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03343 }
03344
03345 break;
03346 }
03347 case CoordinateType::globalAreaReferenceSystem:
03348 {
03349 try
03350 {
03351 Precision::Enum temp_precision = ( dynamic_cast< GARSCoordinates& >( targetCoordinates ) ).precision();
03352 if (temp_precision < 0)
03353 temp_precision = Precision::degree;
03354 if (temp_precision > 5)
03355 temp_precision = Precision::tenthOfSecond;
03356
03357 GARSCoordinates* coordinates = ((GARS*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic, temp_precision );
03358
03359 ( dynamic_cast< GARSCoordinates& >( targetCoordinates ) ).set( coordinates->GARSString() );
03360
03361 delete coordinates;
03362 }
03363 catch( CoordinateConversionException e )
03364 {
03365 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03366 }
03367
03368 break;
03369 }
03370 case CoordinateType::gnomonic:
03371 {
03372 try
03373 {
03374 MapProjectionCoordinates* coordinates = ((Gnomonic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03375
03376 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03377
03378 delete coordinates;
03379 }
03380 catch( CoordinateConversionException e )
03381 {
03382 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03383 }
03384
03385 break;
03386 }
03387 case CoordinateType::lambertConformalConic1Parallel:
03388 {
03389 try
03390 {
03391 MapProjectionCoordinates* coordinates = ((LambertConformalConic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03392
03393 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03394
03395 delete coordinates;
03396 }
03397 catch( CoordinateConversionException e )
03398 {
03399 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03400 }
03401
03402 break;
03403 }
03404 case CoordinateType::lambertConformalConic2Parallels:
03405 {
03406 try
03407 {
03408
03409 MapProjectionCoordinates* coordinates = ((LambertConformalConic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03410
03411 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03412
03413 delete coordinates;
03414 }
03415 catch( CoordinateConversionException e )
03416 {
03417 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03418 }
03419
03420 break;
03421 }
03422 case CoordinateType::localCartesian:
03423 {
03424 try
03425 {
03426 CartesianCoordinates* coordinates = ((LocalCartesian*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03427
03428 ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set( coordinates->x(), coordinates->y(), coordinates->z() );
03429
03430 delete coordinates;
03431 }
03432 catch( CoordinateConversionException e )
03433 {
03434 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03435 }
03436
03437 break;
03438 }
03439 case CoordinateType::mercatorStandardParallel:
03440 case CoordinateType::mercatorScaleFactor:
03441 {
03442 try
03443 {
03444 MapProjectionCoordinates* coordinates = ((Mercator*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03445
03446 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03447
03448 delete coordinates;
03449 }
03450 catch( CoordinateConversionException e )
03451 {
03452 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03453 }
03454
03455 break;
03456 }
03457 case CoordinateType::militaryGridReferenceSystem:
03458 {
03459 try
03460 {
03461 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
03462
03463 if (temp_precision < 0)
03464 temp_precision = Precision::degree;
03465 if (temp_precision > 5)
03466 temp_precision = Precision::tenthOfSecond;
03467 MGRSorUSNGCoordinates* coordinates = ((MGRS*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic, temp_precision );
03468
03469 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set( coordinates->MGRSString() );
03470
03471 delete coordinates;
03472 }
03473 catch( CoordinateConversionException e )
03474 {
03475 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03476 }
03477
03478 break;
03479 }
03480 case CoordinateType::millerCylindrical:
03481 {
03482 try
03483 {
03484 MapProjectionCoordinates* coordinates = ((MillerCylindrical*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03485
03486 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03487
03488 delete coordinates;
03489 }
03490 catch( CoordinateConversionException e )
03491 {
03492 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03493 }
03494
03495 break;
03496 }
03497 case CoordinateType::mollweide:
03498 {
03499 try
03500 {
03501 MapProjectionCoordinates* coordinates = ((Mollweide*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03502
03503 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03504
03505 delete coordinates;
03506 }
03507 catch( CoordinateConversionException e )
03508 {
03509 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03510 }
03511
03512 break;
03513 }
03514 case CoordinateType::neys:
03515 {
03516 try
03517 {
03518 MapProjectionCoordinates* coordinates = ((Neys*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03519
03520 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03521
03522 delete coordinates;
03523 }
03524 catch( CoordinateConversionException e )
03525 {
03526 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03527 }
03528
03529 break;
03530 }
03531 case CoordinateType::newZealandMapGrid:
03532 {
03533 try
03534 {
03535 MapProjectionCoordinates* coordinates = ((NZMG*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03536
03537 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03538
03539 delete coordinates;
03540 }
03541 catch( CoordinateConversionException e )
03542 {
03543 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03544 }
03545
03546 break;
03547 }
03548 case CoordinateType::obliqueMercator:
03549 {
03550 try
03551 {
03552 MapProjectionCoordinates* coordinates = ((ObliqueMercator*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03553
03554 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03555
03556 if( strlen( coordinates->warningMessage() ) > 0)
03557 {
03558 targetCoordinates.setWarningMessage( coordinates->warningMessage() );
03559 strcat( targetWarningMessage, targetCoordinates.warningMessage() );
03560 }
03561
03562 delete coordinates;
03563 }
03564 catch( CoordinateConversionException e )
03565 {
03566 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03567 }
03568
03569 break;
03570 }
03571 case CoordinateType::orthographic:
03572 {
03573 try
03574 {
03575 MapProjectionCoordinates* coordinates = ((Orthographic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03576
03577 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03578
03579 delete coordinates;
03580 }
03581 catch( CoordinateConversionException e )
03582 {
03583 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03584 }
03585
03586 break;
03587 }
03588 case CoordinateType::polarStereographicStandardParallel:
03589 case CoordinateType::polarStereographicScaleFactor:
03590 {
03591 try
03592 {
03593 MapProjectionCoordinates* coordinates = ((PolarStereographic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03594
03595 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03596
03597 delete coordinates;
03598 }
03599 catch( CoordinateConversionException e )
03600 {
03601 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03602 }
03603
03604 break;
03605 }
03606 case CoordinateType::polyconic:
03607 {
03608 try
03609 {
03610 MapProjectionCoordinates* coordinates = ((Polyconic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03611
03612 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03613
03614 if( strlen( coordinates->warningMessage() ) > 0)
03615 {
03616 targetCoordinates.setWarningMessage( coordinates->warningMessage() );
03617 strcat( targetWarningMessage, targetCoordinates.warningMessage() );
03618 }
03619
03620 delete coordinates;
03621 }
03622 catch( CoordinateConversionException e )
03623 {
03624 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03625 }
03626
03627 break;
03628 }
03629 case CoordinateType::sinusoidal:
03630 {
03631 try
03632 {
03633 MapProjectionCoordinates* coordinates = ((Sinusoidal*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03634
03635 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03636
03637 delete coordinates;
03638 }
03639 catch( CoordinateConversionException e )
03640 {
03641 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03642 }
03643
03644 break;
03645 }
03646 case CoordinateType::stereographic:
03647 {
03648 try
03649 {
03650 MapProjectionCoordinates* coordinates = ((Stereographic*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03651
03652 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03653
03654 delete coordinates;
03655 }
03656 catch( CoordinateConversionException e )
03657 {
03658 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03659 }
03660
03661 break;
03662 }
03663 case CoordinateType::transverseCylindricalEqualArea:
03664 {
03665 try
03666 {
03667 MapProjectionCoordinates* coordinates = ((TransverseCylindricalEqualArea*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03668
03669 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03670
03671 if( strlen( coordinates->warningMessage() ) > 0)
03672 {
03673 targetCoordinates.setWarningMessage( coordinates->warningMessage() );
03674 strcat( targetWarningMessage, targetCoordinates.warningMessage() );
03675 }
03676
03677 delete coordinates;
03678 }
03679 catch( CoordinateConversionException e )
03680 {
03681 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03682 }
03683
03684 break;
03685 }
03686 case CoordinateType::transverseMercator:
03687 {
03688 try
03689 {
03690 MapProjectionCoordinates* coordinates = ((TransverseMercator*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03691
03692 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03693
03694 if( strlen( coordinates->warningMessage() ) > 0)
03695 {
03696 targetCoordinates.setWarningMessage( coordinates->warningMessage() );
03697 strcat( targetWarningMessage, targetCoordinates.warningMessage() );
03698 }
03699
03700 delete coordinates;
03701 }
03702 catch( CoordinateConversionException e )
03703 {
03704 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03705 }
03706
03707 break;
03708 }
03709 case CoordinateType::universalPolarStereographic:
03710 {
03711 try
03712 {
03713 UPSCoordinates* coordinates = ((UPS*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03714
03715 ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ).set( coordinates->hemisphere(), coordinates->easting(), coordinates->northing() );
03716
03717 delete coordinates;
03718 }
03719 catch( CoordinateConversionException e )
03720 {
03721 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03722 }
03723
03724 break;
03725 }
03726 case CoordinateType::usNationalGrid:
03727 {
03728 try
03729 {
03730 Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
03731 if (temp_precision < 0)
03732 temp_precision = Precision::degree;
03733 if (temp_precision > 5)
03734 temp_precision = Precision::tenthOfSecond;
03735
03736 MGRSorUSNGCoordinates* coordinates = ((USNG*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic, temp_precision );
03737
03738 ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set( coordinates->MGRSString() );
03739
03740 delete coordinates;
03741 }
03742 catch( CoordinateConversionException e )
03743 {
03744 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03745 }
03746
03747 break;
03748 }
03749 case CoordinateType::universalTransverseMercator:
03750 {
03751 try
03752 {
03753 UTMCoordinates* coordinates = ((UTM*)(target->coordinateSystem))->convertFromGeodetic(
03754 _shiftedGeodetic );
03755
03756 ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ).set( coordinates->zone(), coordinates->hemisphere(), coordinates->easting(), coordinates->northing() );
03757
03758 delete coordinates;
03759 }
03760 catch( CoordinateConversionException e )
03761 {
03762 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03763 }
03764
03765 break;
03766 }
03767 case CoordinateType::vanDerGrinten:
03768 {
03769 try
03770 {
03771 MapProjectionCoordinates* coordinates = ((VanDerGrinten*)(target->coordinateSystem))->convertFromGeodetic( _shiftedGeodetic );
03772
03773 ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set( coordinates->easting(), coordinates->northing() );
03774
03775 delete coordinates;
03776 }
03777 catch( CoordinateConversionException e )
03778 {
03779 throw CoordinateConversionException( "Output ", Coordinate_System_Table[target->coordinateType].Name, ": \n", e.getMessage() );
03780 }
03781
03782 break;
03783 }
03784 }
03785 }
03786
03787
03788 void CoordinateConversionService::convertCollection(
03789 const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinatesCollection,
03790 const std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection,
03791 std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinatesCollection,
03792 std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection )
03793 {
03794
03795
03796
03797
03798
03799
03800
03801
03802
03803
03804 int num = sourceCoordinatesCollection.size();
03805 int numTargetCoordinates = targetCoordinatesCollection.size();
03806 int numTargetAccuracies = targetAccuracyCollection.size();
03807 CoordinateType::Enum targetCoordinateType = coordinateSystemState[SourceOrTarget::target].coordinateType;
03808
03809 CoordinateTuple* _targetCoordinates = 0;
03810 Accuracy* _targetAccuracy;
03811
03812 for( int i = 0; i < num; i++ )
03813 {
03814 CoordinateTuple* _sourceCoordinates = sourceCoordinatesCollection[i];
03815 Accuracy* _sourceAccuracy = sourceAccuracyCollection[i];
03816
03817 bool targetCoordinateExists = true;
03818 bool targetAccuracyExists = true;
03819
03820 if(i < numTargetAccuracies)
03821 _targetAccuracy = targetAccuracyCollection[i];
03822 else
03823 {
03824 _targetAccuracy = new Accuracy();
03825 targetAccuracyExists = false;
03826 }
03827
03828 if( _sourceCoordinates && _sourceAccuracy )
03829 {
03830 switch(targetCoordinateType)
03831 {
03832 case CoordinateType::albersEqualAreaConic:
03833 {
03834 if(i < numTargetCoordinates)
03835 _targetCoordinates = targetCoordinatesCollection[i];
03836 else
03837 {
03838 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::albersEqualAreaConic);
03839 targetCoordinateExists = false;
03840 }
03841 try
03842 {
03843 convert(
03844 SourceOrTarget::source,
03845 SourceOrTarget::target,
03846 sourceCoordinatesCollection[i],
03847 sourceAccuracyCollection[i],
03848 *_targetCoordinates, *_targetAccuracy);
03849 }
03850 catch(CoordinateConversionException e)
03851 {
03852 _targetCoordinates->setErrorMessage(e.getMessage());
03853 }
03854
03855 if(!targetCoordinateExists)
03856 targetCoordinatesCollection.push_back(_targetCoordinates);
03857 break;
03858 }
03859 case CoordinateType::azimuthalEquidistant:
03860 {
03861 if(i < numTargetCoordinates)
03862 _targetCoordinates = targetCoordinatesCollection[i];
03863 else
03864 {
03865 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::azimuthalEquidistant);
03866 targetCoordinateExists = false;
03867 }
03868 try
03869 {
03870 convert(
03871 SourceOrTarget::source,
03872 SourceOrTarget::target,
03873 sourceCoordinatesCollection[i],
03874 sourceAccuracyCollection[i],
03875 *_targetCoordinates, *_targetAccuracy);
03876 }
03877 catch(CoordinateConversionException e)
03878 {
03879 _targetCoordinates->setErrorMessage(e.getMessage());
03880 }
03881
03882 if(!targetCoordinateExists)
03883 targetCoordinatesCollection.push_back(_targetCoordinates);
03884 break;
03885 }
03886 case CoordinateType::bonne:
03887 {
03888 if(i < numTargetCoordinates)
03889 _targetCoordinates = targetCoordinatesCollection[i];
03890 else
03891 {
03892 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::bonne);
03893 targetCoordinateExists = false;
03894 }
03895 try
03896 {
03897 convert(
03898 SourceOrTarget::source,
03899 SourceOrTarget::target,
03900 sourceCoordinatesCollection[i],
03901 sourceAccuracyCollection[i],
03902 *_targetCoordinates, *_targetAccuracy);
03903 }
03904 catch(CoordinateConversionException e)
03905 {
03906 _targetCoordinates->setErrorMessage(e.getMessage());
03907 }
03908
03909 if(!targetCoordinateExists)
03910 targetCoordinatesCollection.push_back(_targetCoordinates);
03911 break;
03912 }
03913 case CoordinateType::britishNationalGrid:
03914 {
03915 if(i < numTargetCoordinates)
03916 _targetCoordinates = targetCoordinatesCollection[i];
03917 else
03918 {
03919 _targetCoordinates = new BNGCoordinates(CoordinateType::britishNationalGrid);
03920 targetCoordinateExists = false;
03921 }
03922 try
03923 {
03924 convert(
03925 SourceOrTarget::source,
03926 SourceOrTarget::target,
03927 sourceCoordinatesCollection[i],
03928 sourceAccuracyCollection[i],
03929 *_targetCoordinates, *_targetAccuracy);
03930 }
03931 catch(CoordinateConversionException e)
03932 {
03933 _targetCoordinates->setErrorMessage(e.getMessage());
03934 }
03935
03936 if(!targetCoordinateExists)
03937 targetCoordinatesCollection.push_back(_targetCoordinates);
03938 break;
03939 }
03940 case CoordinateType::cassini:
03941 {
03942 if(i < numTargetCoordinates)
03943 _targetCoordinates = targetCoordinatesCollection[i];
03944 else
03945 {
03946 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::cassini);
03947 targetCoordinateExists = false;
03948 }
03949 try
03950 {
03951 convert(
03952 SourceOrTarget::source,
03953 SourceOrTarget::target,
03954 sourceCoordinatesCollection[i],
03955 sourceAccuracyCollection[i],
03956 *_targetCoordinates, *_targetAccuracy);
03957 }
03958 catch(CoordinateConversionException e)
03959 {
03960 _targetCoordinates->setErrorMessage(e.getMessage());
03961 }
03962
03963 if(!targetCoordinateExists)
03964 targetCoordinatesCollection.push_back(_targetCoordinates);
03965 break;
03966 }
03967 case CoordinateType::cylindricalEqualArea:
03968 {
03969 if(i < numTargetCoordinates)
03970 _targetCoordinates = targetCoordinatesCollection[i];
03971 else
03972 {
03973 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::cylindricalEqualArea);
03974 targetCoordinateExists = false;
03975 }
03976 try
03977 {
03978 convert(
03979 SourceOrTarget::source,
03980 SourceOrTarget::target,
03981 sourceCoordinatesCollection[i],
03982 sourceAccuracyCollection[i],
03983 *_targetCoordinates, *_targetAccuracy);
03984 }
03985 catch(CoordinateConversionException e)
03986 {
03987 _targetCoordinates->setErrorMessage(e.getMessage());
03988 }
03989
03990 if(!targetCoordinateExists)
03991 targetCoordinatesCollection.push_back(_targetCoordinates);
03992 break;
03993 }
03994 case CoordinateType::eckert4:
03995 {
03996 if(i < numTargetCoordinates)
03997 _targetCoordinates = targetCoordinatesCollection[i];
03998 else
03999 {
04000 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::eckert4);
04001 targetCoordinateExists = false;
04002 }
04003 try
04004 {
04005 convert(
04006 SourceOrTarget::source,
04007 SourceOrTarget::target,
04008 sourceCoordinatesCollection[i],
04009 sourceAccuracyCollection[i],
04010 *_targetCoordinates, *_targetAccuracy);
04011 }
04012 catch(CoordinateConversionException e)
04013 {
04014 _targetCoordinates->setErrorMessage(e.getMessage());
04015 }
04016
04017 if(!targetCoordinateExists)
04018 targetCoordinatesCollection.push_back(_targetCoordinates);
04019 break;
04020 }
04021 case CoordinateType::eckert6:
04022 {
04023 if(i < numTargetCoordinates)
04024 _targetCoordinates = targetCoordinatesCollection[i];
04025 else
04026 {
04027 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::eckert6);
04028 targetCoordinateExists = false;
04029 }
04030 try
04031 {
04032 convert(
04033 SourceOrTarget::source,
04034 SourceOrTarget::target,
04035 sourceCoordinatesCollection[i],
04036 sourceAccuracyCollection[i],
04037 *_targetCoordinates, *_targetAccuracy);
04038 }
04039 catch(CoordinateConversionException e)
04040 {
04041 _targetCoordinates->setErrorMessage(e.getMessage());
04042 }
04043
04044 if(!targetCoordinateExists)
04045 targetCoordinatesCollection.push_back(_targetCoordinates);
04046 break;
04047 }
04048 case CoordinateType::equidistantCylindrical:
04049 {
04050 if(i < numTargetCoordinates)
04051 _targetCoordinates = targetCoordinatesCollection[i];
04052 else
04053 {
04054 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::equidistantCylindrical);
04055 targetCoordinateExists = false;
04056 }
04057 try
04058 {
04059 convert(
04060 SourceOrTarget::source,
04061 SourceOrTarget::target,
04062 sourceCoordinatesCollection[i],
04063 sourceAccuracyCollection[i],
04064 *_targetCoordinates, *_targetAccuracy);
04065 }
04066 catch(CoordinateConversionException e)
04067 {
04068 _targetCoordinates->setErrorMessage(e.getMessage());
04069 }
04070
04071 if(!targetCoordinateExists)
04072 targetCoordinatesCollection.push_back(_targetCoordinates);
04073 break;
04074 }
04075 case CoordinateType::geocentric:
04076 {
04077 if(i < numTargetCoordinates)
04078 _targetCoordinates = targetCoordinatesCollection[i];
04079 else
04080 {
04081 _targetCoordinates = new CartesianCoordinates(CoordinateType::geocentric);
04082 targetCoordinateExists = false;
04083 }
04084 try
04085 {
04086 convert(SourceOrTarget::source, SourceOrTarget::target, sourceCoordinatesCollection[i], sourceAccuracyCollection[i], *_targetCoordinates, *_targetAccuracy);
04087 }
04088 catch(CoordinateConversionException e)
04089 {
04090 _targetCoordinates->setErrorMessage(e.getMessage());
04091 }
04092
04093 if(!targetCoordinateExists)
04094 targetCoordinatesCollection.push_back(_targetCoordinates);
04095 break;
04096 }
04097 case CoordinateType::geodetic:
04098 {
04099 if(i < numTargetCoordinates)
04100 _targetCoordinates = targetCoordinatesCollection[i];
04101 else
04102 {
04103 _targetCoordinates = new GeodeticCoordinates(CoordinateType::geodetic);
04104 targetCoordinateExists = false;
04105 }
04106 try
04107 {
04108 convert(SourceOrTarget::source, SourceOrTarget::target, sourceCoordinatesCollection[i], sourceAccuracyCollection[i], *_targetCoordinates, *_targetAccuracy);
04109 }
04110 catch(CoordinateConversionException e)
04111 {
04112 _targetCoordinates->setErrorMessage(e.getMessage());
04113 }
04114
04115 if(!targetCoordinateExists)
04116 targetCoordinatesCollection.push_back(_targetCoordinates);
04117 break;
04118 }
04119 case CoordinateType::georef:
04120 {
04121 if(i < numTargetCoordinates)
04122 _targetCoordinates = targetCoordinatesCollection[i];
04123 else
04124 {
04125 _targetCoordinates = new GEOREFCoordinates(CoordinateType::georef);
04126 targetCoordinateExists = false;
04127 }
04128 try
04129 {
04130 convert(
04131 SourceOrTarget::source,
04132 SourceOrTarget::target,
04133 sourceCoordinatesCollection[i],
04134 sourceAccuracyCollection[i],
04135 *_targetCoordinates, *_targetAccuracy);
04136 }
04137 catch(CoordinateConversionException e)
04138 {
04139 _targetCoordinates->setErrorMessage(e.getMessage());
04140 }
04141
04142 if(!targetCoordinateExists)
04143 targetCoordinatesCollection.push_back(_targetCoordinates);
04144 break;
04145 }
04146 case CoordinateType::globalAreaReferenceSystem:
04147 {
04148 if(i < numTargetCoordinates)
04149 _targetCoordinates = targetCoordinatesCollection[i];
04150 else
04151 {
04152 _targetCoordinates = new GARSCoordinates(CoordinateType::globalAreaReferenceSystem);
04153 targetCoordinateExists = false;
04154 }
04155 try
04156 {
04157 convert(
04158 SourceOrTarget::source,
04159 SourceOrTarget::target,
04160 sourceCoordinatesCollection[i],
04161 sourceAccuracyCollection[i],
04162 *_targetCoordinates, *_targetAccuracy);
04163 }
04164 catch(CoordinateConversionException e)
04165 {
04166 _targetCoordinates->setErrorMessage(e.getMessage());
04167 }
04168
04169 if(!targetCoordinateExists)
04170 targetCoordinatesCollection.push_back(_targetCoordinates);
04171 break;
04172 }
04173 case CoordinateType::gnomonic:
04174 {
04175 if(i < numTargetCoordinates)
04176 _targetCoordinates = targetCoordinatesCollection[i];
04177 else
04178 {
04179 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::gnomonic);
04180 targetCoordinateExists = false;
04181 }
04182 try
04183 {
04184 convert(
04185 SourceOrTarget::source,
04186 SourceOrTarget::target,
04187 sourceCoordinatesCollection[i],
04188 sourceAccuracyCollection[i],
04189 *_targetCoordinates, *_targetAccuracy);
04190 }
04191 catch(CoordinateConversionException e)
04192 {
04193 _targetCoordinates->setErrorMessage(e.getMessage());
04194 }
04195
04196 if(!targetCoordinateExists)
04197 targetCoordinatesCollection.push_back(_targetCoordinates);
04198 break;
04199 }
04200 case CoordinateType::lambertConformalConic1Parallel:
04201 {
04202 if(i < numTargetCoordinates)
04203 _targetCoordinates = targetCoordinatesCollection[i];
04204 else
04205 {
04206 _targetCoordinates = new MapProjectionCoordinates(
04207 CoordinateType::lambertConformalConic1Parallel);
04208 targetCoordinateExists = false;
04209 }
04210 try
04211 {
04212 convert(
04213 SourceOrTarget::source,
04214 SourceOrTarget::target,
04215 sourceCoordinatesCollection[i],
04216 sourceAccuracyCollection[i],
04217 *_targetCoordinates,
04218 *_targetAccuracy);
04219 }
04220 catch(CoordinateConversionException e)
04221 {
04222 _targetCoordinates->setErrorMessage(e.getMessage());
04223 }
04224
04225 if(!targetCoordinateExists)
04226 targetCoordinatesCollection.push_back(_targetCoordinates);
04227 break;
04228 }
04229 case CoordinateType::lambertConformalConic2Parallels:
04230 {
04231 if(i < numTargetCoordinates)
04232 _targetCoordinates = targetCoordinatesCollection[i];
04233 else
04234 {
04235 _targetCoordinates = new MapProjectionCoordinates(
04236 CoordinateType::lambertConformalConic2Parallels);
04237 targetCoordinateExists = false;
04238 }
04239 try
04240 {
04241 convert(
04242 SourceOrTarget::source,
04243 SourceOrTarget::target,
04244 sourceCoordinatesCollection[i],
04245 sourceAccuracyCollection[i],
04246 *_targetCoordinates, *_targetAccuracy);
04247 }
04248 catch(CoordinateConversionException e)
04249 {
04250 _targetCoordinates->setErrorMessage(e.getMessage());
04251 }
04252
04253 if(!targetCoordinateExists)
04254 targetCoordinatesCollection.push_back(_targetCoordinates);
04255 break;
04256 }
04257 case CoordinateType::localCartesian:
04258 {
04259 if(i < numTargetCoordinates)
04260 _targetCoordinates = targetCoordinatesCollection[i];
04261 else
04262 {
04263 _targetCoordinates = new CartesianCoordinates(CoordinateType::localCartesian);
04264 targetCoordinateExists = false;
04265 }
04266 try
04267 {
04268 convert(
04269 SourceOrTarget::source,
04270 SourceOrTarget::target,
04271 sourceCoordinatesCollection[i],
04272 sourceAccuracyCollection[i],
04273 *_targetCoordinates, *_targetAccuracy);
04274 }
04275 catch(CoordinateConversionException e)
04276 {
04277 _targetCoordinates->setErrorMessage(e.getMessage());
04278 }
04279
04280 if(!targetCoordinateExists)
04281 targetCoordinatesCollection.push_back(_targetCoordinates);
04282 break;
04283 }
04284 case CoordinateType::mercatorStandardParallel:
04285 {
04286 if(i < numTargetCoordinates)
04287 _targetCoordinates = targetCoordinatesCollection[i];
04288 else
04289 {
04290 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::mercatorStandardParallel);
04291 targetCoordinateExists = false;
04292 }
04293 try
04294 {
04295 convert(
04296 SourceOrTarget::source,
04297 SourceOrTarget::target,
04298 sourceCoordinatesCollection[i],
04299 sourceAccuracyCollection[i],
04300 *_targetCoordinates, *_targetAccuracy);
04301 }
04302 catch(CoordinateConversionException e)
04303 {
04304 _targetCoordinates->setErrorMessage(e.getMessage());
04305 }
04306
04307 if(!targetCoordinateExists)
04308 targetCoordinatesCollection.push_back(_targetCoordinates);
04309 break;
04310 }
04311 case CoordinateType::mercatorScaleFactor:
04312 {
04313 if(i < numTargetCoordinates)
04314 _targetCoordinates = targetCoordinatesCollection[i];
04315 else
04316 {
04317 _targetCoordinates = new MapProjectionCoordinates(
04318 CoordinateType::mercatorScaleFactor);
04319 targetCoordinateExists = false;
04320 }
04321 try
04322 {
04323 convert(
04324 SourceOrTarget::source,
04325 SourceOrTarget::target,
04326 sourceCoordinatesCollection[i],
04327 sourceAccuracyCollection[i],
04328 *_targetCoordinates, *_targetAccuracy);
04329 }
04330 catch(CoordinateConversionException e)
04331 {
04332 _targetCoordinates->setErrorMessage(e.getMessage());
04333 }
04334
04335 if(!targetCoordinateExists)
04336 targetCoordinatesCollection.push_back(_targetCoordinates);
04337 break;
04338 }
04339 case CoordinateType::militaryGridReferenceSystem:
04340 {
04341 if(i < numTargetCoordinates)
04342 _targetCoordinates = targetCoordinatesCollection[i];
04343 else
04344 {
04345 _targetCoordinates = new MGRSorUSNGCoordinates(CoordinateType::militaryGridReferenceSystem);
04346 targetCoordinateExists = false;
04347 }
04348 try
04349 {
04350 convert(
04351 SourceOrTarget::source,
04352 SourceOrTarget::target,
04353 sourceCoordinatesCollection[i],
04354 sourceAccuracyCollection[i],
04355 *_targetCoordinates, *_targetAccuracy);
04356 }
04357 catch(CoordinateConversionException e)
04358 {
04359 _targetCoordinates->setErrorMessage(e.getMessage());
04360 }
04361
04362 if(!targetCoordinateExists)
04363 targetCoordinatesCollection.push_back(_targetCoordinates);
04364 break;
04365 }
04366 case CoordinateType::millerCylindrical:
04367 {
04368 if(i < numTargetCoordinates)
04369 _targetCoordinates = targetCoordinatesCollection[i];
04370 else
04371 {
04372 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::millerCylindrical);
04373 targetCoordinateExists = false;
04374 }
04375 try
04376 {
04377 convert(
04378 SourceOrTarget::source,
04379 SourceOrTarget::target,
04380 sourceCoordinatesCollection[i],
04381 sourceAccuracyCollection[i],
04382 *_targetCoordinates, *_targetAccuracy);
04383 }
04384 catch(CoordinateConversionException e)
04385 {
04386 _targetCoordinates->setErrorMessage(e.getMessage());
04387 }
04388
04389 if(!targetCoordinateExists)
04390 targetCoordinatesCollection.push_back(_targetCoordinates);
04391 break;
04392 }
04393 case CoordinateType::mollweide:
04394 {
04395 if(i < numTargetCoordinates)
04396 _targetCoordinates = targetCoordinatesCollection[i];
04397 else
04398 {
04399 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::mollweide);
04400 targetCoordinateExists = false;
04401 }
04402 try
04403 {
04404 convert(
04405 SourceOrTarget::source,
04406 SourceOrTarget::target,
04407 sourceCoordinatesCollection[i],
04408 sourceAccuracyCollection[i],
04409 *_targetCoordinates, *_targetAccuracy);
04410 }
04411 catch(CoordinateConversionException e)
04412 {
04413 _targetCoordinates->setErrorMessage(e.getMessage());
04414 }
04415
04416 if(!targetCoordinateExists)
04417 targetCoordinatesCollection.push_back(_targetCoordinates);
04418 break;
04419 }
04420 case CoordinateType::newZealandMapGrid:
04421 {
04422 if(i < numTargetCoordinates)
04423 _targetCoordinates = targetCoordinatesCollection[i];
04424 else
04425 {
04426 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::newZealandMapGrid);
04427 targetCoordinateExists = false;
04428 }
04429 try
04430 {
04431 convert(
04432 SourceOrTarget::source,
04433 SourceOrTarget::target,
04434 sourceCoordinatesCollection[i],
04435 sourceAccuracyCollection[i],
04436 *_targetCoordinates, *_targetAccuracy);
04437 }
04438 catch(CoordinateConversionException e)
04439 {
04440 _targetCoordinates->setErrorMessage(e.getMessage());
04441 }
04442
04443 if(!targetCoordinateExists)
04444 targetCoordinatesCollection.push_back(_targetCoordinates);
04445 break;
04446 }
04447 case CoordinateType::neys:
04448 {
04449 if(i < numTargetCoordinates)
04450 _targetCoordinates = targetCoordinatesCollection[i];
04451 else
04452 {
04453 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::neys);
04454 targetCoordinateExists = false;
04455 }
04456 try
04457 {
04458 convert(
04459 SourceOrTarget::source,
04460 SourceOrTarget::target,
04461 sourceCoordinatesCollection[i],
04462 sourceAccuracyCollection[i],
04463 *_targetCoordinates, *_targetAccuracy);
04464 }
04465 catch(CoordinateConversionException e)
04466 {
04467 _targetCoordinates->setErrorMessage(e.getMessage());
04468 }
04469
04470 if(!targetCoordinateExists)
04471 targetCoordinatesCollection.push_back(_targetCoordinates);
04472 break;
04473 }
04474 case CoordinateType::obliqueMercator:
04475 {
04476 if(i < numTargetCoordinates)
04477 _targetCoordinates = targetCoordinatesCollection[i];
04478 else
04479 {
04480 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::obliqueMercator);
04481 targetCoordinateExists = false;
04482 }
04483 try
04484 {
04485 convert(
04486 SourceOrTarget::source,
04487 SourceOrTarget::target,
04488 sourceCoordinatesCollection[i],
04489 sourceAccuracyCollection[i],
04490 *_targetCoordinates, *_targetAccuracy);
04491 }
04492 catch(CoordinateConversionException e)
04493 {
04494 _targetCoordinates->setErrorMessage(e.getMessage());
04495 }
04496
04497 if(!targetCoordinateExists)
04498 targetCoordinatesCollection.push_back(_targetCoordinates);
04499 break;
04500 }
04501 case CoordinateType::orthographic:
04502 {
04503 if(i < numTargetCoordinates)
04504 _targetCoordinates = targetCoordinatesCollection[i];
04505 else
04506 {
04507 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::orthographic);
04508 targetCoordinateExists = false;
04509 }
04510 try
04511 {
04512 convert(
04513 SourceOrTarget::source,
04514 SourceOrTarget::target,
04515 sourceCoordinatesCollection[i],
04516 sourceAccuracyCollection[i],
04517 *_targetCoordinates, *_targetAccuracy);
04518 }
04519 catch(CoordinateConversionException e)
04520 {
04521 _targetCoordinates->setErrorMessage(e.getMessage());
04522 }
04523
04524 if(!targetCoordinateExists)
04525 targetCoordinatesCollection.push_back(_targetCoordinates);
04526 break;
04527 }
04528 case CoordinateType::polarStereographicStandardParallel:
04529 {
04530 if(i < numTargetCoordinates)
04531 _targetCoordinates = targetCoordinatesCollection[i];
04532 else
04533 {
04534 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::polarStereographicStandardParallel);
04535 targetCoordinateExists = false;
04536 }
04537 try
04538 {
04539 convert(
04540 SourceOrTarget::source,
04541 SourceOrTarget::target,
04542 sourceCoordinatesCollection[i],
04543 sourceAccuracyCollection[i],
04544 *_targetCoordinates, *_targetAccuracy);
04545 }
04546 catch(CoordinateConversionException e)
04547 {
04548 _targetCoordinates->setErrorMessage(e.getMessage());
04549 }
04550
04551 if(!targetCoordinateExists)
04552 targetCoordinatesCollection.push_back(_targetCoordinates);
04553 break;
04554 }
04555 case CoordinateType::polarStereographicScaleFactor:
04556 {
04557 if(i < numTargetCoordinates)
04558 _targetCoordinates = targetCoordinatesCollection[i];
04559 else
04560 {
04561 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::polarStereographicScaleFactor);
04562 targetCoordinateExists = false;
04563 }
04564 try
04565 {
04566 convert(
04567 SourceOrTarget::source,
04568 SourceOrTarget::target,
04569 sourceCoordinatesCollection[i],
04570 sourceAccuracyCollection[i],
04571 *_targetCoordinates, *_targetAccuracy);
04572 }
04573 catch(CoordinateConversionException e)
04574 {
04575 _targetCoordinates->setErrorMessage(e.getMessage());
04576 }
04577
04578 if(!targetCoordinateExists)
04579 targetCoordinatesCollection.push_back(_targetCoordinates);
04580 break;
04581 }
04582 case CoordinateType::polyconic:
04583 {
04584 if(i < numTargetCoordinates)
04585 _targetCoordinates = targetCoordinatesCollection[i];
04586 else
04587 {
04588 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::polyconic);
04589 targetCoordinateExists = false;
04590 }
04591 try
04592 {
04593 convert(
04594 SourceOrTarget::source,
04595 SourceOrTarget::target,
04596 sourceCoordinatesCollection[i],
04597 sourceAccuracyCollection[i],
04598 *_targetCoordinates, *_targetAccuracy);
04599 }
04600 catch(CoordinateConversionException e)
04601 {
04602 _targetCoordinates->setErrorMessage(e.getMessage());
04603 }
04604
04605 if(!targetCoordinateExists)
04606 targetCoordinatesCollection.push_back(_targetCoordinates);
04607 break;
04608 }
04609 case CoordinateType::sinusoidal:
04610 {
04611 if(i < numTargetCoordinates)
04612 _targetCoordinates = targetCoordinatesCollection[i];
04613 else
04614 {
04615 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::sinusoidal);
04616 targetCoordinateExists = false;
04617 }
04618 try
04619 {
04620 convert(
04621 SourceOrTarget::source,
04622 SourceOrTarget::target,
04623 sourceCoordinatesCollection[i],
04624 sourceAccuracyCollection[i],
04625 *_targetCoordinates, *_targetAccuracy);
04626 }
04627 catch(CoordinateConversionException e)
04628 {
04629 _targetCoordinates->setErrorMessage(e.getMessage());
04630 }
04631
04632 if(!targetCoordinateExists)
04633 targetCoordinatesCollection.push_back(_targetCoordinates);
04634 break;
04635 }
04636 case CoordinateType::stereographic:
04637 {
04638 if(i < numTargetCoordinates)
04639 _targetCoordinates = targetCoordinatesCollection[i];
04640 else
04641 {
04642 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::stereographic);
04643 targetCoordinateExists = false;
04644 }
04645 try
04646 {
04647 convert(
04648 SourceOrTarget::source,
04649 SourceOrTarget::target,
04650 sourceCoordinatesCollection[i],
04651 sourceAccuracyCollection[i],
04652 *_targetCoordinates, *_targetAccuracy);
04653 }
04654 catch(CoordinateConversionException e)
04655 {
04656 _targetCoordinates->setErrorMessage(e.getMessage());
04657 }
04658
04659 if(!targetCoordinateExists)
04660 targetCoordinatesCollection.push_back(_targetCoordinates);
04661 break;
04662 }
04663 case CoordinateType::transverseCylindricalEqualArea:
04664 {
04665 if(i < numTargetCoordinates)
04666 _targetCoordinates = targetCoordinatesCollection[i];
04667 else
04668 {
04669 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::transverseCylindricalEqualArea);
04670 targetCoordinateExists = false;
04671 }
04672 try
04673 {
04674 convert(
04675 SourceOrTarget::source,
04676 SourceOrTarget::target,
04677 sourceCoordinatesCollection[i],
04678 sourceAccuracyCollection[i],
04679 *_targetCoordinates, *_targetAccuracy);
04680 }
04681 catch(CoordinateConversionException e)
04682 {
04683 _targetCoordinates->setErrorMessage(e.getMessage());
04684 }
04685
04686 if(!targetCoordinateExists)
04687 targetCoordinatesCollection.push_back(_targetCoordinates);
04688 break;
04689 }
04690 case CoordinateType::transverseMercator:
04691 {
04692 if(i < numTargetCoordinates)
04693 _targetCoordinates = targetCoordinatesCollection[i];
04694 else
04695 {
04696 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::transverseMercator);
04697 targetCoordinateExists = false;
04698 }
04699 try
04700 {
04701 convert(
04702 SourceOrTarget::source,
04703 SourceOrTarget::target,
04704 sourceCoordinatesCollection[i],
04705 sourceAccuracyCollection[i],
04706 *_targetCoordinates, *_targetAccuracy);
04707 }
04708 catch(CoordinateConversionException e)
04709 {
04710 _targetCoordinates->setErrorMessage(e.getMessage());
04711 }
04712
04713 if(!targetCoordinateExists)
04714 targetCoordinatesCollection.push_back(_targetCoordinates);
04715 break;
04716 }
04717 case CoordinateType::universalPolarStereographic:
04718 {
04719 if(i < numTargetCoordinates)
04720 _targetCoordinates = targetCoordinatesCollection[i];
04721 else
04722 {
04723 _targetCoordinates = new UPSCoordinates(CoordinateType::universalPolarStereographic);
04724 targetCoordinateExists = false;
04725 }
04726 try
04727 {
04728 convert(
04729 SourceOrTarget::source,
04730 SourceOrTarget::target,
04731 _sourceCoordinates,
04732 _sourceAccuracy,
04733 *_targetCoordinates, *_targetAccuracy);
04734 }
04735 catch(CoordinateConversionException e)
04736 {
04737 _targetCoordinates->setErrorMessage(e.getMessage());
04738 }
04739
04740 if(!targetCoordinateExists)
04741 targetCoordinatesCollection.push_back(_targetCoordinates);
04742 break;
04743 }
04744 case CoordinateType::universalTransverseMercator:
04745 {
04746 if(i < numTargetCoordinates)
04747 _targetCoordinates = targetCoordinatesCollection[i];
04748 else
04749 {
04750 _targetCoordinates = new UTMCoordinates(CoordinateType::universalTransverseMercator);
04751 targetCoordinateExists = false;
04752 }
04753 try
04754 {
04755 convert(
04756 SourceOrTarget::source,
04757 SourceOrTarget::target,
04758 sourceCoordinatesCollection[i],
04759 sourceAccuracyCollection[i],
04760 *_targetCoordinates, *_targetAccuracy);
04761 }
04762 catch(CoordinateConversionException e)
04763 {
04764 _targetCoordinates->setErrorMessage(e.getMessage());
04765 }
04766
04767 if(!targetCoordinateExists)
04768 targetCoordinatesCollection.push_back(_targetCoordinates);
04769 break;
04770 }
04771 case CoordinateType::usNationalGrid:
04772 {
04773 if(i < numTargetCoordinates)
04774 _targetCoordinates = targetCoordinatesCollection[i];
04775 else
04776 {
04777 _targetCoordinates = new MGRSorUSNGCoordinates(CoordinateType::usNationalGrid);
04778 targetCoordinateExists = false;
04779 }
04780 try
04781 {
04782 convert(
04783 SourceOrTarget::source,
04784 SourceOrTarget::target,
04785 sourceCoordinatesCollection[i],
04786 sourceAccuracyCollection[i],
04787 *_targetCoordinates, *_targetAccuracy);
04788 }
04789 catch(CoordinateConversionException e)
04790 {
04791 _targetCoordinates->setErrorMessage(e.getMessage());
04792 }
04793
04794 if(!targetCoordinateExists)
04795 targetCoordinatesCollection.push_back(_targetCoordinates);
04796 break;
04797 }
04798 case CoordinateType::vanDerGrinten:
04799 {
04800 if(i < numTargetCoordinates)
04801 _targetCoordinates = targetCoordinatesCollection[i];
04802 else
04803 {
04804 _targetCoordinates = new MapProjectionCoordinates(CoordinateType::vanDerGrinten);
04805 targetCoordinateExists = false;
04806 }
04807 try
04808 {
04809 convert(
04810 SourceOrTarget::source,
04811 SourceOrTarget::target,
04812 sourceCoordinatesCollection[i],
04813 sourceAccuracyCollection[i],
04814 *_targetCoordinates, *_targetAccuracy);
04815 }
04816 catch(CoordinateConversionException e)
04817 {
04818 _targetCoordinates->setErrorMessage(e.getMessage());
04819 }
04820
04821 if(!targetCoordinateExists)
04822 targetCoordinatesCollection.push_back(_targetCoordinates);
04823 break;
04824 }
04825 default:
04826 throw CoordinateConversionException(ErrorMessages::invalidType);
04827 }
04828
04829 if(!targetAccuracyExists)
04830 targetAccuracyCollection.push_back( _targetAccuracy );
04831 }
04832 else
04833 {
04834 if(i >= numTargetCoordinates)
04835 targetCoordinateExists = false;
04836
04837 if( _sourceCoordinates )
04838 {
04839 if(!targetCoordinateExists)
04840 targetCoordinatesCollection.push_back( new CoordinateTuple( *_sourceCoordinates ) );
04841 else
04842 {
04843 _targetCoordinates = targetCoordinatesCollection[i];
04844 _targetCoordinates->set(
04845 _sourceCoordinates->coordinateType(),
04846 _sourceCoordinates->warningMessage(),
04847 _sourceCoordinates->errorMessage());
04848 }
04849 }
04850 else
04851 {
04852 if(!targetCoordinateExists)
04853 targetCoordinatesCollection.push_back( new CoordinateTuple() );
04854 }
04855
04856 if(!targetAccuracyExists)
04857 {
04858 if( _sourceAccuracy )
04859 targetAccuracyCollection.push_back( _sourceAccuracy );
04860 else
04861 {
04862 Accuracy* __sourceAccuracy = new Accuracy();
04863 targetAccuracyCollection.push_back( __sourceAccuracy );
04864 }
04865 }
04866 }
04867 }
04868
04869 if(numTargetCoordinates > num)
04870 {
04871 for(int i = num; i < numTargetCoordinates; i++)
04872 {
04873 delete targetCoordinatesCollection[i];
04874 targetCoordinatesCollection.pop_back();
04875 }
04876 }
04877 if(numTargetAccuracies > num)
04878 {
04879 for(int i = num; i < numTargetAccuracies; i++)
04880 {
04881 targetAccuracyCollection.pop_back();
04882 }
04883 }
04884 }
04885
04886
04887
04888
04889