- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# Y:/msp/devkits/temp_geotrans/master/geotrans3.1/CCS/src/CoordinateConversion/CoordinateConversionService.cpp

Go to the documentation of this file.

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