UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
CoordinateConversionService.cpp
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 /***************************************************************************/
3 /* RSC IDENTIFIER: Coordinate Conversion Service
4  *
5  * ABSTRACT
6  *
7  * This component is the coordinate conversion service for the MSPCCS
8  * application. It provides an external input interface that supports the
9  * MSPCCS GUI (Java) and the MSPCCS file processing
10  * component.
11  *
12  * This component depends on the DT&CC modules: DATUM, ELLIPSOID,
13  * GEOCENTRIC, GEOREF, MERCATOR, TRANSVERSE MERCATOR, UTM, MGRS, USNG, POLAR
14  * STEREOGRAPHIC, UPS, LAMBERT_1, LAMBERT_2, ALBERS, AZIMUTHAL EQUIDISTANT,
15  * BONNE, BRITISH NATIONAL GRID, CASSINI, CYLINDRICAL EQUAL AREA,ECKERT4,
16  * ECKERT6, EQUIDISTANT CYLINDRICAL, GARS, GNOMONIC, LOCAL CARTESIAN, LOCAL SPHERICAL
17  * MILLER, MOLLWEIDE, NEYS, NEW ZEALAND MAP GRID, OBLIQUE MERCATOR,
18  * ORTHOGRAPHIC, POLYCONIC, SINUSOIDAL, SPHERICAL, STEREOGRAPHIC,
19  * TRANSVERSE CYLINDRICAL EQUAL AREA, VAN DER GRINTEN, AND WEB MERCATOR.
20  *
21  *
22  * ERROR HANDLING
23  *
24  * This component checks for error codes returned by the DT&CC modules.
25  * If an error code is returned, it is combined with the current
26  * error code using the bitwise or. This combining allows multiple error
27  * codes to be returned. The possible error codes are listed below.
28  *
29  *
30  * REUSE NOTES
31  *
32  * Coordinate Conversion Service is intended for reuse by other applications
33  * that require coordinate conversions between multiple coordinate systems
34  * and/or datum transformations between multiple datums.
35  *
36  *
37  * REFERENCES
38  *
39  * Further information on Coordinate Conversion Service can be found in the
40  * Coordinate Conversion Service Reuse Manual.
41  *
42  * Coordinate Conversion Service originated from :
43  * U.S. Army Topographic Engineering Center
44  * Digital Concepts & Analysis Center
45  * 7701 Telegraph Road
46  * Alexandria, VA 22310-3864
47  *
48  *
49  * LICENSES
50  *
51  * None apply to this component.
52  *
53  * RESTRICTIONS
54  *
55  * Coordinate Conversion Service has no restrictions.
56  *
57  * MODIFICATIONS
58  *
59  * Date Description
60  * ---- -----------
61  * 04-22-97 Original Code
62  * 09-30-99 Added support for 15 new projections
63  * 05-30-00 Added support for 2 new projections
64  * 06-30-00 Added support for 1 new projection
65  * 09-30-00 Added support for 4 new projections
66  * 03-24-05 Added support for Lambert Conformal Conic (1 Standard Parallel)
67  * 08-17-05 Changed Lambert_Conformal_Conic to Lambert_Conformal_Conic_2
68  * 06-06-06 Added support for USNG
69  * 07-17-06 Added support for GARS
70  * 03-17-07 Original C++ Code
71  * 05-12-10 S. Gillis, BAEts26542, MSP TS MSL-HAE conversion
72  * should use CCS
73  * 06-11-10 S. Gillis, BAEts26724, Fixed memory error problem
74  * when MSPCCS_DATA is not set
75  * 07-07-10 K.Lam, BAEts27269, Replace C functions in threads.h
76  * with C++ methods in classes CCSThreadMutex
77  * 7/20/10 NGL BAEts27152 Updated getServiceVersion to return an int
78  * return 310 for MSP Geotrans 3.1
79  * 01/24/11 S. Gillis, BAEts26267, Add support for EGM2008 geoid heights
80  * 02/02/11 K.Lam, BAE27554, Fix memory leaks caused by mgrs function calls
81  * convertToUTM, convertToUPS, convertFromUTM, convertFromUPS
82  * 02/14/11 S. Gillis, BAE26267, Add support for EGM2008 geoid heights
83  * 3/23/11 N. Lundgren BAE28583 Updated for memory leaks in convert method
84  * 05/31/11 K. Lam BAE28657 Update service version for MSP 1.1.5
85  * 11/18/11 K. Lam MSP_29475 Update service version for MSP 1.2
86  * 06/16/14 Krinsky Add Web Mercator
87  * 01/16/16 A. Layne MSP_DR30125 added pass of ellipsoid code into transverseMercator
88  * and UTM.
89  * 10/08/17 M. Thakkar : LSC-5331 : Fixed array index for sinusoidal
90  * 06/25/18 K. Lam MSP-459 Update service version for MSP 1.6
91  * 07/03/18 C. Wendling : GTR-15 - Fixed IF block at 2235 brackets to
92  * include the rest of the special cases.
93  * 04/30/19 K. Lam GTR-28 Update service version for Geotrans 3.8
94  * 01/27/22 K. Lam GTRU-15 Update service version for Geotrans 3.9
95  */
96 
97 #include <stdio.h>
100 #include "CoordinateTuple.h"
101 #include "CoordinateType.h"
102 #include "EllipsoidLibrary.h"
104 #include "DatumLibrary.h"
106 #include "GeoidLibrary.h"
107 #include "Accuracy.h"
109 #include "GeodeticParameters.h"
117 #include "NeysParameters.h"
121 #include "UTMParameters.h"
122 #include "BNGCoordinates.h"
123 #include "CartesianCoordinates.h"
124 #include "GARSCoordinates.h"
125 #include "GeodeticCoordinates.h"
126 #include "GEOREFCoordinates.h"
128 #include "MGRSorUSNGCoordinates.h"
129 #include "SphericalCoordinates.h"
130 #include "UPSCoordinates.h"
131 #include "UTMCoordinates.h"
132 #include "AlbersEqualAreaConic.h"
133 #include "AzimuthalEquidistant.h"
134 #include "Bonne.h"
135 #include "BritishNationalGrid.h"
136 #include "Cassini.h"
137 #include "CylindricalEqualArea.h"
138 #include "Eckert4.h"
139 #include "Eckert6.h"
140 #include "EquidistantCylindrical.h"
141 #include "GARS.h"
142 #include "Geocentric.h"
143 #include "GEOREF.h"
144 #include "Gnomonic.h"
145 #include "LambertConformalConic.h"
146 #include "LocalCartesian.h"
147 #include "LocalSpherical.h"
148 #include "Mercator.h"
149 #include "MGRS.h"
150 #include "MillerCylindrical.h"
151 #include "Mollweide.h"
152 #include "Neys.h"
153 #include "NZMG.h"
154 #include "ObliqueMercator.h"
155 #include "Orthographic.h"
156 #include "PolarStereographic.h"
157 #include "Polyconic.h"
158 #include "Sinusoidal.h"
159 #include "Spherical.h"
160 #include "Stereographic.h"
162 #include "TransverseMercator.h"
163 #include "UPS.h"
164 #include "USNG.h"
165 #include "UTM.h"
166 #include "VanDerGrinten.h"
167 #include "WebMercator.h"
169 #include "ErrorMessages.h"
170 #include "WarningMessages.h"
171 #include "CCSThreadMutex.h"
172 #include "CCSThreadLock.h"
173 
174 using namespace MSP::CCS;
175 using MSP::CCSThreadMutex;
176 using MSP::CCSThreadLock;
177 
178 // DEFINES
179 const double PI = 3.14159265358979323e0;
180 CCSThreadMutex CoordinateConversionService::mutex;
181 
182 
183 
184 CoordinateConversionService::CCSData::CCSData() :
185  refCount( 1 )
186 {
187  ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
188  ellipsoidLibrary = new EllipsoidLibrary( ellipsoidLibraryImplementation );
189  datumLibraryImplementation = DatumLibraryImplementation::getInstance();
190  datumLibrary = new DatumLibrary( datumLibraryImplementation );
191  geoidLibrary = GeoidLibrary::getInstance();
192 }
193 
194 
195 CoordinateConversionService::CCSData::~CCSData()
196 {
197  delete ellipsoidLibrary;
198  ellipsoidLibrary = 0;
199 
200  EllipsoidLibraryImplementation::removeInstance();
201  ellipsoidLibraryImplementation = 0;
202 
203  delete datumLibrary;
204  datumLibrary = 0;
205 
206  DatumLibraryImplementation::removeInstance();
207  datumLibraryImplementation = 0;
208 
209  GeoidLibrary::removeInstance();
210  geoidLibrary = 0;
211 
212  refCount = 0;
213 }
214 
215 /************************************************************************/
216 /* FUNCTIONS */
217 
218 CoordinateConversionService::CoordinateConversionService(
219  const char* sourceDatumCode,
220  MSP::CCS::CoordinateSystemParameters* sourceParameters,
221  const char* targetDatumCode,
222  MSP::CCS::CoordinateSystemParameters* targetParameters ) :
223  WGS84_datum_index( 0 )
224 {
225  //Instantiate the variables here so exceptions can be caught
226  try
227  {
228  ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
229  datumLibraryImplementation = DatumLibraryImplementation::getInstance();
230  geoidLibrary = GeoidLibrary::getInstance();
231  ccsData = new CCSData();
232  }
234  {
235  //Manage the memory since there could be an instance
237  ellipsoidLibraryImplementation = 0;
238 
240  datumLibraryImplementation = 0;
241 
243  geoidLibrary = 0;
244 
245  throw e;
246  }
247 
248  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
249  datumLibraryImplementation = ccsData->datumLibraryImplementation;
250  geoidLibrary = ccsData->geoidLibrary;
251 
252  initCoordinateSystemState( SourceOrTarget::source );
253  initCoordinateSystemState( SourceOrTarget::target );
254 
255  /* Initialize Coordinate System Table */
256  Coordinate_System_Table[CoordinateType::albersEqualAreaConic].set( "Albers Equal Area Conic", "AC" );
257  Coordinate_System_Table[CoordinateType::azimuthalEquidistant].set( "Azimuthal Equidistant (S)", "AL" );
258  Coordinate_System_Table[CoordinateType::bonne].set( "Bonne", "BF" );
259  Coordinate_System_Table[CoordinateType::britishNationalGrid].set( "British National Grid (BNG)", "BN" );
260  Coordinate_System_Table[CoordinateType::cassini].set( "Cassini", "CS" );
261  Coordinate_System_Table[CoordinateType::cylindricalEqualArea].set( "Cylindrical Equal Area", "LI" );
262  Coordinate_System_Table[CoordinateType::eckert4].set( "Eckert IV (S)", "EF" );
263  Coordinate_System_Table[CoordinateType::eckert6].set( "Eckert VI (S)", "ED" );
264  Coordinate_System_Table[CoordinateType::equidistantCylindrical].set( "Equidistant Cylindrical (S)", "CP" );
265  Coordinate_System_Table[CoordinateType::geocentric].set( "Geocentric", "GC" );
266  Coordinate_System_Table[CoordinateType::geodetic].set( "Geodetic", "GD" );
267  Coordinate_System_Table[CoordinateType::georef].set( "GEOREF", "GE" );
268  Coordinate_System_Table[CoordinateType::globalAreaReferenceSystem].set( "Global Area Reference System (GARS)", "GA" );
269  Coordinate_System_Table[CoordinateType::gnomonic].set( "Gnomonic (S)", "GN" );
270  Coordinate_System_Table[CoordinateType::lambertConformalConic1Parallel].set( "Lambert Conformal Conic (1 Standard Parallel)", "L1" );
271  Coordinate_System_Table[CoordinateType::lambertConformalConic2Parallels].set( "Lambert Conformal Conic (2 Standard Parallel)", "L2" );
272  Coordinate_System_Table[CoordinateType::localCartesian].set( "Local Cartesian", "LC" );
273  Coordinate_System_Table[CoordinateType::localSpherical].set( "Local Spherical", "LS" );
274  Coordinate_System_Table[CoordinateType::mercatorStandardParallel].set( "Mercator (Standard Parallel)", "MC" );
275  Coordinate_System_Table[CoordinateType::mercatorScaleFactor].set( "Mercator (Scale Factor)", "MF" );
276  Coordinate_System_Table[CoordinateType::militaryGridReferenceSystem].set( "Military Grid Reference System (MGRS)", "MG" );
277  Coordinate_System_Table[CoordinateType::millerCylindrical].set( "Miller Cylindrical (S)", "MH" );
278  Coordinate_System_Table[CoordinateType::mollweide].set( "Mollweide (S)", "MP" );
279  Coordinate_System_Table[CoordinateType::newZealandMapGrid].set( "New Zealand Map Grid (NZMG)", "NT" );
280  Coordinate_System_Table[CoordinateType::neys].set( "Ney's (Modified Lambert Conformal Conic)", "NY" );
281  Coordinate_System_Table[CoordinateType::obliqueMercator].set( "Oblique Mercator", "OC" );
282  Coordinate_System_Table[CoordinateType::orthographic].set( "Orthographic (S)", "OD" );
283  Coordinate_System_Table[CoordinateType::polarStereographicStandardParallel].set( "Polar Stereographic (Standard Parallel)", "PG" );
284  Coordinate_System_Table[CoordinateType::polarStereographicScaleFactor].set( "Polar Stereographic (Scale Factor)", "PF" );
285  Coordinate_System_Table[CoordinateType::polyconic].set( "Polyconic", "PH" );
286  Coordinate_System_Table[CoordinateType::sinusoidal].set( "Sinusoidal", "SA" );
287  Coordinate_System_Table[CoordinateType::spherical].set( "Spherical", "SP" );
288  Coordinate_System_Table[CoordinateType::stereographic].set( "Stereographic (S)", "SD" );
289  Coordinate_System_Table[CoordinateType::transverseCylindricalEqualArea].set( "Transverse Cylindrical Equal Area", "TX" );
290  Coordinate_System_Table[CoordinateType::transverseMercator].set( "Transverse Mercator", "TC" );
291  Coordinate_System_Table[CoordinateType::universalPolarStereographic].set( "Universal Polar Stereographic (UPS)", "UP" );
292  Coordinate_System_Table[CoordinateType::universalTransverseMercator].set( "Universal Transverse Mercator (UTM)", "UT" );
293  Coordinate_System_Table[CoordinateType::usNationalGrid].set( "United States National Grid (USNG)", "US" );
294  Coordinate_System_Table[CoordinateType::vanDerGrinten].set( "Van der Grinten", "VA");
295  Coordinate_System_Table[CoordinateType::webMercator].set( "Web Mercator", "WM" );
296  setDataLibraries();
297 
298  setDatum(SourceOrTarget::source, sourceDatumCode);
299  try
300  {
301  setCoordinateSystem(SourceOrTarget::source, sourceParameters);
302  }
304  {
306  "Input ",
307  Coordinate_System_Table[sourceParameters->coordinateType()].Name,
308  ": \n", e.getMessage() );
309  }
310 
311  setDatum(SourceOrTarget::target, targetDatumCode);
312 
313  try
314  {
315  setCoordinateSystem(SourceOrTarget::target, targetParameters);
316  }
318  {
320  "Output ",
321  Coordinate_System_Table[targetParameters->coordinateType()].Name,
322  ": \n", e.getMessage() );
323  }
324 
325  datumLibraryImplementation->datumIndex( "WGE", &WGS84_datum_index );
326 }
327 
328 
330  const CoordinateConversionService &ccs ) :
331  ccsData( ccs.ccsData )
332 {
333  CCSThreadLock lock(&mutex);
334 
335  ++ccsData->refCount;
336 
337  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
338  datumLibraryImplementation = ccsData->datumLibraryImplementation;
339  geoidLibrary = ccsData->geoidLibrary;
340 
341  coordinateSystemState[SourceOrTarget::source].coordinateType =
342  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
343  coordinateSystemState[SourceOrTarget::target].coordinateType =
344  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
345 
346  copyParameters( SourceOrTarget::source,
347  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType,
348  ccs.coordinateSystemState[SourceOrTarget::source].parameters );
349  copyParameters( SourceOrTarget::target,
350  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType,
351  ccs.coordinateSystemState[SourceOrTarget::target].parameters );
352 
353  coordinateSystemState[SourceOrTarget::source].datumIndex =
354  ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
355  coordinateSystemState[SourceOrTarget::target].datumIndex =
356  ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
357 
358  WGS84_datum_index = ccs.WGS84_datum_index;
359 }
360 
361 
363 {
364  CCSThreadLock lock(&mutex);
365 
366  if( --ccsData->refCount == 0 )
367  {
368  delete ccsData;
369  ccsData = 0;
370 
372  ellipsoidLibraryImplementation = 0;
373 
375  datumLibraryImplementation = 0;
376 
378  geoidLibrary = 0;
379  }
380 
381  deleteCoordinateSystem( SourceOrTarget::source );
382  deleteCoordinateSystem( SourceOrTarget::target );
383 }
384 
385 
387  const CoordinateConversionService &ccs )
388 {
389  CCSThreadLock lock(&mutex);
390 
391  if( ccsData == ccs.ccsData )
392  return *this;
393 
394  if( --ccsData->refCount == 0 )
395  delete ccsData;
396 
397  ccsData = ccs.ccsData;
398  ++ccsData->refCount;
399 
400  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
401  datumLibraryImplementation = ccsData->datumLibraryImplementation;
402  geoidLibrary = ccsData->geoidLibrary;
403 
404  coordinateSystemState[SourceOrTarget::source].coordinateType =
405  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
406  coordinateSystemState[SourceOrTarget::target].coordinateType =
407  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
408 
409  copyParameters( SourceOrTarget::source,
410  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType,
411  ccs.coordinateSystemState[SourceOrTarget::source].parameters );
412  copyParameters( SourceOrTarget::target,
413  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType,
414  ccs.coordinateSystemState[SourceOrTarget::target].parameters );
415 
416  coordinateSystemState[SourceOrTarget::source].datumIndex =
417  ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
418  coordinateSystemState[SourceOrTarget::target].datumIndex =
419  ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
420 
421  WGS84_datum_index = ccs.WGS84_datum_index;
422 
423  return *this;
424 }
425 
426 
428  CoordinateTuple* sourceCoordinates,
429  Accuracy* sourceAccuracy,
430  CoordinateTuple& targetCoordinates,
431  Accuracy& targetAccuracy )
432 {
433 /*
434  * The function convertSourceToTarget converts the current source coordinates
435  * in the coordinate system defined by the current source coordinate system
436  * parameters and source datum, into target coordinates in the coordinate
437  * system defined by the target coordinate system parameters and target datum.
438  */
439 
441  sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
442 }
443 
444 
446  CoordinateTuple* targetCoordinates,
447  Accuracy* targetAccuracy,
448  CoordinateTuple& sourceCoordinates,
449  Accuracy& sourceAccuracy )
450 {
451 /*
452  * The function convertTargetToSource converts the current target coordinates in the coordinate
453  * system defined by the current target coordinate system parameters and target datum,
454  * into source coordinates in the coordinate system defined by the source coordinate
455  * system parameters and source datum.
456  */
457 
458  convert(
460  targetCoordinates, targetAccuracy,
461  sourceCoordinates, sourceAccuracy );
462 }
463 
464 
466  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
467  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracy,
468  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
469  std::vector<MSP::CCS::Accuracy*>& targetAccuracy )
470 {
471 /*
472  * The function convertSourceToTargetCollection will convert a list of
473  * source coordinates to a list of target coordinates in a single step.
474  *
475  * sourceCoordinates : Coordinates to be converted (input)
476  * sourceAccuracy : Source circular, linear and spherical errors (input)
477  * targetCoordinates : Converted coordinates of the target CS (output)
478  * targetAccuracy : Target circular, linear and spherical errors (output)
479  */
480 
481  convertCollection(
482  sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
483 }
484 
485 
487  const std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
488  const std::vector<MSP::CCS::Accuracy*>& targetAccuracy,
489  std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
490  std::vector<MSP::CCS::Accuracy*>& sourceAccuracy )
491 {
492 /*
493  * The function convertTargetToSourceCollection will convert a list of target
494  * coordinates to a list of source coordinates in a single step.
495  *
496  * targetCoordinates : Converted coordinates of the target CS (input)
497  * targetAccuracy : Target circular, linear and spherical errors (input)
498  * sourceCoordinates : Coordinates of the source CS to be converted (output)
499  * sourceAccuracy : Source circular, linear and spherical errors (output)
500  */
501 
502  convertCollection(
503  targetCoordinates, targetAccuracy, sourceCoordinates, sourceAccuracy );
504 }
505 
506 
508 {
509  /*
510  * The function getEllipsoidLibrary returns the ellipsoid library
511  * which provides access to ellipsoidparameter information.
512  *
513  */
514 
515  return ccsData->ellipsoidLibrary;
516 }
517 
518 
520 {
521  /*
522  * The function getDatumLibrary returns the datum library
523  * which provides access to datum transformation and parameter information.
524  *
525  */
526 
527  return ccsData->datumLibrary;
528 }
529 
530 
532 {
533  /*
534  * The function getServiceVersion returns current service version.
535  */
536 
537  return 390; // update service version for geotrans 3.9
538 }
539 
540 
542  const SourceOrTarget::Enum direction ) const
543 {
544  /*
545  * The function getDatum returns the index of the current datum
546  *
547  * direction : Indicates whether the datum is for source or target (input)
548  */
549 
550  return coordinateSystemState[direction].datumCode;
551 }
552 
553 
556  const SourceOrTarget::Enum direction ) const
557 {
558  /*
559  * The function getCoordinateSystem returns the current coordinate system
560  * type.
561  *
562  * direction : Indicates whether the coordinate system is to be used for
563  * source or target (input)
564  */
565 
566  switch( coordinateSystemState[direction].coordinateType )
567  {
570  return coordinateSystemState[direction].parameters.mapProjection6Parameters;
579  return coordinateSystemState[direction].parameters.mapProjection4Parameters;
586  return coordinateSystemState[direction].parameters.mapProjection3Parameters;
588  return coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
590  return coordinateSystemState[direction].parameters.geodeticParameters;
594  return coordinateSystemState[direction].parameters.mapProjection5Parameters;
597  return coordinateSystemState[direction].parameters.localCartesianParameters;
599  return ((Mercator*)(coordinateSystemState[direction].coordinateSystem))->getStandardParallelParameters(); // gets the calculated scale factor
601  return coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
603  return coordinateSystemState[direction].parameters.neysParameters;
605  return coordinateSystemState[direction].parameters.obliqueMercatorParameters;
607  return coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
609  return coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
611  return coordinateSystemState[direction].parameters.utmParameters;
622  return coordinateSystemState[direction].parameters.coordinateSystemParameters;
623  default:
625  }
626 }
627 
628 
629 /************************************************************************/
630 /* PRIVATE FUNCTIONS
631  *
632  */
633 
634 void CoordinateConversionService::initCoordinateSystemState(
635  const SourceOrTarget::Enum direction )
636 {
637 /*
638  * The function initCoordinateSystemState initializes coordinateSystemState.
639  *
640  * direction : Indicates whether the coordinate system is to be used for
641  * source or target (input)
642  */
643 
644  CCSThreadLock lock(&mutex);
645 
646  coordinateSystemState[direction].datumIndex = 0;
647  coordinateSystemState[direction].coordinateType = CoordinateType::geodetic;
648  coordinateSystemState[direction].coordinateSystem = 0;
649 
650  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
651  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
652  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
653  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
654  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
655  coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
656  coordinateSystemState[direction].parameters.geodeticParameters = 0;
657  coordinateSystemState[direction].parameters.localCartesianParameters = 0;
658  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
659  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
660  coordinateSystemState[direction].parameters.neysParameters = 0;
661  coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
662  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
663  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
664  coordinateSystemState[direction].parameters.utmParameters = 0;
665 }
666 
667 
668 void CoordinateConversionService::setDataLibraries()
669 {
670  /*
671  * The function setDataLibraries sets the initial state of the engine in
672  * in preparation for coordinate conversion and/or datum transformation
673  * operations.
674  */
675 
676  try
677  {
678  datumLibraryImplementation->setEllipsoidLibraryImplementation(
679  ellipsoidLibraryImplementation );
680  ellipsoidLibraryImplementation->setDatumLibraryImplementation(
681  datumLibraryImplementation );
682  }
684  {
685  char message[256] = "Error initializing MSP CCS data: ";
686  strcpy( message, e.getMessage() );
687  throw CoordinateConversionException( message );
688  }
689 }
690 
691 
692 void CoordinateConversionService::setDatum(
693  const SourceOrTarget::Enum direction,
694  const char* datumCode )
695 {
696  /*
697  * The function setDatum sets the datum to the
698  * datum corresponding to the specified index.
699  *
700  * direction : Indicates whether the datum is for source or target (input)
701  * datumCode : Identifies the code of the datum to be used (input)
702  */
703 
704  CCSThreadLock lock(&mutex);
705 
706  if( !datumCode )
708 
709  strcpy( coordinateSystemState[direction].datumCode, datumCode );
710 
711  long datumIndex = 0;
712  datumLibraryImplementation->datumIndex( datumCode, &datumIndex );
713  coordinateSystemState[direction].datumIndex = datumIndex;
714 }
715 
716 
717 void CoordinateConversionService::setCoordinateSystem(
718  const SourceOrTarget::Enum direction,
720 {
721  /*
722  * The function setCoordinateSystem sets the coordinate system.
723  *
724  * direction : Indicates whether the coordinate system is to be used for
725  * source or target (input)
726  * parameters : Coordinate system parameters to be used (input)
727  */
728 
729  CCSThreadLock lock(&mutex);
730 
731  coordinateSystemState[direction].coordinateSystem = 0;
732 
733  switch( parameters->coordinateType() )
734  {
736  coordinateSystemState[direction].coordinateType =
738  coordinateSystemState[direction].parameters.mapProjection6Parameters =
740  *dynamic_cast< MapProjection6Parameters* >( parameters ) );
741  break;
743  coordinateSystemState[direction].coordinateType =
745  coordinateSystemState[direction].parameters.mapProjection4Parameters =
747  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
748  break;
750  coordinateSystemState[direction].coordinateType = CoordinateType::bonne;
751  coordinateSystemState[direction].parameters.mapProjection4Parameters =
753  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
754  break;
756  coordinateSystemState[direction].coordinateType =
758  coordinateSystemState[direction].parameters.coordinateSystemParameters =
760  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
761  break;
763  coordinateSystemState[direction].coordinateType = CoordinateType::cassini;
764  coordinateSystemState[direction].parameters.mapProjection4Parameters =
766  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
767  break;
769  coordinateSystemState[direction].coordinateType =
771  coordinateSystemState[direction].parameters.mapProjection4Parameters =
773  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
774  break;
776  coordinateSystemState[direction].coordinateType = CoordinateType::eckert4;
777  coordinateSystemState[direction].parameters.mapProjection3Parameters =
779  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
780  break;
782  coordinateSystemState[direction].coordinateType = CoordinateType::eckert6;
783  coordinateSystemState[direction].parameters.mapProjection3Parameters =
785  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
786  break;
788  coordinateSystemState[direction].coordinateType =
790  coordinateSystemState[direction].parameters.equidistantCylindricalParameters =
792  *dynamic_cast< EquidistantCylindricalParameters* >( parameters ) );
793  break;
795  coordinateSystemState[direction].coordinateType =
797  coordinateSystemState[direction].parameters.coordinateSystemParameters =
799  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
800  break;
802  coordinateSystemState[direction].coordinateType =
804  coordinateSystemState[direction].parameters.coordinateSystemParameters =
806  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
807  break;
809  coordinateSystemState[direction].coordinateType =
811  coordinateSystemState[direction].parameters.geodeticParameters =
812  new GeodeticParameters(
813  *dynamic_cast< GeodeticParameters* >( parameters ) );
814  break;
816  coordinateSystemState[direction].coordinateType = CoordinateType::georef;
817  coordinateSystemState[direction].parameters.coordinateSystemParameters =
819  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
820  break;
822  coordinateSystemState[direction].coordinateType =
824  coordinateSystemState[direction].parameters.coordinateSystemParameters =
826  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
827  break;
829  coordinateSystemState[direction].coordinateType =
831  coordinateSystemState[direction].parameters.mapProjection4Parameters =
833  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
834  break;
836  coordinateSystemState[direction].coordinateType = CoordinateType::lambertConformalConic1Parallel;
837  coordinateSystemState[direction].parameters.mapProjection5Parameters =
839  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
840  break;
842  coordinateSystemState[direction].coordinateType =
844  coordinateSystemState[direction].parameters.mapProjection6Parameters =
846  *dynamic_cast< MapProjection6Parameters* >( parameters ) );
847  break;
849  coordinateSystemState[direction].coordinateType =
851  coordinateSystemState[direction].parameters.localCartesianParameters =
853  *dynamic_cast< LocalCartesianParameters* >( parameters ) );
854  break;
856  coordinateSystemState[direction].coordinateType =
858  coordinateSystemState[direction].parameters.localCartesianParameters =
860  *dynamic_cast< LocalCartesianParameters* >( parameters ) );
861  break;
863  coordinateSystemState[direction].coordinateType =
865  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters =
867  *dynamic_cast< MercatorStandardParallelParameters* >( parameters ));
868  break;
870  coordinateSystemState[direction].coordinateType =
872  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters =
874  *dynamic_cast< MercatorScaleFactorParameters* >( parameters ) );
875  break;
877  coordinateSystemState[direction].coordinateType =
879  coordinateSystemState[direction].parameters.coordinateSystemParameters =
881  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
882  break;
884  coordinateSystemState[direction].coordinateType = CoordinateType::millerCylindrical;
885  coordinateSystemState[direction].parameters.mapProjection3Parameters =
887  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
888  break;
890  coordinateSystemState[direction].coordinateType =
892  coordinateSystemState[direction].parameters.mapProjection3Parameters =
894  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
895  break;
897  coordinateSystemState[direction].coordinateType =
899  coordinateSystemState[direction].parameters.coordinateSystemParameters =
901  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
902  break;
904  coordinateSystemState[direction].coordinateType = CoordinateType::neys;
905  coordinateSystemState[direction].parameters.neysParameters =
906  new NeysParameters( *dynamic_cast< NeysParameters* >( parameters ) );
907  break;
909  coordinateSystemState[direction].coordinateType =
911  coordinateSystemState[direction].parameters.obliqueMercatorParameters =
913  *dynamic_cast< ObliqueMercatorParameters* >( parameters ) );
914  break;
916  coordinateSystemState[direction].coordinateType =
918  coordinateSystemState[direction].parameters.mapProjection4Parameters =
920  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
921  break;
923  coordinateSystemState[direction].coordinateType =
925  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters =
927  *dynamic_cast< PolarStereographicStandardParallelParameters* >(
928  parameters ) );
929  break;
931  coordinateSystemState[direction].coordinateType =
933  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters =
935  *dynamic_cast< PolarStereographicScaleFactorParameters* >( parameters ) );
936  break;
938  coordinateSystemState[direction].coordinateType =
940  coordinateSystemState[direction].parameters.mapProjection4Parameters =
942  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
943  break;
945  coordinateSystemState[direction].coordinateType =
947  coordinateSystemState[direction].parameters.mapProjection3Parameters =
949  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
950  break;
952  coordinateSystemState[direction].coordinateType =
954  coordinateSystemState[direction].parameters.mapProjection4Parameters =
956  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
957  break;
959  coordinateSystemState[direction].coordinateType =
961  coordinateSystemState[direction].parameters.mapProjection5Parameters =
963  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
964  break;
966  coordinateSystemState[direction].coordinateType =
968  coordinateSystemState[direction].parameters.mapProjection5Parameters =
970  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
971  break;
973  coordinateSystemState[direction].coordinateType =
975  coordinateSystemState[direction].parameters.coordinateSystemParameters =
977  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
978  break;
980  coordinateSystemState[direction].coordinateType =
982  coordinateSystemState[direction].parameters.utmParameters =
983  new UTMParameters( *dynamic_cast< UTMParameters* >( parameters ) );
984  break;
986  coordinateSystemState[direction].coordinateType =
988  coordinateSystemState[direction].parameters.coordinateSystemParameters =
990  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
991  break;
993  coordinateSystemState[direction].coordinateType =
995  coordinateSystemState[direction].parameters.mapProjection3Parameters =
997  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
998  break;
1000  coordinateSystemState[direction].coordinateType =
1002  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1004  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1005  break;
1006  default:
1008  }
1009 
1010  setParameters( direction );
1011 }
1012 
1013 void CoordinateConversionService::setParameters(
1014  const SourceOrTarget::Enum direction )
1015 {
1016 /*
1017  * The function setParameters calls the setParameters function of the source
1018  * or target coordinate system.
1019  *
1020  * direction : Indicates whether the coordinate system is to be used for
1021  * source or target (input)
1022  */
1023 
1024 
1025  Coordinate_State_Row* row = &coordinateSystemState[direction];
1026 
1027  char ellipsoidCode[3];
1028  long ellipsoidIndex;
1029  double semiMajorAxis;
1030  double flattening;
1031 
1032  datumLibraryImplementation->datumEllipsoidCode(
1033  row->datumIndex, ellipsoidCode );
1034 
1035  ellipsoidLibraryImplementation->ellipsoidIndex(
1036  ellipsoidCode, &ellipsoidIndex );
1037 
1038  ellipsoidLibraryImplementation->ellipsoidParameters(
1039  ellipsoidIndex, &semiMajorAxis, &flattening );
1040 
1041  switch( coordinateSystemState[direction].coordinateType )
1042  {
1044  {
1045  MapProjection6Parameters* param =
1046  row->parameters.mapProjection6Parameters;
1047 
1048  coordinateSystemState[direction].coordinateSystem =
1050  semiMajorAxis, flattening,
1051  param->centralMeridian(),
1052  param->originLatitude(),
1053  param->standardParallel1(),
1054  param->standardParallel2(),
1055  param->falseEasting(),
1056  param->falseNorthing() );
1057  break;
1058  }
1060  {
1061  MapProjection4Parameters* param =
1062  row->parameters.mapProjection4Parameters;
1063 
1064  coordinateSystemState[direction].coordinateSystem =
1066  semiMajorAxis, flattening,
1067  param->centralMeridian(),
1068  param->originLatitude(),
1069  param->falseEasting(),
1070  param->falseNorthing() );
1071  break;
1072  }
1073  case CoordinateType::bonne:
1074  {
1075  MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
1076 
1077  coordinateSystemState[direction].coordinateSystem = new Bonne(
1078  semiMajorAxis, flattening,
1079  param->centralMeridian(),
1080  param->originLatitude(),
1081  param->falseEasting(),
1082  param->falseNorthing() );
1083  break;
1084  }
1086  {
1087  coordinateSystemState[direction].coordinateSystem =
1088  new BritishNationalGrid( ellipsoidCode );
1089 
1090  break;
1091  }
1093  {
1094  MapProjection4Parameters* param =
1095  row->parameters.mapProjection4Parameters;
1096 
1097  coordinateSystemState[direction].coordinateSystem = new Cassini(
1098  semiMajorAxis, flattening,
1099  param->centralMeridian(),
1100  param->originLatitude(),
1101  param->falseEasting(),
1102  param->falseNorthing() );
1103  break;
1104  }
1106  {
1107  MapProjection4Parameters* param =
1108  row->parameters.mapProjection4Parameters;
1109 
1110  coordinateSystemState[direction].coordinateSystem =
1112  semiMajorAxis, flattening,
1113  param->centralMeridian(),
1114  param->originLatitude(),
1115  param->falseEasting(),
1116  param->falseNorthing() );
1117  break;
1118  }
1120  {
1121  MapProjection3Parameters* param =
1122  row->parameters.mapProjection3Parameters;
1123 
1124  coordinateSystemState[direction].coordinateSystem = new Eckert4(
1125  semiMajorAxis, flattening,
1126  param->centralMeridian(),
1127  param->falseEasting(),
1128  param->falseNorthing() );
1129  break;
1130  }
1132  {
1133  MapProjection3Parameters* param =
1134  row->parameters.mapProjection3Parameters;
1135 
1136  coordinateSystemState[direction].coordinateSystem = new Eckert6(
1137  semiMajorAxis, flattening,
1138  param->centralMeridian(),
1139  param->falseEasting(),
1140  param->falseNorthing() );
1141  break;
1142  }
1144  {
1146  row->parameters.equidistantCylindricalParameters;
1147 
1148  coordinateSystemState[direction].coordinateSystem =
1150  semiMajorAxis,flattening,
1151  param->centralMeridian(),
1152  param->standardParallel(),
1153  param->falseEasting(),
1154  param->falseNorthing() );
1155  break;
1156  }
1158  {
1159  coordinateSystemState[direction].coordinateSystem =
1160  new Geocentric( semiMajorAxis, flattening );
1161  break;
1162  }
1164  {
1165  coordinateSystemState[direction].coordinateSystem =
1166  new Spherical( semiMajorAxis, flattening );
1167  break;
1168  }
1170  coordinateSystemState[direction].coordinateSystem = 0;
1171  break;
1173  coordinateSystemState[direction].coordinateSystem = new GEOREF();
1174  break;
1176  coordinateSystemState[direction].coordinateSystem = new GARS();
1177  break;
1179  {
1180  MapProjection4Parameters* param =
1181  row->parameters.mapProjection4Parameters;
1182 
1183  coordinateSystemState[direction].coordinateSystem = new Gnomonic(
1184  semiMajorAxis, flattening,
1185  param->centralMeridian(),
1186  param->originLatitude(),
1187  param->falseEasting(),
1188  param->falseNorthing() );
1189  break;
1190  }
1192  {
1193  MapProjection5Parameters* param = row->parameters.mapProjection5Parameters;
1194 
1195  coordinateSystemState[direction].coordinateSystem =
1197  semiMajorAxis, flattening,
1198  param->centralMeridian(),
1199  param->originLatitude(),
1200  param->falseEasting(),
1201  param->falseNorthing(),
1202  param->scaleFactor() );
1203  break;
1204  }
1206  {
1207  MapProjection6Parameters* param =
1208  row->parameters.mapProjection6Parameters;
1209 
1210  coordinateSystemState[direction].coordinateSystem =
1212  semiMajorAxis, flattening,
1213  param->centralMeridian(),
1214  param->originLatitude(),
1215  param->standardParallel1(),
1216  param->standardParallel2(),
1217  param->falseEasting(),
1218  param->falseNorthing() );
1219  break;
1220  }
1222  {
1223  LocalCartesianParameters* param =
1224  row->parameters.localCartesianParameters;
1225 
1226  coordinateSystemState[direction].coordinateSystem = new LocalCartesian(
1227  semiMajorAxis, flattening,
1228  param->longitude(),
1229  param->latitude(),
1230  param->height(),
1231  param->orientation() );
1232  break;
1233  }
1235  {
1236  LocalCartesianParameters* param =
1237  row->parameters.localCartesianParameters;
1238 
1239  coordinateSystemState[direction].coordinateSystem = new LocalSpherical(
1240  semiMajorAxis, flattening,
1241  param->longitude(),
1242  param->latitude(),
1243  param->height(),
1244  param->orientation() );
1245  break;
1246  }
1248  {
1250  row->parameters.mercatorStandardParallelParameters;
1251  double scaleFactor;
1252  coordinateSystemState[direction].coordinateSystem = new Mercator(
1253  semiMajorAxis, flattening,
1254  param->centralMeridian(),
1255  param->standardParallel(),
1256  param->falseEasting(),
1257  param->falseNorthing(),
1258  &scaleFactor );
1259 
1260  param->setScaleFactor( scaleFactor );
1261 
1262  break;
1263  }
1265  {
1267  row->parameters.mercatorScaleFactorParameters;
1268 
1269  coordinateSystemState[direction].coordinateSystem = new Mercator(
1270  semiMajorAxis, flattening,
1271  param->centralMeridian(),
1272  param->falseEasting(),
1273  param->falseNorthing(),
1274  param->scaleFactor() );
1275 
1276  break;
1277  }
1279  {
1280  coordinateSystemState[direction].coordinateSystem = new MGRS(
1281  semiMajorAxis, flattening, ellipsoidCode );
1282 
1283  break;
1284  }
1286  {
1287  MapProjection3Parameters* param =
1288  row->parameters.mapProjection3Parameters;
1289 
1290  coordinateSystemState[direction].coordinateSystem =
1291  new MillerCylindrical(
1292  semiMajorAxis, flattening,
1293  param->centralMeridian(),
1294  param->falseEasting(),
1295  param->falseNorthing() );
1296  break;
1297  }
1299  {
1300  MapProjection3Parameters* param =
1301  row->parameters.mapProjection3Parameters;
1302 
1303  coordinateSystemState[direction].coordinateSystem = new Mollweide(
1304  semiMajorAxis,flattening,
1305  param->centralMeridian(),
1306  param->falseEasting(),
1307  param->falseNorthing() );
1308  break;
1309  }
1311  {
1312  coordinateSystemState[direction].coordinateSystem =
1313  new NZMG( ellipsoidCode );
1314 
1315  break;
1316  }
1317  case CoordinateType::neys:
1318  {
1319  NeysParameters* param = row->parameters.neysParameters;
1320 
1321  coordinateSystemState[direction].coordinateSystem = new Neys(
1322  semiMajorAxis, flattening,
1323  param->centralMeridian(),
1324  param->originLatitude(),
1325  param->standardParallel1(),
1326  param->falseEasting(),
1327  param->falseNorthing() );
1328  break;
1329  }
1331  {
1332  ObliqueMercatorParameters* param =
1333  row->parameters.obliqueMercatorParameters;
1334 
1335  coordinateSystemState[direction].coordinateSystem = new ObliqueMercator(
1336  semiMajorAxis, flattening,
1337  param->originLatitude(),
1338  param->longitude1(),
1339  param->latitude1(),
1340  param->longitude2(),
1341  param->latitude2(),
1342  param->falseEasting(),
1343  param->falseNorthing(),
1344  param->scaleFactor() );
1345  break;
1346  }
1348  {
1349  MapProjection4Parameters* param =
1350  row->parameters.mapProjection4Parameters;
1351 
1352  coordinateSystemState[direction].coordinateSystem = new Orthographic(
1353  semiMajorAxis, flattening,
1354  param->centralMeridian(),
1355  param->originLatitude(),
1356  param->falseEasting(),
1357  param->falseNorthing() );
1358  break;
1359  }
1361  {
1363  row->parameters.polarStereographicStandardParallelParameters;
1364 
1365  coordinateSystemState[direction].coordinateSystem =
1366  new PolarStereographic(
1367  semiMajorAxis, flattening,
1368  param->centralMeridian(),
1369  param->standardParallel(),
1370  param->falseEasting(),
1371  param->falseNorthing() );
1372 
1373  break;
1374  }
1376  {
1378  row->parameters.polarStereographicScaleFactorParameters;
1379 
1380  coordinateSystemState[direction].coordinateSystem =
1381  new PolarStereographic(
1382  semiMajorAxis, flattening,
1383  param->centralMeridian(),
1384  param->scaleFactor(),
1385  param->hemisphere(),
1386  param->falseEasting(),
1387  param->falseNorthing() );
1388  break;
1389  }
1391  {
1392  MapProjection4Parameters* param =
1393  row->parameters.mapProjection4Parameters;
1394 
1395  coordinateSystemState[direction].coordinateSystem = new Polyconic(
1396  semiMajorAxis, flattening,
1397  param->centralMeridian(),
1398  param->originLatitude(),
1399  param->falseEasting(),
1400  param->falseNorthing() );
1401  break;
1402  }
1404  {
1405  MapProjection3Parameters* param =
1406  row->parameters.mapProjection3Parameters;
1407 
1408  coordinateSystemState[direction].coordinateSystem = new Sinusoidal(
1409  semiMajorAxis, flattening,
1410  param->centralMeridian(),
1411  param->falseEasting(),
1412  param->falseNorthing() );
1413  break;
1414  }
1416  {
1417  MapProjection4Parameters* param =
1418  row->parameters.mapProjection4Parameters;
1419 
1420  coordinateSystemState[direction].coordinateSystem = new Stereographic(
1421  semiMajorAxis, flattening,
1422  param->centralMeridian(),
1423  param->originLatitude(),
1424  param->falseEasting(),
1425  param->falseNorthing() );
1426  break;
1427  }
1429  {
1430  MapProjection5Parameters* param =
1431  row->parameters.mapProjection5Parameters;
1432 
1433  coordinateSystemState[direction].coordinateSystem =
1435  semiMajorAxis, flattening,
1436  param->centralMeridian(),
1437  param->originLatitude(),
1438  param->falseEasting(),
1439  param->falseNorthing(),
1440  param->scaleFactor() );
1441  break;
1442  }
1444  {
1445  MapProjection5Parameters* param =
1446  row->parameters.mapProjection5Parameters;
1447 
1448  coordinateSystemState[direction].coordinateSystem =
1449  new TransverseMercator(
1450  semiMajorAxis, flattening,
1451  param->centralMeridian(),
1452  param->originLatitude(),
1453  param->falseEasting(),
1454  param->falseNorthing(),
1455  param->scaleFactor(),
1456  ellipsoidCode);
1457  break;
1458  }
1460  {
1461  coordinateSystemState[direction].coordinateSystem = new UPS(
1462  semiMajorAxis, flattening );
1463 
1464  break;
1465  }
1467  {
1468  if( direction == SourceOrTarget::target )
1469  {
1470  UTMParameters* param = row->parameters.utmParameters;
1471 
1472  if((param->override() != 0) && (param->zone() == 0))
1474  else
1475  {
1476  if(param->override() == 0)
1477  param->setZone( 0 );
1478  }
1479 
1480  coordinateSystemState[direction].coordinateSystem = new UTM(
1481  semiMajorAxis, flattening, ellipsoidCode, param->zone() );
1482  }
1483  else
1484  coordinateSystemState[direction].coordinateSystem = new UTM(
1485  semiMajorAxis, flattening, ellipsoidCode, 0 );
1486 
1487  break;
1488  }
1490  {
1491  coordinateSystemState[direction].coordinateSystem = new USNG(
1492  semiMajorAxis, flattening, ellipsoidCode );
1493 
1494  break;
1495  }
1497  {
1498  MapProjection3Parameters* param =
1499  row->parameters.mapProjection3Parameters;
1500 
1501  coordinateSystemState[direction].coordinateSystem = new VanDerGrinten(
1502  semiMajorAxis, flattening,
1503  param->centralMeridian(),
1504  param->falseEasting(),
1505  param->falseNorthing() );
1506  break;
1507  }
1509  {
1510  coordinateSystemState[direction].coordinateSystem =
1511  new WebMercator( ellipsoidCode );
1512  break;
1513  }
1514  default:
1515  break;
1516  }
1517 }
1518 
1519 
1520 void CoordinateConversionService::deleteCoordinateSystem(
1521  const SourceOrTarget::Enum direction )
1522 {
1523 /*
1524  * The function deleteCoordinateSystem frees memory of coordinateSystemState.
1525  *
1526  * direction : Indicates whether the coordinate system is to be used for
1527  * source or target (input)
1528  */
1529 
1530  switch( coordinateSystemState[direction].coordinateType )
1531  {
1533  if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
1534  {
1535  delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
1536  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
1537  }
1538  if( coordinateSystemState[direction].coordinateSystem )
1539  {
1540  delete ((AlbersEqualAreaConic*)(coordinateSystemState[direction].coordinateSystem));
1541  coordinateSystemState[direction].coordinateSystem = 0;
1542  }
1543  break;
1545  if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
1546  {
1547  delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
1548  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
1549  }
1550  if( coordinateSystemState[direction].coordinateSystem )
1551  {
1552  delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
1553  coordinateSystemState[direction].coordinateSystem = 0;
1554  }
1555  break;
1557  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1558  {
1559  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1560  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1561  }
1562  if( coordinateSystemState[direction].coordinateSystem )
1563  {
1564  delete ((AzimuthalEquidistant*)(coordinateSystemState[direction].coordinateSystem));
1565  coordinateSystemState[direction].coordinateSystem = 0;
1566  }
1567  break;
1568  case CoordinateType::bonne:
1569  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1570  {
1571  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1572  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1573  }
1574  if( coordinateSystemState[direction].coordinateSystem )
1575  {
1576  delete ((Bonne*)(coordinateSystemState[direction].coordinateSystem));
1577  coordinateSystemState[direction].coordinateSystem = 0;
1578  }
1579  break;
1581  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1582  {
1583  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1584  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1585  }
1586  if( coordinateSystemState[direction].coordinateSystem )
1587  {
1588  delete ((Cassini*)(coordinateSystemState[direction].coordinateSystem));
1589  coordinateSystemState[direction].coordinateSystem = 0;
1590  }
1591  break;
1593  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1594  {
1595  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1596  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1597  }
1598  if( coordinateSystemState[direction].coordinateSystem )
1599  {
1600  delete ((CylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
1601  coordinateSystemState[direction].coordinateSystem = 0;
1602  }
1603  break;
1605  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1606  {
1607  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1608  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1609  }
1610  if( coordinateSystemState[direction].coordinateSystem )
1611  {
1612  delete ((Gnomonic*)(coordinateSystemState[direction].coordinateSystem));
1613  coordinateSystemState[direction].coordinateSystem = 0;
1614  }
1615  break;
1617  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1618  {
1619  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1620  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1621  }
1622  if( coordinateSystemState[direction].coordinateSystem )
1623  {
1624  delete ((Orthographic*)(coordinateSystemState[direction].coordinateSystem));
1625  coordinateSystemState[direction].coordinateSystem = 0;
1626  }
1627  break;
1629  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1630  {
1631  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1632  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1633  }
1634  if( coordinateSystemState[direction].coordinateSystem )
1635  {
1636  delete ((Polyconic*)(coordinateSystemState[direction].coordinateSystem));
1637  coordinateSystemState[direction].coordinateSystem = 0;
1638  }
1639  break;
1641  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1642  {
1643  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1644  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1645  }
1646  if( coordinateSystemState[direction].coordinateSystem )
1647  {
1648  delete ((Stereographic*)(coordinateSystemState[direction].coordinateSystem));
1649  coordinateSystemState[direction].coordinateSystem = 0;
1650  }
1651  break;
1653  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1654  {
1655  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1656  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1657  }
1658  if( coordinateSystemState[direction].coordinateSystem )
1659  {
1660  delete ((BritishNationalGrid*)(coordinateSystemState[direction].coordinateSystem));
1661  coordinateSystemState[direction].coordinateSystem = 0;
1662  }
1663  break;
1665  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1666  {
1667  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1668  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1669  }
1670  if( coordinateSystemState[direction].coordinateSystem )
1671  {
1672  delete ((Eckert4*)(coordinateSystemState[direction].coordinateSystem));
1673  coordinateSystemState[direction].coordinateSystem = 0;
1674  }
1675  break;
1677  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1678  {
1679  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1680  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1681  }
1682  if( coordinateSystemState[direction].coordinateSystem )
1683  {
1684  delete ((Eckert6*)(coordinateSystemState[direction].coordinateSystem));
1685  coordinateSystemState[direction].coordinateSystem = 0;
1686  }
1687  break;
1689  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1690  {
1691  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1692  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1693  }
1694  if( coordinateSystemState[direction].coordinateSystem )
1695  {
1696  delete ((MillerCylindrical*)(coordinateSystemState[direction].coordinateSystem));
1697  coordinateSystemState[direction].coordinateSystem = 0;
1698  }
1699  break;
1701  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1702  {
1703  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1704  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1705  }
1706  if( coordinateSystemState[direction].coordinateSystem )
1707  {
1708  delete ((Mollweide*)(coordinateSystemState[direction].coordinateSystem));
1709  coordinateSystemState[direction].coordinateSystem = 0;
1710  }
1711  break;
1713  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1714  {
1715  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1716  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1717  }
1718  if( coordinateSystemState[direction].coordinateSystem )
1719  {
1720  delete ((Sinusoidal*)(coordinateSystemState[direction].coordinateSystem));
1721  coordinateSystemState[direction].coordinateSystem = 0;
1722  }
1723  break;
1725  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1726  {
1727  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1728  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1729  }
1730  if( coordinateSystemState[direction].coordinateSystem )
1731  {
1732  delete ((VanDerGrinten*)(coordinateSystemState[direction].coordinateSystem));
1733  coordinateSystemState[direction].coordinateSystem = 0;
1734  }
1735  break;
1737  if( coordinateSystemState[direction].parameters.equidistantCylindricalParameters )
1738  {
1739  delete coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
1740  coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
1741  }
1742  if( coordinateSystemState[direction].coordinateSystem )
1743  {
1744  delete ((EquidistantCylindrical*)(coordinateSystemState[direction].coordinateSystem));
1745  coordinateSystemState[direction].coordinateSystem = 0;
1746  }
1747  break;
1749  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1750  {
1751  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1752  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1753  }
1754  if( coordinateSystemState[direction].coordinateSystem )
1755  {
1756  delete ((Geocentric*)(coordinateSystemState[direction].coordinateSystem));
1757  coordinateSystemState[direction].coordinateSystem = 0;
1758  }
1759  break;
1761  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1762  {
1763  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1764  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1765  }
1766  if( coordinateSystemState[direction].coordinateSystem )
1767  {
1768  delete ((Spherical*)(coordinateSystemState[direction].coordinateSystem));
1769  coordinateSystemState[direction].coordinateSystem = 0;
1770  }
1771  break;
1773  if( coordinateSystemState[direction].parameters.geodeticParameters )
1774  {
1775  delete coordinateSystemState[direction].parameters.geodeticParameters;
1776  coordinateSystemState[direction].parameters.geodeticParameters = 0;
1777  }
1778  break;
1780  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1781  {
1782  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1783  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1784  }
1785  if( coordinateSystemState[direction].coordinateSystem )
1786  {
1787  delete ((GEOREF*)(coordinateSystemState[direction].coordinateSystem));
1788  coordinateSystemState[direction].coordinateSystem = 0;
1789  }
1790  break;
1792  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1793  {
1794  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1795  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1796  }
1797  if( coordinateSystemState[direction].coordinateSystem )
1798  {
1799  delete ((GARS*)(coordinateSystemState[direction].coordinateSystem));
1800  coordinateSystemState[direction].coordinateSystem = 0;
1801  }
1802  break;
1804  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1805  {
1806  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1807  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1808  }
1809  if( coordinateSystemState[direction].coordinateSystem )
1810  {
1811  delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
1812  coordinateSystemState[direction].coordinateSystem = 0;
1813  }
1814  break;
1816  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1817  {
1818  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1819  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1820  }
1821  if( coordinateSystemState[direction].coordinateSystem )
1822  {
1823  delete ((TransverseCylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
1824  coordinateSystemState[direction].coordinateSystem = 0;
1825  }
1826  break;
1828  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1829  {
1830  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1831  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1832  }
1833  if( coordinateSystemState[direction].coordinateSystem )
1834  {
1835  delete ((TransverseMercator*)(coordinateSystemState[direction].coordinateSystem));
1836  coordinateSystemState[direction].coordinateSystem = 0;
1837  }
1838  break;
1840  if( coordinateSystemState[direction].parameters.localCartesianParameters )
1841  {
1842  delete coordinateSystemState[direction].parameters.localCartesianParameters;
1843  coordinateSystemState[direction].parameters.localCartesianParameters = 0;
1844  }
1845  if( coordinateSystemState[direction].coordinateSystem )
1846  {
1847  delete ((LocalCartesian*)(coordinateSystemState[direction].coordinateSystem));
1848  coordinateSystemState[direction].coordinateSystem = 0;
1849  }
1850  break;
1852  if( coordinateSystemState[direction].parameters.localCartesianParameters )
1853  {
1854  delete coordinateSystemState[direction].parameters.localCartesianParameters;
1855  coordinateSystemState[direction].parameters.localCartesianParameters = 0;
1856  }
1857  if( coordinateSystemState[direction].coordinateSystem )
1858  {
1859  delete ((LocalSpherical*)(coordinateSystemState[direction].coordinateSystem));
1860  coordinateSystemState[direction].coordinateSystem = 0;
1861  }
1862  break;
1864  if( coordinateSystemState[direction].parameters.mercatorStandardParallelParameters )
1865  {
1866  delete coordinateSystemState[direction].parameters.mercatorStandardParallelParameters;
1867  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
1868  }
1869  if( coordinateSystemState[direction].coordinateSystem )
1870  {
1871  delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
1872  coordinateSystemState[direction].coordinateSystem = 0;
1873  }
1874  break;
1876  if( coordinateSystemState[direction].parameters.mercatorScaleFactorParameters )
1877  {
1878  delete coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
1879  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
1880  }
1881  if( coordinateSystemState[direction].coordinateSystem )
1882  {
1883  delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
1884  coordinateSystemState[direction].coordinateSystem = 0;
1885  }
1886  break;
1888  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1889  {
1890  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1891  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1892  }
1893  if( coordinateSystemState[direction].coordinateSystem )
1894  {
1895  delete ((MGRS*)(coordinateSystemState[direction].coordinateSystem));
1896  coordinateSystemState[direction].coordinateSystem = 0;
1897  }
1898  break;
1900  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1901  {
1902  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1903  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1904  }
1905  if( coordinateSystemState[direction].coordinateSystem )
1906  {
1907  delete ((USNG*)(coordinateSystemState[direction].coordinateSystem));
1908  coordinateSystemState[direction].coordinateSystem = 0;
1909  }
1910  break;
1912  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1913  {
1914  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1915  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1916  }
1917  if( coordinateSystemState[direction].coordinateSystem )
1918  {
1919  delete ((NZMG*)(coordinateSystemState[direction].coordinateSystem));
1920  coordinateSystemState[direction].coordinateSystem = 0;
1921  }
1922  break;
1923  case CoordinateType::neys:
1924  if( coordinateSystemState[direction].parameters.neysParameters )
1925  {
1926  delete coordinateSystemState[direction].parameters.neysParameters;
1927  coordinateSystemState[direction].parameters.neysParameters = 0;
1928  }
1929  if( coordinateSystemState[direction].coordinateSystem )
1930  {
1931  delete ((Neys*)(coordinateSystemState[direction].coordinateSystem));
1932  coordinateSystemState[direction].coordinateSystem = 0;
1933  }
1934  break;
1936  if( coordinateSystemState[direction].parameters.obliqueMercatorParameters )
1937  {
1938  delete coordinateSystemState[direction].parameters.obliqueMercatorParameters;
1939  coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
1940  }
1941  if( coordinateSystemState[direction].coordinateSystem )
1942  {
1943  delete ((ObliqueMercator*)(coordinateSystemState[direction].coordinateSystem));
1944  coordinateSystemState[direction].coordinateSystem = 0;
1945  }
1946  break;
1948  if( coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters )
1949  {
1950  delete coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
1951  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
1952  }
1953  if( coordinateSystemState[direction].coordinateSystem )
1954  {
1955  delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
1956  coordinateSystemState[direction].coordinateSystem = 0;
1957  }
1958  break;
1960  if( coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters )
1961  {
1962  delete coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
1963  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
1964  }
1965  if( coordinateSystemState[direction].coordinateSystem )
1966  {
1967  delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
1968  coordinateSystemState[direction].coordinateSystem = 0;
1969  }
1970  break;
1972  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1973  {
1974  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1975  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1976  }
1977  if( coordinateSystemState[direction].coordinateSystem )
1978  {
1979  delete ((UPS*)(coordinateSystemState[direction].coordinateSystem));
1980  coordinateSystemState[direction].coordinateSystem = 0;
1981  }
1982  break;
1984  if( coordinateSystemState[direction].parameters.utmParameters )
1985  {
1986  delete coordinateSystemState[direction].parameters.utmParameters;
1987  coordinateSystemState[direction].parameters.utmParameters = 0;
1988  }
1989  if( coordinateSystemState[direction].coordinateSystem )
1990  {
1991  delete ((UTM*)(coordinateSystemState[direction].coordinateSystem));
1992  coordinateSystemState[direction].coordinateSystem = 0;
1993  }
1994  break;
1996  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1997  {
1998  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1999  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
2000  }
2001  if( coordinateSystemState[direction].coordinateSystem )
2002  {
2003  delete ((WebMercator*)(coordinateSystemState[direction].coordinateSystem));
2004  coordinateSystemState[direction].coordinateSystem = 0;
2005  }
2006  break;
2007  default:
2008  break;
2009  }
2010 }
2011 
2012 
2013 void CoordinateConversionService::copyParameters(
2014  SourceOrTarget::Enum direction,
2015  CoordinateType::Enum coordinateType,
2016  Parameters parameters )
2017 {
2018 /*
2019  * The function copyParameters uses the input parameters to set the value of the
2020  * current parameters.
2021  *
2022  * direction : Indicates whether the coordinate system is to be used for
2023  * source or target (input)
2024  * coordinateType : Coordinate system type (input)
2025  * parameters : Coordinate system parameters to copy (input)
2026  */
2027 
2028  initCoordinateSystemState( direction );
2029 
2030  switch( coordinateType )
2031  {
2034  setCoordinateSystem( direction, parameters.mapProjection6Parameters );
2035  break;
2037  case CoordinateType::bonne:
2044  setCoordinateSystem( direction, parameters.mapProjection4Parameters );
2045  break;
2052  setCoordinateSystem( direction, parameters.mapProjection3Parameters );
2053  break;
2055  setCoordinateSystem( direction, parameters.equidistantCylindricalParameters );
2056  break;
2058  setCoordinateSystem( direction, parameters.geodeticParameters );
2059  break;
2063  setCoordinateSystem( direction, parameters.mapProjection5Parameters );
2064  break;
2067  setCoordinateSystem( direction, parameters.localCartesianParameters );
2068  break;
2070  setCoordinateSystem( direction, parameters.mercatorStandardParallelParameters );
2071  break;
2073  setCoordinateSystem( direction, parameters.mercatorScaleFactorParameters );
2074  break;
2075  case CoordinateType::neys:
2076  setCoordinateSystem( direction, parameters.neysParameters );
2077  break;
2079  setCoordinateSystem( direction, parameters.obliqueMercatorParameters );
2080  break;
2082  setCoordinateSystem( direction, parameters.polarStereographicStandardParallelParameters );
2083  break;
2085  setCoordinateSystem( direction, parameters.polarStereographicScaleFactorParameters );
2086  break;
2088  setCoordinateSystem( direction, parameters.utmParameters );
2089  break;
2100  setCoordinateSystem( direction, parameters.coordinateSystemParameters );
2101  break;
2102  default:
2103  break;
2104  }
2105 }
2106 
2107 
2108 void CoordinateConversionService::convert(
2109  SourceOrTarget::Enum sourceDirection,
2110  SourceOrTarget::Enum targetDirection,
2111  CoordinateTuple* sourceCoordinates,
2112  Accuracy* sourceAccuracy,
2113  CoordinateTuple& targetCoordinates,
2114  Accuracy& targetAccuracy )
2115 {
2116 /*
2117  * The function convert converts the current source coordinates in the coordinate
2118  * system defined by the current source coordinate system parameters and source datum,
2119  * into target coordinates in the coordinate system defined by the target coordinate
2120  * system parameters and target datum.
2121  *
2122  * sourceDirection: Indicates which set of coordinates and parameters to use as the source (input)
2123  * targetDirection: Indicates which set of coordinates and parameters to use as the target (input)
2124  */
2125 
2126  CCSThreadLock lock(&mutex);
2127 
2128  GeodeticCoordinates* _convertedGeodetic = 0;
2129  GeodeticCoordinates* _wgs84Geodetic = 0;
2130  GeodeticCoordinates* _shiftedGeodetic = 0;
2131 
2132  bool special = false;
2133 
2134  Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
2135  Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
2136 
2137  char sourceWarningMessage[256] = "";
2138  char targetWarningMessage[256] = "";
2139 
2140  if ( // NGA only allows Web Mercator conversions to geodetic
2141  (source->coordinateType == CoordinateType::webMercator) &&
2142  (target->coordinateType != CoordinateType::geodetic) )
2143  {
2145  }
2146 
2147  try
2148  {
2149  try
2150  {
2151  /********************************************************/
2152  /* Check for special cases when there is no datum shift */
2153  /********************************************************/
2154  if (source->datumIndex == target->datumIndex)
2155  {
2156  if((source->coordinateType == CoordinateType::geocentric) &&
2157  (target->coordinateType == CoordinateType::localCartesian))
2158  {
2159  special = true;
2160 
2161  CartesianCoordinates* coordinates =
2162  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2163 
2164  CartesianCoordinates* cartesianCoordinates =
2165  ((LocalCartesian*)(
2166  target->coordinateSystem))->convertFromGeocentric(
2167  coordinates );
2168  (dynamic_cast<CartesianCoordinates&>(targetCoordinates)) =
2169  *dynamic_cast<CartesianCoordinates*>( cartesianCoordinates );
2170  delete cartesianCoordinates;
2171  }
2172  else if((source->coordinateType == CoordinateType::localCartesian) &&
2173  (target->coordinateType == CoordinateType::geocentric))
2174  {
2175  special = true;
2176 
2177  CartesianCoordinates* coordinates =
2178  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2179 
2180  CartesianCoordinates* cartesianCoordinates =
2181  ((LocalCartesian*)(source->coordinateSystem))->convertToGeocentric(
2182  coordinates );
2183  (dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ) =
2184  *dynamic_cast< CartesianCoordinates* >( cartesianCoordinates );
2185  delete cartesianCoordinates;
2186  }
2187  else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
2188  (target->coordinateType == CoordinateType::universalTransverseMercator) &&
2189  (target->parameters.utmParameters->override() == 0))
2190  {
2191  special = true;
2192 
2193  MGRSorUSNGCoordinates* coordinates =
2194  dynamic_cast<MGRSorUSNGCoordinates*>(sourceCoordinates);
2195 
2196  UTMCoordinates* utmCoordinates =
2197  ((MGRS*)(source->coordinateSystem))->convertToUTM( coordinates );
2198  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) =
2199  *dynamic_cast< UTMCoordinates* >( utmCoordinates );
2200  delete utmCoordinates;
2201  }
2202  else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
2203  (target->coordinateType == CoordinateType::universalPolarStereographic))
2204  {
2205  special = true;
2206 
2207  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2208 
2209  UPSCoordinates* upsCoordinates = ((MGRS*)(source->coordinateSystem))->convertToUPS( coordinates );
2210  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
2211  delete upsCoordinates;
2212  }
2213  else if ((source->coordinateType == CoordinateType::universalTransverseMercator) &&
2214  (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
2215  {
2216  special = true;
2217 
2218  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2219  if (temp_precision < 0)
2220  temp_precision = Precision::degree;
2221  if (temp_precision > 5)
2222  temp_precision = Precision::tenthOfSecond;
2223 
2224  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
2225 
2226  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
2227  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2228  delete mgrsOrUSNGCoordinates;
2229  }
2230  else if ((source->coordinateType == CoordinateType::universalPolarStereographic) && (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
2231  {
2232  special = true;
2233 
2234  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2235  if (temp_precision < 0)
2236  temp_precision = Precision::degree;
2237  if (temp_precision > 5)
2238  temp_precision = Precision::tenthOfSecond;
2239 
2240  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
2241 
2242  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUPS( coordinates, temp_precision );
2243  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2244  delete mgrsOrUSNGCoordinates;
2245  }
2246  else if ((source->coordinateType == CoordinateType::usNationalGrid) &&
2247  (target->coordinateType == CoordinateType::universalTransverseMercator) && (target->parameters.utmParameters->override() == 0))
2248  {
2249  special = true;
2250 
2251  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2252 
2253  UTMCoordinates* utmCoordinates = ((USNG*)(source->coordinateSystem))->convertToUTM( coordinates );
2254  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UTMCoordinates* >( utmCoordinates );
2255  delete utmCoordinates;
2256  }
2257  else if ((source->coordinateType == CoordinateType::usNationalGrid) && (target->coordinateType == CoordinateType::universalPolarStereographic))
2258  {
2259  special = true;
2260 
2261  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2262 
2263  UPSCoordinates* upsCoordinates = ((USNG*)(source->coordinateSystem))->convertToUPS( coordinates );
2264  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
2265  delete upsCoordinates;
2266  }
2267  else if ((source->coordinateType == CoordinateType::universalTransverseMercator) && (target->coordinateType == CoordinateType::usNationalGrid))
2268  {
2269  special = true;
2270 
2271  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2272  if (temp_precision < 0)
2273  temp_precision = Precision::degree;
2274  if (temp_precision > 5)
2275  temp_precision = Precision::tenthOfSecond;
2276 
2277  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
2278 
2279  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((USNG*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
2280  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2281  delete mgrsOrUSNGCoordinates;
2282  }
2283  else if((source->coordinateType == CoordinateType::universalPolarStereographic) &&
2284  (target->coordinateType == CoordinateType::usNationalGrid))
2285  {
2286  special = true;
2287 
2288  Precision::Enum temp_precision =
2289  ( dynamic_cast< MGRSorUSNGCoordinates& >(
2290  targetCoordinates ) ).precision();
2291  if (temp_precision < 0)
2292  temp_precision = Precision::degree;
2293  if (temp_precision > 5)
2294  temp_precision = Precision::tenthOfSecond;
2295 
2296  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >(
2297  sourceCoordinates );
2298 
2299  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates =
2300  ((USNG*)(target->coordinateSystem))->convertFromUPS(
2301  coordinates, temp_precision );
2302  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) =
2303  *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2304  delete mgrsOrUSNGCoordinates;
2305  }
2306  else if ((source->coordinateType == CoordinateType::transverseMercator) &&
2307  (target->coordinateType == CoordinateType::britishNationalGrid))
2308  {
2309  MapProjection5Parameters* param =
2310  source->parameters.mapProjection5Parameters;
2311 
2312  if ((param->centralMeridian() == -2.0 * PI / 180) &&
2313  (param->originLatitude() == 49.0 * PI / 180) &&
2314  (param->scaleFactor() == .9996012717) &&
2315  (param->falseEasting() == 400000.0) &&
2316  (param->falseNorthing() == -100000.0))
2317  {
2318  special = true;
2319 
2320  Precision::Enum temp_precision = ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).precision();
2321  if (temp_precision < 0)
2322  temp_precision = Precision::degree;
2323  if (temp_precision > 5)
2324  temp_precision = Precision::tenthOfSecond;
2325 
2326  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2327 
2328  BNGCoordinates* bngCoordinates =
2329  ((BritishNationalGrid*)(target->coordinateSystem))->
2330  convertFromTransverseMercator( coordinates, temp_precision );
2331  ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ) =
2332  *dynamic_cast< BNGCoordinates* >( bngCoordinates );
2333  delete bngCoordinates;
2334  }
2335  else
2336  special = false;
2337  }
2338  else if((source->coordinateType == CoordinateType::britishNationalGrid) &&
2339  (target->coordinateType == CoordinateType::transverseMercator))
2340  {
2341  MapProjection5Parameters* param =
2342  target->parameters.mapProjection5Parameters;
2343 
2344  if ((param->centralMeridian() == -2.0 * PI / 180) &&
2345  (param->originLatitude() == 49.0 * PI / 180) &&
2346  (param->scaleFactor() == .9996012717) &&
2347  (param->falseEasting() == 400000.0) &&
2348  (param->falseNorthing() == -100000.0))
2349  {
2350  special = true;
2351 
2352  BNGCoordinates* coordinates =
2353  dynamic_cast< BNGCoordinates* >( sourceCoordinates );
2354 
2355  MapProjectionCoordinates* mapProjectionCoordinates =
2356  ((BritishNationalGrid*)(
2357  source->coordinateSystem))->convertToTransverseMercator(
2358  coordinates );
2359  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ) =
2360  *dynamic_cast< MapProjectionCoordinates* >(
2361  mapProjectionCoordinates );
2362  delete mapProjectionCoordinates;
2363  }
2364  else
2365  special = false;
2366  }
2367  }
2368  }
2370  {
2372  "Input ",
2373  Coordinate_System_Table[source->coordinateType].Name,
2374  ": \n", e.getMessage() );
2375  }
2376 
2377  if( !special )
2378  {
2379  /**********************************************************/
2380  /* First coordinate conversion stage, convert to Geodetic */
2381  /**********************************************************/
2382 
2383  _convertedGeodetic = convertSourceToGeodetic(
2384  sourceDirection, sourceCoordinates, sourceWarningMessage );
2385 
2386  /******************************/
2387  /* Datum Transformation Stage */
2388  /******************************/
2389 
2390  HeightType::Enum input_height_type;
2391  HeightType::Enum output_height_type;
2392 
2393  if (source->coordinateType == CoordinateType::geodetic)
2394  input_height_type = source->parameters.geodeticParameters->heightType();
2395  else if ((source->coordinateType == CoordinateType::geocentric) ||
2396  (source->coordinateType == CoordinateType::localCartesian) ||
2397  (source->coordinateType == CoordinateType::localSpherical) ||
2398  (source->coordinateType == CoordinateType::spherical))
2399  input_height_type = HeightType::ellipsoidHeight;
2400  else
2401  input_height_type = HeightType::noHeight;
2402 
2403  if (target->coordinateType == CoordinateType::geodetic)
2404  output_height_type = target->parameters.geodeticParameters->heightType();
2405  else if ((target->coordinateType == CoordinateType::geocentric) ||
2406  (target->coordinateType == CoordinateType::localCartesian) ||
2407  (target->coordinateType == CoordinateType::localSpherical) ||
2408  (target->coordinateType == CoordinateType::spherical))
2409  output_height_type = HeightType::ellipsoidHeight;
2410  else
2411  output_height_type = HeightType::noHeight;
2412 
2413  if ((source->datumIndex == target->datumIndex) &&
2414  ((input_height_type == output_height_type) ||
2415  (input_height_type == HeightType::noHeight) ||
2416  (output_height_type == HeightType::noHeight)))
2417  { /* Copy coordinate tuple */
2418  _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
2419  _shiftedGeodetic = new GeodeticCoordinates( *_convertedGeodetic );
2420 
2421  if ((input_height_type == HeightType::noHeight) ||
2422  (output_height_type == HeightType::noHeight))
2423  {
2424  _shiftedGeodetic->setHeight( 0 );
2425  }
2426 
2427  if(source->datumIndex != WGS84_datum_index &&
2428  target->datumIndex != WGS84_datum_index)
2429  {
2430  long valid = 0;
2431 
2432  /* check source datum validity */
2433  datumLibraryImplementation->validDatum(
2434  source->datumIndex, _wgs84Geodetic->longitude(),
2435  _wgs84Geodetic->latitude(), &valid );
2436  if( !valid )
2437  {
2438  strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
2439  }
2440 
2441  /* check target datum validity */
2442  datumLibraryImplementation->validDatum(
2443  target->datumIndex, _wgs84Geodetic->longitude(),
2444  _wgs84Geodetic->latitude(), &valid );
2445  if( !valid )
2446  {
2447  strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
2448  }
2449  }
2450  }
2451  else
2452  { /* Shift to WGS84, apply geoid correction, shift to target datum */
2453  if (source->datumIndex != WGS84_datum_index)
2454  {
2455  _wgs84Geodetic = datumLibraryImplementation->geodeticShiftToWGS84(
2456  source->datumIndex, _convertedGeodetic );
2457 
2458  switch(input_height_type)
2459  {
2466  _wgs84Geodetic->setHeight( _convertedGeodetic->height() );
2467  break;
2468  case HeightType::noHeight:
2469  _wgs84Geodetic->setHeight( 0.0 );
2470  break;
2472  default:
2473  break;
2474  }
2475 
2476  /* check source datum validity */
2477  long sourceValid = 0;
2478 
2479  datumLibraryImplementation->validDatum(
2480  source->datumIndex, _wgs84Geodetic->longitude(),
2481  _wgs84Geodetic->latitude(), &sourceValid );
2482  if( !sourceValid )
2483  {
2484  strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
2485  }
2486  }
2487  else
2488  { /* Copy coordinate tuple */
2489  _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
2490  if( input_height_type == HeightType::noHeight )
2491  _wgs84Geodetic->setHeight( 0.0 );
2492  }
2493 
2494  if(input_height_type != output_height_type)
2495  {
2496  double tempHeight;
2497 
2498  /* Convert the source height value to an ellipsoid height value */
2499  switch(input_height_type)
2500  {
2503  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2504  _wgs84Geodetic->height(), &tempHeight);
2505  break;
2508  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2509  _wgs84Geodetic->height(), &tempHeight);
2510  break;
2513  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2514  _wgs84Geodetic->height(), &tempHeight );
2515  break;
2518  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2519  _wgs84Geodetic->height(), &tempHeight );
2520  break;
2523  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2524  _wgs84Geodetic->height(), &tempHeight );
2525  break;
2528  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2529  _wgs84Geodetic->height(), &tempHeight );
2530  break;
2532  default:
2533  tempHeight = _wgs84Geodetic->height();
2534  break;
2535  }
2536 
2537  double correctedHeight;
2538 
2539  /* Convert the ellipsoid height value to the target height value */
2540  switch(output_height_type)
2541  {
2544  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2545  tempHeight, &correctedHeight );
2546  break;
2549  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2550  tempHeight, &correctedHeight );
2551  break;
2554  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2555  tempHeight, &correctedHeight );
2556  break;
2559  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2560  tempHeight, &correctedHeight );
2561  break;
2564  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2565  tempHeight, &correctedHeight );
2566  break;
2569  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2570  tempHeight, &correctedHeight );
2571  break;
2573  default:
2574  correctedHeight = tempHeight;
2575  break;
2576  }
2577 
2578  /* Set the target height */
2579  _wgs84Geodetic->setHeight( correctedHeight );
2580  }
2581 
2582  if (target->datumIndex != WGS84_datum_index)
2583  {
2584  _shiftedGeodetic =
2585  datumLibraryImplementation->geodeticShiftFromWGS84(
2586  _wgs84Geodetic, target->datumIndex );
2587 
2588  switch(output_height_type)
2589  {
2596  _shiftedGeodetic->setHeight( _wgs84Geodetic->height() );
2597  break;
2598  case HeightType::noHeight:
2599  _shiftedGeodetic->setHeight( 0.0 );
2600  break;
2602  default:
2603  break;
2604  }
2605 
2606  /* check target datum validity */
2607  long targetValid = 0;
2608 
2609  datumLibraryImplementation->validDatum(
2610  target->datumIndex, _wgs84Geodetic->longitude(),
2611  _wgs84Geodetic->latitude(), &targetValid );
2612  if( !targetValid )
2613  {
2614  strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
2615  }
2616  }
2617  else
2618  { /* Copy coordinate tuple */
2619  _shiftedGeodetic = new GeodeticCoordinates( *_wgs84Geodetic );
2620  if( output_height_type == HeightType::noHeight )
2621  _shiftedGeodetic->setHeight( 0.0 );
2622  }
2623  }
2624 
2625  /* calculate conversion errors */
2626  if( strlen( sourceWarningMessage ) > 0 ||
2627  strlen( targetWarningMessage ) > 0 )
2628  targetAccuracy.set(-1.0, -1.0, -1.0);
2629  else
2630  {
2631  Precision::Enum precS = sourceCoordinates->precision();
2632  Precision::Enum precT = targetCoordinates.precision();
2633  Precision::Enum prec = precS;
2634  if( precT < prec )
2635  {
2636  prec = precT;
2637  }
2638 
2639  Accuracy* _targetAccuracy =
2640  datumLibraryImplementation->datumShiftError(
2641  source->datumIndex, target->datumIndex,
2642  _wgs84Geodetic->longitude(),
2643  _wgs84Geodetic->latitude(), sourceAccuracy, prec );
2644 
2645  targetAccuracy.set(
2646  _targetAccuracy->circularError90(),
2647  _targetAccuracy->linearError90(),
2648  _targetAccuracy->sphericalError90() );
2649 
2650  delete _targetAccuracy;
2651  }
2652 
2653  /*************************************************************/
2654  /* Second coordinate conversion stage, convert from Geodetic */
2655  /*************************************************************/
2656 
2657  convertGeodeticToTarget(
2658  targetDirection, _shiftedGeodetic,
2659  targetCoordinates, targetWarningMessage );
2660 
2661  // Format and set the warning message in the target coordinates
2662  char warningMessage[500] = "";
2663  bool warning = false;
2664  if( strlen( sourceWarningMessage ) > 0 )
2665  {
2666  strcpy( warningMessage, "Input " );
2667  strcat( warningMessage,
2668  Coordinate_System_Table[source->coordinateType].Name );
2669  strcat( warningMessage, ": \n" );
2670  strcat( warningMessage, sourceWarningMessage );
2671  warning = true;
2672  }
2673 
2674  if( strlen( targetWarningMessage ) > 0 )
2675  {
2676  if( strlen( warningMessage ) > 0 )
2677  strcat( warningMessage, "\nOutput " );
2678  else
2679  strcpy( warningMessage, "Output " );
2680 
2681  strcat( warningMessage,
2682  Coordinate_System_Table[target->coordinateType].Name );
2683  strcat( warningMessage, ": \n" );
2684  strcat( warningMessage, targetWarningMessage );
2685  warning = true;
2686  }
2687 
2688  if( warning )
2689  {
2690  warningMessage[strlen( warningMessage )] = '\0';
2691  targetCoordinates.setWarningMessage(warningMessage);
2692  }
2693  } /* if (!special) */
2694  }
2696  {
2697  targetAccuracy.set(-1.0, -1.0, -1.0);
2698 
2699  /* since initialized to 0 at the top is safe to
2700  cleanup memory before rethrowing the exception */
2701  delete _convertedGeodetic;
2702  delete _shiftedGeodetic;
2703  delete _wgs84Geodetic;
2704 
2706  }
2707 
2708  // cleanup memory before returning
2709  delete _convertedGeodetic;
2710  delete _shiftedGeodetic;
2711  delete _wgs84Geodetic;
2712 
2713 }
2714 
2715 
2716 GeodeticCoordinates* CoordinateConversionService::convertSourceToGeodetic(
2717  SourceOrTarget::Enum sourceDirection,
2718  CoordinateTuple* sourceCoordinates,
2719  char* sourceWarningMessage )
2720 {
2721  Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
2722 
2723  /**********************************************************/
2724  /* First coordinate conversion stage, convert to Geodetic */
2725  /**********************************************************/
2726  try
2727  {
2728  switch (source->coordinateType)
2729  {
2731  {
2732  CartesianCoordinates* coordinates =
2733  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2734 
2735  return ((Geocentric*)(source->coordinateSystem))->convertToGeodetic(
2736  coordinates );
2737  }
2739  {
2740  SphericalCoordinates* coordinates =
2741  dynamic_cast< SphericalCoordinates* >( sourceCoordinates );
2742 
2743  return ((Spherical*)(source->coordinateSystem))->convertToGeodetic(
2744  coordinates );
2745  }
2747  {
2748  GeodeticCoordinates* _convertedGeodetic =
2749  new GeodeticCoordinates(
2750  *dynamic_cast< GeodeticCoordinates* >( sourceCoordinates ) );
2751 
2752  if( source->parameters.geodeticParameters->heightType() == HeightType::noHeight )
2753  _convertedGeodetic->setHeight( 0.0 );
2754 
2755  return _convertedGeodetic;
2756  }
2758  {
2759  GEOREFCoordinates* coordinates = dynamic_cast< GEOREFCoordinates* >(
2760  sourceCoordinates );
2761 
2762  return ((GEOREF*)(source->coordinateSystem))->convertToGeodetic(
2763  coordinates );
2764  }
2766  {
2767  MapProjectionCoordinates* coordinates =
2768  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2769 
2770  return ((AlbersEqualAreaConic*)(
2771  source->coordinateSystem))->convertToGeodetic( coordinates );
2772  }
2774  {
2775  MapProjectionCoordinates* coordinates =
2776  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2777 
2778  return ((AzimuthalEquidistant*)(
2779  source->coordinateSystem))->convertToGeodetic( coordinates );
2780  }
2782  {
2783  BNGCoordinates* coordinates = dynamic_cast< BNGCoordinates* >( sourceCoordinates );
2784 
2785  return ((BritishNationalGrid*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2786  }
2787  case CoordinateType::bonne:
2788  {
2789  MapProjectionCoordinates* coordinates =
2790  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2791 
2792  return ((Bonne*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2793  }
2795  {
2796  MapProjectionCoordinates* coordinates =
2797  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2798 
2799  GeodeticCoordinates* _convertedGeodetic =
2800  ((Cassini*)(source->coordinateSystem))->convertToGeodetic(
2801  coordinates );
2802 
2803  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2804  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2805 
2806  return _convertedGeodetic;
2807  }
2809  {
2810  MapProjectionCoordinates* coordinates =
2811  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2812 
2813  return ((CylindricalEqualArea*)(
2814  source->coordinateSystem))->convertToGeodetic( coordinates);
2815  }
2817  {
2818  MapProjectionCoordinates* coordinates =
2819  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2820 
2821  return ((Eckert4*)(source->coordinateSystem))->convertToGeodetic(
2822  coordinates );
2823  }
2825  {
2826  MapProjectionCoordinates* coordinates =
2827  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2828 
2829  return ((Eckert6*)(source->coordinateSystem))->convertToGeodetic(
2830  coordinates );
2831  }
2833  {
2834  MapProjectionCoordinates* coordinates =
2835  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2836 
2837  return ((EquidistantCylindrical*)(
2838  source->coordinateSystem))->convertToGeodetic( coordinates );
2839  }
2841  {
2842  GARSCoordinates* coordinates = dynamic_cast< GARSCoordinates* >( sourceCoordinates );
2843 
2844  return ((GARS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2845  }
2847  {
2848  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2849 
2850  return ((Gnomonic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2851  }
2853  {
2854  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2855 
2856  return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2857  }
2859  {
2860  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2861 
2862  return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2863  }
2865  {
2866  CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2867 
2868  return ((LocalCartesian*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2869  }
2871  {
2872  SphericalCoordinates* coordinates = dynamic_cast< SphericalCoordinates* >( sourceCoordinates );
2873 
2874  return ((LocalSpherical*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2875  }
2878  {
2879  MapProjectionCoordinates* coordinates =
2880  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2881 
2882  return ((Mercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2883  }
2885  {
2886  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2887 
2888  GeodeticCoordinates* _convertedGeodetic = ((MGRS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2889 
2890  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2891  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2892 
2893  return _convertedGeodetic;
2894  }
2896  {
2897  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2898 
2899  return ((MillerCylindrical*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2900  }
2902  {
2903  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2904 
2905  return ((Mollweide*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2906  }
2907  case CoordinateType::neys:
2908  {
2909  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2910 
2911  return ((Neys*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2912  }
2914  {
2915  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2916 
2917  return ((NZMG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2918  }
2920  {
2921  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2922 
2923  GeodeticCoordinates* _convertedGeodetic = ((ObliqueMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2924 
2925  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2926  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2927 
2928  return _convertedGeodetic;
2929  }
2931  {
2932  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2933 
2934  return ((Orthographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2935  }
2938  {
2939  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2940 
2941  return ((PolarStereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2942  }
2944  {
2945  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2946 
2947  return ((Polyconic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2948  }
2950  {
2951  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2952 
2953  return ((Sinusoidal*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2954  }
2956  {
2957  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2958 
2959  return ((Stereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2960  }
2962  {
2963  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2964 
2965  return ((TransverseCylindricalEqualArea*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2966  }
2968  {
2969  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2970 
2971  GeodeticCoordinates* _convertedGeodetic = ((TransverseMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2972 
2973  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2974  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2975 
2976  return _convertedGeodetic;
2977  }
2979  {
2980  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
2981 
2982  return ((UPS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2983  }
2985  {
2986  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2987 
2988  GeodeticCoordinates* _convertedGeodetic = ((USNG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2989 
2990  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2991  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2992 
2993  return _convertedGeodetic;
2994  }
2996  {
2997  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
2998 
2999  return ((UTM*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3000  }
3002  {
3003  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3004 
3005  return ((VanDerGrinten*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3006  }
3008  {
3009  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3010 
3011  return ((WebMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3012  }
3013  }
3014  }
3016  {
3018  "Input ", Coordinate_System_Table[source->coordinateType].Name,
3019  ": \n", e.getMessage() );
3020  }
3021  return NULL;
3022 }
3023 
3024 
3025 void CoordinateConversionService::convertGeodeticToTarget(
3026  SourceOrTarget::Enum targetDirection,
3027  GeodeticCoordinates* _shiftedGeodetic,
3028  CoordinateTuple& targetCoordinates,
3029  char* targetWarningMessage )
3030 {
3031  Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
3032 
3033  /*************************************************************/
3034  /* Second coordinate conversion stage, convert from Geodetic */
3035  /*************************************************************/
3036  try
3037  {
3038  switch (target->coordinateType)
3039  {
3041  {
3042  CartesianCoordinates* coordinates =
3043  ((Geocentric*)(target->coordinateSystem))->convertFromGeodetic(
3044  _shiftedGeodetic );
3045 
3046  ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set(
3047  coordinates->x(), coordinates->y(), coordinates->z() );
3048 
3049  delete coordinates;
3050 
3051  break;
3052  }
3054  {
3055  SphericalCoordinates* coordinates =
3056  ((Spherical*)(target->coordinateSystem))->convertFromGeodetic(
3057  _shiftedGeodetic );
3058 
3059  ( dynamic_cast< SphericalCoordinates& >( targetCoordinates ) ).setSphericalCoord(
3060  coordinates->sphericalLongitude(), coordinates->sphericalLatitude(), coordinates->radius() );
3061 
3062  delete coordinates;
3063 
3064  break;
3065  }
3067  {
3068  if (target->parameters.geodeticParameters->heightType() == HeightType::noHeight)
3069  ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set(
3070  _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(), 0.0 );
3071  else
3072  ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set(
3073  _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(),
3074  _shiftedGeodetic->height() );
3075 
3076  break;
3077  }
3079  {
3080  Precision::Enum temp_precision =
3081  ( dynamic_cast< GEOREFCoordinates& >(
3082  targetCoordinates ) ).precision();
3083  if (temp_precision < 0)
3084  temp_precision = Precision::degree;
3085  if (temp_precision > 5)
3086  temp_precision = Precision::tenthOfSecond;
3087 
3088  GEOREFCoordinates* coordinates =
3089  ((GEOREF*)(target->coordinateSystem))->convertFromGeodetic(
3090  _shiftedGeodetic, temp_precision );
3091 
3092  ( dynamic_cast< GEOREFCoordinates& >( targetCoordinates ) ).set(
3093  coordinates->GEOREFString() );
3094 
3095  delete coordinates;
3096 
3097  break;
3098  }
3100  {
3101  MapProjectionCoordinates* coordinates =
3103  target->coordinateSystem))->convertFromGeodetic(
3104  _shiftedGeodetic );
3105 
3106  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3107  coordinates->easting(), coordinates->northing() );
3108 
3109  delete coordinates;
3110 
3111  break;
3112  }
3114  {
3115  MapProjectionCoordinates* coordinates =
3117  target->coordinateSystem))->convertFromGeodetic(
3118  _shiftedGeodetic );
3119 
3120  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3121  coordinates->easting(), coordinates->northing() );
3122 
3123  delete coordinates;
3124 
3125  break;
3126  }
3128  {
3129  Precision::Enum temp_precision =
3130  ( dynamic_cast< BNGCoordinates& >(targetCoordinates ) ).precision();
3131  if (temp_precision < 0)
3132  temp_precision = Precision::degree;
3133  if (temp_precision > 5)
3134  temp_precision = Precision::tenthOfSecond;
3135 
3136  BNGCoordinates* coordinates =
3137  ((BritishNationalGrid*)(
3138  target->coordinateSystem))->convertFromGeodetic(
3139  _shiftedGeodetic, temp_precision );
3140 
3141  ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).set(
3142  coordinates->BNGString() );
3143 
3144  delete coordinates;
3145 
3146  break;
3147  }
3148  case CoordinateType::bonne:
3149  {
3150  MapProjectionCoordinates* coordinates =
3151  ((Bonne*)(target->coordinateSystem))->convertFromGeodetic(
3152  _shiftedGeodetic );
3153 
3154  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3155  coordinates->easting(), coordinates->northing() );
3156 
3157  delete coordinates;
3158 
3159  break;
3160  }
3162  {
3163  MapProjectionCoordinates* coordinates =
3164  ((Cassini*)(target->coordinateSystem))->convertFromGeodetic(
3165  _shiftedGeodetic );
3166 
3167  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3168  coordinates->easting(), coordinates->northing() );
3169 
3170  if( strlen( coordinates->warningMessage() ) > 0)
3171  {
3172  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3173  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3174  }
3175 
3176  delete coordinates;
3177 
3178  break;
3179  }
3181  {
3182  MapProjectionCoordinates* coordinates =
3184  target->coordinateSystem))->convertFromGeodetic(
3185  _shiftedGeodetic );
3186 
3187  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3188  coordinates->easting(), coordinates->northing() );
3189 
3190  delete coordinates;
3191 
3192  break;
3193  }
3195  {
3196  MapProjectionCoordinates* coordinates =
3197  ((Eckert4*)(target->coordinateSystem))->convertFromGeodetic(
3198  _shiftedGeodetic );
3199 
3200  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3201  coordinates->easting(), coordinates->northing() );
3202 
3203  delete coordinates;
3204 
3205  break;
3206  }
3208  {
3209  MapProjectionCoordinates* coordinates =
3210  ((Eckert6*)(target->coordinateSystem))->convertFromGeodetic(
3211  _shiftedGeodetic );
3212 
3213  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3214  coordinates->easting(), coordinates->northing() );
3215 
3216  delete coordinates;
3217 
3218  break;
3219  }
3221  {
3222  MapProjectionCoordinates* coordinates =
3224  target->coordinateSystem))->convertFromGeodetic(
3225  _shiftedGeodetic );
3226 
3227  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3228  coordinates->easting(), coordinates->northing() );
3229 
3230  delete coordinates;
3231 
3232  break;
3233  }
3235  {
3236  Precision::Enum temp_precision =
3237  (dynamic_cast< GARSCoordinates& >( targetCoordinates )).precision();
3238  if (temp_precision < 0)
3239  temp_precision = Precision::degree;
3240  if (temp_precision > 5)
3241  temp_precision = Precision::tenthOfSecond;
3242 
3243  GARSCoordinates* coordinates =
3244  ((GARS*)(target->coordinateSystem))->convertFromGeodetic(
3245  _shiftedGeodetic, temp_precision );
3246 
3247  ( dynamic_cast< GARSCoordinates& >( targetCoordinates ) ).set(
3248  coordinates->GARSString() );
3249 
3250  delete coordinates;
3251 
3252  break;
3253  }
3255  {
3256  MapProjectionCoordinates* coordinates =
3257  ((Gnomonic*)(target->coordinateSystem))->convertFromGeodetic(
3258  _shiftedGeodetic );
3259 
3260  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3261  coordinates->easting(), coordinates->northing() );
3262 
3263  delete coordinates;
3264 
3265  break;
3266  }
3268  {
3269  MapProjectionCoordinates* coordinates =
3271  target->coordinateSystem))->convertFromGeodetic(
3272  _shiftedGeodetic );
3273 
3274  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3275  coordinates->easting(), coordinates->northing() );
3276 
3277  delete coordinates;
3278 
3279  break;
3280  }
3282  {
3283  MapProjectionCoordinates* coordinates =
3285  target->coordinateSystem))->convertFromGeodetic(
3286  _shiftedGeodetic );
3287 
3288  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3289  coordinates->easting(), coordinates->northing() );
3290 
3291  delete coordinates;
3292 
3293  break;
3294  }
3296  {
3297  CartesianCoordinates* coordinates =
3298  ((LocalCartesian*)(target->coordinateSystem))->convertFromGeodetic(
3299  _shiftedGeodetic );
3300 
3301  ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set(
3302  coordinates->x(), coordinates->y(), coordinates->z() );
3303 
3304  delete coordinates;
3305 
3306  break;
3307  }
3309  {
3310  SphericalCoordinates* coordinates =
3311  ((LocalSpherical*)(target->coordinateSystem))->convertFromGeodetic(
3312  _shiftedGeodetic );
3313 
3314  ( dynamic_cast< SphericalCoordinates& >( targetCoordinates ) ).setLocalSphericalCoord(
3315  coordinates->azimuth(), coordinates->elevationAngle(), coordinates->range() );
3316 
3317  delete coordinates;
3318 
3319  break;
3320  }
3323  {
3324  MapProjectionCoordinates* coordinates =
3325  ((Mercator*)(target->coordinateSystem))->convertFromGeodetic(
3326  _shiftedGeodetic );
3327 
3328  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3329  coordinates->easting(), coordinates->northing() );
3330 
3331  delete coordinates;
3332 
3333  break;
3334  }
3336  {
3337  Precision::Enum temp_precision =
3338  ( dynamic_cast< MGRSorUSNGCoordinates& >(
3339  targetCoordinates ) ).precision();
3340 
3341  if (temp_precision < 0)
3342  temp_precision = Precision::degree;
3343  if (temp_precision > 5)
3344  temp_precision = Precision::tenthOfSecond;
3345  MGRSorUSNGCoordinates* coordinates =
3346  ((MGRS*)(target->coordinateSystem))->convertFromGeodetic(
3347  _shiftedGeodetic, temp_precision );
3348 
3349  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set(
3350  coordinates->MGRSString() );
3351 
3352  delete coordinates;
3353 
3354  break;
3355  }
3357  {
3358  MapProjectionCoordinates* coordinates =
3359  ((MillerCylindrical*)(
3360  target->coordinateSystem))->convertFromGeodetic(
3361  _shiftedGeodetic );
3362 
3363  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3364  coordinates->easting(), coordinates->northing() );
3365 
3366  delete coordinates;
3367 
3368  break;
3369  }
3371  {
3372  MapProjectionCoordinates* coordinates =
3373  ((Mollweide*)(target->coordinateSystem))->convertFromGeodetic(
3374  _shiftedGeodetic );
3375 
3376  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3377  coordinates->easting(), coordinates->northing() );
3378 
3379  delete coordinates;
3380 
3381  break;
3382  }
3383  case CoordinateType::neys:
3384  {
3385  MapProjectionCoordinates* coordinates =
3386  ((Neys*)(target->coordinateSystem))->convertFromGeodetic(
3387  _shiftedGeodetic );
3388 
3389  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3390  coordinates->easting(), coordinates->northing() );
3391 
3392  delete coordinates;
3393 
3394  break;
3395  }
3397  {
3398  MapProjectionCoordinates* coordinates =
3399  ((NZMG*)(target->coordinateSystem))->convertFromGeodetic(
3400  _shiftedGeodetic );
3401 
3402  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3403  coordinates->easting(), coordinates->northing() );
3404 
3405  delete coordinates;
3406 
3407  break;
3408  }
3410  {
3411  MapProjectionCoordinates* coordinates =
3412  ((ObliqueMercator*)(target->coordinateSystem))->convertFromGeodetic(
3413  _shiftedGeodetic );
3414 
3415  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3416  coordinates->easting(), coordinates->northing() );
3417 
3418  if( strlen( coordinates->warningMessage() ) > 0)
3419  {
3420  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3421  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3422  }
3423 
3424  delete coordinates;
3425 
3426  break;
3427  }
3429  {
3430  MapProjectionCoordinates* coordinates =
3431  ((Orthographic*)(target->coordinateSystem))->convertFromGeodetic(
3432  _shiftedGeodetic );
3433 
3434  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3435  coordinates->easting(), coordinates->northing() );
3436 
3437  delete coordinates;
3438 
3439  break;
3440  }
3443  {
3444  MapProjectionCoordinates* coordinates =
3445  ((PolarStereographic*)(
3446  target->coordinateSystem))->convertFromGeodetic(
3447  _shiftedGeodetic );
3448 
3449  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3450  coordinates->easting(), coordinates->northing() );
3451 
3452  delete coordinates;
3453 
3454  break;
3455  }
3457  {
3458  MapProjectionCoordinates* coordinates =
3459  ((Polyconic*)(target->coordinateSystem))->convertFromGeodetic(
3460  _shiftedGeodetic );
3461 
3462  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3463  coordinates->easting(), coordinates->northing() );
3464 
3465  if( strlen( coordinates->warningMessage() ) > 0)
3466  {
3467  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3468  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3469  }
3470 
3471  delete coordinates;
3472 
3473  break;
3474  }
3476  {
3477  MapProjectionCoordinates* coordinates =
3478  ((Sinusoidal*)(target->coordinateSystem))->convertFromGeodetic(
3479  _shiftedGeodetic );
3480 
3481  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3482  coordinates->easting(), coordinates->northing() );
3483 
3484  delete coordinates;
3485 
3486  break;
3487  }
3489  {
3490  MapProjectionCoordinates* coordinates =
3491  ((Stereographic*)(target->coordinateSystem))->convertFromGeodetic(
3492  _shiftedGeodetic );
3493 
3494  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3495  coordinates->easting(), coordinates->northing() );
3496 
3497  delete coordinates;
3498 
3499  break;
3500  }
3502  {
3503  MapProjectionCoordinates* coordinates =
3505  target->coordinateSystem))->convertFromGeodetic(
3506  _shiftedGeodetic );
3507 
3508  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3509  coordinates->easting(), coordinates->northing() );
3510 
3511  if( strlen( coordinates->warningMessage() ) > 0)
3512  {
3513  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3514  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3515  }
3516 
3517  delete coordinates;
3518 
3519  break;
3520  }
3522  {
3523  MapProjectionCoordinates* coordinates =
3524  ((TransverseMercator*)(
3525  target->coordinateSystem))->convertFromGeodetic(
3526  _shiftedGeodetic );
3527 
3528  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3529  coordinates->easting(), coordinates->northing() );
3530 
3531  if( strlen( coordinates->warningMessage() ) > 0)
3532  {
3533  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3534  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3535  }
3536 
3537  delete coordinates;
3538 
3539  break;
3540  }
3542  {
3543  UPSCoordinates* coordinates =
3544  ((UPS*)(target->coordinateSystem))->convertFromGeodetic(
3545  _shiftedGeodetic );
3546 
3547  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ).set(
3548  coordinates->hemisphere(),
3549  coordinates->easting(),
3550  coordinates->northing() );
3551 
3552  delete coordinates;
3553 
3554  break;
3555  }
3557  {
3558  Precision::Enum temp_precision =
3559  ( dynamic_cast< MGRSorUSNGCoordinates& >(
3560  targetCoordinates ) ).precision();
3561  if (temp_precision < 0)
3562  temp_precision = Precision::degree;
3563  if (temp_precision > 5)
3564  temp_precision = Precision::tenthOfSecond;
3565 
3566  MGRSorUSNGCoordinates* coordinates =
3567  ((USNG*)(target->coordinateSystem))->convertFromGeodetic(
3568  _shiftedGeodetic, temp_precision );
3569 
3570  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set(
3571  coordinates->MGRSString() );
3572 
3573  delete coordinates;
3574 
3575  break;
3576  }
3578  {
3579  UTMCoordinates* coordinates =
3580  ((UTM*)(target->coordinateSystem))->convertFromGeodetic(
3581  _shiftedGeodetic );
3582 
3583  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ).set(
3584  coordinates->zone(), coordinates->hemisphere(),
3585  coordinates->easting(), coordinates->northing() );
3586 
3587  delete coordinates;
3588 
3589  break;
3590  }
3592  {
3593  MapProjectionCoordinates* coordinates =
3594  ((VanDerGrinten*)(target->coordinateSystem))->convertFromGeodetic(
3595  _shiftedGeodetic );
3596 
3597  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3598  coordinates->easting(), coordinates->northing() );
3599 
3600  delete coordinates;
3601 
3602  break;
3603  }
3605  {
3606  MapProjectionCoordinates* coordinates =
3607  ((WebMercator*)(target->coordinateSystem))->convertFromGeodetic(
3608  _shiftedGeodetic );
3609 
3610  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3611  coordinates->easting(), coordinates->northing() );
3612 
3613  delete coordinates;
3614 
3615  break;
3616  }
3617  } /* switch (target->coordinateType) */
3618  }
3620  {
3622  "Output ", Coordinate_System_Table[target->coordinateType].Name,
3623  ": \n", e.getMessage() );
3624  }
3625 }
3626 
3627 
3628 void CoordinateConversionService::convertCollection(
3629  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinatesCollection,
3630  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection,
3631  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinatesCollection,
3632  std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection )
3633 {
3634 /*
3635  * The function convertCollection will convert a list of source coordinates
3636  * to a list of target coordinates in a single step.
3637  *
3638  * sourceCoordinatesCollection : Coordinates to be converted (input)
3639  * sourceAccuracyCollection : Source circular/linear/spherical errors (input)
3640  * targetCoordinatesCollection : Converted coordinates (output)
3641  * targetAccuracyCollection : Target circular/linear/spherical errors (output)
3642  */
3643 
3644  int num = sourceCoordinatesCollection.size();
3645  int numTargetCoordinates = targetCoordinatesCollection.size();
3646  int numTargetAccuracies = targetAccuracyCollection.size();
3647  CoordinateType::Enum targetCoordinateType =
3648  coordinateSystemState[SourceOrTarget::target].coordinateType;
3649 
3650  CoordinateTuple* _targetCoordinates = 0;
3651  Accuracy* _targetAccuracy;
3652 
3653  for( int i = 0; i < num; i++ )
3654  {
3655  CoordinateTuple* _sourceCoordinates = sourceCoordinatesCollection[i];
3656  Accuracy* _sourceAccuracy = sourceAccuracyCollection[i];
3657 
3658  bool targetCoordinateExists = true;
3659  bool targetAccuracyExists = true;
3660 
3661  if(i < numTargetAccuracies)
3662  _targetAccuracy = targetAccuracyCollection[i];
3663  else
3664  {
3665  _targetAccuracy = new Accuracy();
3666  targetAccuracyExists = false;
3667  }
3668 
3669  if( _sourceCoordinates && _sourceAccuracy )
3670  {
3671  switch(targetCoordinateType)
3672  {
3674  {
3675  if(i < numTargetCoordinates)
3676  _targetCoordinates = targetCoordinatesCollection[i];
3677  else
3678  {
3679  _targetCoordinates = new MapProjectionCoordinates(
3681  targetCoordinateExists = false;
3682  }
3683  try
3684  {
3685  convert(
3688  sourceCoordinatesCollection[i],
3689  sourceAccuracyCollection[i],
3690  *_targetCoordinates, *_targetAccuracy);
3691  }
3693  {
3694  _targetCoordinates->setErrorMessage(e.getMessage());
3695  }
3696 
3697  if(!targetCoordinateExists)
3698  targetCoordinatesCollection.push_back(_targetCoordinates);
3699  break;
3700  }
3702  {
3703  if(i < numTargetCoordinates)
3704  _targetCoordinates = targetCoordinatesCollection[i];
3705  else
3706  {
3707  _targetCoordinates = new MapProjectionCoordinates(
3709  targetCoordinateExists = false;
3710  }
3711  try
3712  {
3713  convert(
3716  sourceCoordinatesCollection[i],
3717  sourceAccuracyCollection[i],
3718  *_targetCoordinates, *_targetAccuracy);
3719  }
3721  {
3722  _targetCoordinates->setErrorMessage(e.getMessage());
3723  }
3724 
3725  if(!targetCoordinateExists)
3726  targetCoordinatesCollection.push_back(_targetCoordinates);
3727  break;
3728  }
3729  case CoordinateType::bonne:
3730  {
3731  if(i < numTargetCoordinates)
3732  _targetCoordinates = targetCoordinatesCollection[i];
3733  else
3734  {
3735  _targetCoordinates = new MapProjectionCoordinates(
3737  targetCoordinateExists = false;
3738  }
3739  try
3740  {
3741  convert(
3744  sourceCoordinatesCollection[i],
3745  sourceAccuracyCollection[i],
3746  *_targetCoordinates, *_targetAccuracy);
3747  }
3749  {
3750  _targetCoordinates->setErrorMessage(e.getMessage());
3751  }
3752 
3753  if(!targetCoordinateExists)
3754  targetCoordinatesCollection.push_back(_targetCoordinates);
3755  break;
3756  }
3758  {
3759  if(i < numTargetCoordinates)
3760  _targetCoordinates = targetCoordinatesCollection[i];
3761  else
3762  {
3763  _targetCoordinates = new BNGCoordinates(
3765  targetCoordinateExists = false;
3766  }
3767  try
3768  {
3769  convert(
3772  sourceCoordinatesCollection[i],
3773  sourceAccuracyCollection[i],
3774  *_targetCoordinates, *_targetAccuracy);
3775  }
3777  {
3778  _targetCoordinates->setErrorMessage(e.getMessage());
3779  }
3780 
3781  if(!targetCoordinateExists)
3782  targetCoordinatesCollection.push_back(_targetCoordinates);
3783  break;
3784  }
3786  {
3787  if(i < numTargetCoordinates)
3788  _targetCoordinates = targetCoordinatesCollection[i];
3789  else
3790  {
3791  _targetCoordinates = new MapProjectionCoordinates(
3793  targetCoordinateExists = false;
3794  }
3795  try
3796  {
3797  convert(
3800  sourceCoordinatesCollection[i],
3801  sourceAccuracyCollection[i],
3802  *_targetCoordinates, *_targetAccuracy);
3803  }
3805  {
3806  _targetCoordinates->setErrorMessage(e.getMessage());
3807  }
3808 
3809  if(!targetCoordinateExists)
3810  targetCoordinatesCollection.push_back(_targetCoordinates);
3811  break;
3812  }
3814  {
3815  if(i < numTargetCoordinates)
3816  _targetCoordinates = targetCoordinatesCollection[i];
3817  else
3818  {
3819  _targetCoordinates = new MapProjectionCoordinates(
3821  targetCoordinateExists = false;
3822  }
3823  try
3824  {
3825  convert(
3828  sourceCoordinatesCollection[i],
3829  sourceAccuracyCollection[i],
3830  *_targetCoordinates, *_targetAccuracy);
3831  }
3833  {
3834  _targetCoordinates->setErrorMessage(e.getMessage());
3835  }
3836 
3837  if(!targetCoordinateExists)
3838  targetCoordinatesCollection.push_back(_targetCoordinates);
3839  break;
3840  }
3842  {
3843  if(i < numTargetCoordinates)
3844  _targetCoordinates = targetCoordinatesCollection[i];
3845  else
3846  {
3847  _targetCoordinates = new MapProjectionCoordinates(
3849  targetCoordinateExists = false;
3850  }
3851  try
3852  {
3853  convert(
3856  sourceCoordinatesCollection[i],
3857  sourceAccuracyCollection[i],
3858  *_targetCoordinates, *_targetAccuracy);
3859  }
3861  {
3862  _targetCoordinates->setErrorMessage(e.getMessage());
3863  }
3864 
3865  if(!targetCoordinateExists)
3866  targetCoordinatesCollection.push_back(_targetCoordinates);
3867  break;
3868  }
3870  {
3871  if(i < numTargetCoordinates)
3872  _targetCoordinates = targetCoordinatesCollection[i];
3873  else
3874  {
3875  _targetCoordinates = new MapProjectionCoordinates(
3877  targetCoordinateExists = false;
3878  }
3879  try
3880  {
3881  convert(
3884  sourceCoordinatesCollection[i],
3885  sourceAccuracyCollection[i],
3886  *_targetCoordinates, *_targetAccuracy);
3887  }
3889  {
3890  _targetCoordinates->setErrorMessage(e.getMessage());
3891  }
3892 
3893  if(!targetCoordinateExists)
3894  targetCoordinatesCollection.push_back(_targetCoordinates);
3895  break;
3896  }
3898  {
3899  if(i < numTargetCoordinates)
3900  _targetCoordinates = targetCoordinatesCollection[i];
3901  else
3902  {
3903  _targetCoordinates = new MapProjectionCoordinates(
3905  targetCoordinateExists = false;
3906  }
3907  try
3908  {
3909  convert(
3912  sourceCoordinatesCollection[i],
3913  sourceAccuracyCollection[i],
3914  *_targetCoordinates, *_targetAccuracy);
3915  }
3917  {
3918  _targetCoordinates->setErrorMessage(e.getMessage());
3919  }
3920 
3921  if(!targetCoordinateExists)
3922  targetCoordinatesCollection.push_back(_targetCoordinates);
3923  break;
3924  }
3926  {
3927  if(i < numTargetCoordinates)
3928  _targetCoordinates = targetCoordinatesCollection[i];
3929  else
3930  {
3931  _targetCoordinates = new CartesianCoordinates(
3933  targetCoordinateExists = false;
3934  }
3935  try
3936  {
3937  convert(
3939  sourceCoordinatesCollection[i], sourceAccuracyCollection[i],
3940  *_targetCoordinates, *_targetAccuracy);
3941  }
3943  {
3944  _targetCoordinates->setErrorMessage(e.getMessage());
3945  }
3946 
3947  if(!targetCoordinateExists)
3948  targetCoordinatesCollection.push_back(_targetCoordinates);
3949  break;
3950  }
3952  {
3953  if(i < numTargetCoordinates)
3954  _targetCoordinates = targetCoordinatesCollection[i];
3955  else
3956  {
3957  _targetCoordinates = new SphericalCoordinates(
3959  targetCoordinateExists = false;
3960  }
3961  try
3962  {
3963  convert(
3965  sourceCoordinatesCollection[i], sourceAccuracyCollection[i],
3966  *_targetCoordinates, *_targetAccuracy);
3967  }
3969  {
3970  _targetCoordinates->setErrorMessage(e.getMessage());
3971  }
3972 
3973  if(!targetCoordinateExists)
3974  targetCoordinatesCollection.push_back(_targetCoordinates);
3975  break;
3976  }
3978  {
3979  if(i < numTargetCoordinates)
3980  _targetCoordinates = targetCoordinatesCollection[i];
3981  else
3982  {
3983  _targetCoordinates = new GeodeticCoordinates(
3985  targetCoordinateExists = false;
3986  }
3987  try
3988  {
3989  convert(
3991  sourceCoordinatesCollection[i], sourceAccuracyCollection[i],
3992  *_targetCoordinates, *_targetAccuracy);
3993  }
3995  {
3996  _targetCoordinates->setErrorMessage(e.getMessage());
3997  }
3998 
3999  if(!targetCoordinateExists)
4000  targetCoordinatesCollection.push_back(_targetCoordinates);
4001  break;
4002  }
4004  {
4005  if(i < numTargetCoordinates)
4006  _targetCoordinates = targetCoordinatesCollection[i];
4007  else
4008  {
4009  _targetCoordinates = new GEOREFCoordinates(CoordinateType::georef);
4010  targetCoordinateExists = false;
4011  }
4012  try
4013  {
4014  convert(
4017  sourceCoordinatesCollection[i],
4018  sourceAccuracyCollection[i],
4019  *_targetCoordinates, *_targetAccuracy);
4020  }
4022  {
4023  _targetCoordinates->setErrorMessage(e.getMessage());
4024  }
4025 
4026  if(!targetCoordinateExists)
4027  targetCoordinatesCollection.push_back(_targetCoordinates);
4028  break;
4029  }
4031  {
4032  if(i < numTargetCoordinates)
4033  _targetCoordinates = targetCoordinatesCollection[i];
4034  else
4035  {
4036  _targetCoordinates = new GARSCoordinates(
4038  targetCoordinateExists = false;
4039  }
4040  try
4041  {
4042  convert(
4045  sourceCoordinatesCollection[i],
4046  sourceAccuracyCollection[i],
4047  *_targetCoordinates, *_targetAccuracy);
4048  }
4050  {
4051  _targetCoordinates->setErrorMessage(e.getMessage());
4052  }
4053 
4054  if(!targetCoordinateExists)
4055  targetCoordinatesCollection.push_back(_targetCoordinates);
4056  break;
4057  }
4059  {
4060  if(i < numTargetCoordinates)
4061  _targetCoordinates = targetCoordinatesCollection[i];
4062  else
4063  {
4064  _targetCoordinates = new MapProjectionCoordinates(
4066  targetCoordinateExists = false;
4067  }
4068  try
4069  {
4070  convert(
4073  sourceCoordinatesCollection[i],
4074  sourceAccuracyCollection[i],
4075  *_targetCoordinates, *_targetAccuracy);
4076  }
4078  {
4079  _targetCoordinates->setErrorMessage(e.getMessage());
4080  }
4081 
4082  if(!targetCoordinateExists)
4083  targetCoordinatesCollection.push_back(_targetCoordinates);
4084  break;
4085  }
4087  {
4088  if(i < numTargetCoordinates)
4089  _targetCoordinates = targetCoordinatesCollection[i];
4090  else
4091  {
4092  _targetCoordinates = new MapProjectionCoordinates(
4094  targetCoordinateExists = false;
4095  }
4096  try
4097  {
4098  convert(
4101  sourceCoordinatesCollection[i],
4102  sourceAccuracyCollection[i],
4103  *_targetCoordinates,
4104  *_targetAccuracy);
4105  }
4107  {
4108  _targetCoordinates->setErrorMessage(e.getMessage());
4109  }
4110 
4111  if(!targetCoordinateExists)
4112  targetCoordinatesCollection.push_back(_targetCoordinates);
4113  break;
4114  }
4116  {
4117  if(i < numTargetCoordinates)
4118  _targetCoordinates = targetCoordinatesCollection[i];
4119  else
4120  {
4121  _targetCoordinates = new MapProjectionCoordinates(
4123  targetCoordinateExists = false;
4124  }
4125  try
4126  {
4127  convert(
4130  sourceCoordinatesCollection[i],
4131  sourceAccuracyCollection[i],
4132  *_targetCoordinates, *_targetAccuracy);
4133  }
4135  {
4136  _targetCoordinates->setErrorMessage(e.getMessage());
4137  }
4138 
4139  if(!targetCoordinateExists)
4140  targetCoordinatesCollection.push_back(_targetCoordinates);
4141  break;
4142  }
4144  {
4145  if(i < numTargetCoordinates)
4146  _targetCoordinates = targetCoordinatesCollection[i];
4147  else
4148  {
4149  _targetCoordinates = new CartesianCoordinates(
4151  targetCoordinateExists = false;
4152  }
4153  try
4154  {
4155  convert(
4158  sourceCoordinatesCollection[i],
4159  sourceAccuracyCollection[i],
4160  *_targetCoordinates, *_targetAccuracy);
4161  }
4163  {
4164  _targetCoordinates->setErrorMessage(e.getMessage());
4165  }
4166 
4167  if(!targetCoordinateExists)
4168  targetCoordinatesCollection.push_back(_targetCoordinates);
4169  break;
4170  }
4172  {
4173  if(i < numTargetCoordinates)
4174  _targetCoordinates = targetCoordinatesCollection[i];
4175  else
4176  {
4177  _targetCoordinates = new SphericalCoordinates(
4179  targetCoordinateExists = false;
4180  }
4181  try
4182  {
4183  convert(
4186  sourceCoordinatesCollection[i],
4187  sourceAccuracyCollection[i],
4188  *_targetCoordinates, *_targetAccuracy);
4189  }
4191  {
4192  _targetCoordinates->setErrorMessage(e.getMessage());
4193  }
4194 
4195  if(!targetCoordinateExists)
4196  targetCoordinatesCollection.push_back(_targetCoordinates);
4197  break;
4198  }
4200  {
4201  if(i < numTargetCoordinates)
4202  _targetCoordinates = targetCoordinatesCollection[i];
4203  else
4204  {
4205  _targetCoordinates = new MapProjectionCoordinates(
4207  targetCoordinateExists = false;
4208  }
4209  try
4210  {
4211  convert(
4214  sourceCoordinatesCollection[i],
4215  sourceAccuracyCollection[i],
4216  *_targetCoordinates, *_targetAccuracy);
4217  }
4219  {
4220  _targetCoordinates->setErrorMessage(e.getMessage());
4221  }
4222 
4223  if(!targetCoordinateExists)
4224  targetCoordinatesCollection.push_back(_targetCoordinates);
4225  break;
4226  }
4228  {
4229  if(i < numTargetCoordinates)
4230  _targetCoordinates = targetCoordinatesCollection[i];
4231  else
4232  {
4233  _targetCoordinates = new MapProjectionCoordinates(
4235  targetCoordinateExists = false;
4236  }
4237  try
4238  {
4239  convert(
4242  sourceCoordinatesCollection[i],
4243  sourceAccuracyCollection[i],
4244  *_targetCoordinates, *_targetAccuracy);
4245  }
4247  {
4248  _targetCoordinates->setErrorMessage(e.getMessage());
4249  }
4250 
4251  if(!targetCoordinateExists)
4252  targetCoordinatesCollection.push_back(_targetCoordinates);
4253  break;
4254  }
4256  {
4257  if(i < numTargetCoordinates)
4258  _targetCoordinates = targetCoordinatesCollection[i];
4259  else
4260  {
4261  _targetCoordinates = new MGRSorUSNGCoordinates(
4263  targetCoordinateExists = false;
4264  }
4265  try
4266  {
4267  convert(
4270  sourceCoordinatesCollection[i],
4271  sourceAccuracyCollection[i],
4272  *_targetCoordinates, *_targetAccuracy);
4273  }
4275  {
4276  _targetCoordinates->setErrorMessage(e.getMessage());
4277  }
4278 
4279  if(!targetCoordinateExists)
4280  targetCoordinatesCollection.push_back(_targetCoordinates);
4281  break;
4282  }
4284  {
4285  if(i < numTargetCoordinates)
4286  _targetCoordinates = targetCoordinatesCollection[i];
4287  else
4288  {
4289  _targetCoordinates = new MapProjectionCoordinates(
4291  targetCoordinateExists = false;
4292  }
4293  try
4294  {
4295  convert(
4298  sourceCoordinatesCollection[i],
4299  sourceAccuracyCollection[i],
4300  *_targetCoordinates, *_targetAccuracy);
4301  }
4303  {
4304  _targetCoordinates->setErrorMessage(e.getMessage());
4305  }
4306 
4307  if(!targetCoordinateExists)
4308  targetCoordinatesCollection.push_back(_targetCoordinates);
4309  break;
4310  }
4312  {
4313  if(i < numTargetCoordinates)
4314  _targetCoordinates = targetCoordinatesCollection[i];
4315  else
4316  {
4317  _targetCoordinates = new MapProjectionCoordinates(
4319  targetCoordinateExists = false;
4320  }
4321  try
4322  {
4323  convert(
4326  sourceCoordinatesCollection[i],
4327  sourceAccuracyCollection[i],
4328  *_targetCoordinates, *_targetAccuracy);
4329  }
4331  {
4332  _targetCoordinates->setErrorMessage(e.getMessage());
4333  }
4334 
4335  if(!targetCoordinateExists)
4336  targetCoordinatesCollection.push_back(_targetCoordinates);
4337  break;
4338  }
4340  {
4341  if(i < numTargetCoordinates)
4342  _targetCoordinates = targetCoordinatesCollection[i];
4343  else
4344  {
4345  _targetCoordinates = new MapProjectionCoordinates(
4347  targetCoordinateExists = false;
4348  }
4349  try
4350  {
4351  convert(
4354  sourceCoordinatesCollection[i],
4355  sourceAccuracyCollection[i],
4356  *_targetCoordinates, *_targetAccuracy);
4357  }
4359  {
4360  _targetCoordinates->setErrorMessage(e.getMessage());
4361  }
4362 
4363  if(!targetCoordinateExists)
4364  targetCoordinatesCollection.push_back(_targetCoordinates);
4365  break;
4366  }
4367  case CoordinateType::neys:
4368  {
4369  if(i < numTargetCoordinates)
4370  _targetCoordinates = targetCoordinatesCollection[i];
4371  else
4372  {
4373  _targetCoordinates = new MapProjectionCoordinates(
4375  targetCoordinateExists = false;
4376  }
4377  try
4378  {
4379  convert(
4382  sourceCoordinatesCollection[i],
4383  sourceAccuracyCollection[i],
4384  *_targetCoordinates, *_targetAccuracy);
4385  }
4387  {
4388  _targetCoordinates->setErrorMessage(e.getMessage());
4389  }
4390 
4391  if(!targetCoordinateExists)
4392  targetCoordinatesCollection.push_back(_targetCoordinates);
4393  break;
4394  }
4396  {
4397  if(i < numTargetCoordinates)
4398  _targetCoordinates = targetCoordinatesCollection[i];
4399  else
4400  {
4401  _targetCoordinates = new MapProjectionCoordinates(
4403  targetCoordinateExists = false;
4404  }
4405  try
4406  {
4407  convert(
4410  sourceCoordinatesCollection[i],
4411  sourceAccuracyCollection[i],
4412  *_targetCoordinates, *_targetAccuracy);
4413  }
4415  {
4416  _targetCoordinates->setErrorMessage(e.getMessage());
4417  }
4418 
4419  if(!targetCoordinateExists)
4420  targetCoordinatesCollection.push_back(_targetCoordinates);
4421  break;
4422  }
4424  {
4425  if(i < numTargetCoordinates)
4426  _targetCoordinates = targetCoordinatesCollection[i];
4427  else
4428  {
4429  _targetCoordinates = new MapProjectionCoordinates(
4431  targetCoordinateExists = false;
4432  }
4433  try
4434  {
4435  convert(
4438  sourceCoordinatesCollection[i],
4439  sourceAccuracyCollection[i],
4440  *_targetCoordinates, *_targetAccuracy);
4441  }
4443  {
4444  _targetCoordinates->setErrorMessage(e.getMessage());
4445  }
4446 
4447  if(!targetCoordinateExists)
4448  targetCoordinatesCollection.push_back(_targetCoordinates);
4449  break;
4450  }
4452  {
4453  if(i < numTargetCoordinates)
4454  _targetCoordinates = targetCoordinatesCollection[i];
4455  else
4456  {
4457  _targetCoordinates = new MapProjectionCoordinates(
4459  targetCoordinateExists = false;
4460  }
4461  try
4462  {
4463  convert(
4466  sourceCoordinatesCollection[i],
4467  sourceAccuracyCollection[i],
4468  *_targetCoordinates, *_targetAccuracy);
4469  }
4471  {
4472  _targetCoordinates->setErrorMessage(e.getMessage());
4473  }
4474 
4475  if(!targetCoordinateExists)
4476  targetCoordinatesCollection.push_back(_targetCoordinates);
4477  break;
4478  }
4480  {
4481  if(i < numTargetCoordinates)
4482  _targetCoordinates = targetCoordinatesCollection[i];
4483  else
4484  {
4485  _targetCoordinates = new MapProjectionCoordinates(
4487  targetCoordinateExists = false;
4488  }
4489  try
4490  {
4491  convert(
4494  sourceCoordinatesCollection[i],
4495  sourceAccuracyCollection[i],
4496  *_targetCoordinates, *_targetAccuracy);
4497  }
4499  {
4500  _targetCoordinates->setErrorMessage(e.getMessage());
4501  }
4502 
4503  if(!targetCoordinateExists)
4504  targetCoordinatesCollection.push_back(_targetCoordinates);
4505  break;
4506  }
4508  {
4509  if(i < numTargetCoordinates)
4510  _targetCoordinates = targetCoordinatesCollection[i];
4511  else
4512  {
4513  _targetCoordinates = new MapProjectionCoordinates(
4515  targetCoordinateExists = false;
4516  }
4517  try
4518  {
4519  convert(
4522  sourceCoordinatesCollection[i],
4523  sourceAccuracyCollection[i],
4524  *_targetCoordinates, *_targetAccuracy);
4525  }
4527  {
4528  _targetCoordinates->setErrorMessage(e.getMessage());
4529  }
4530 
4531  if(!targetCoordinateExists)
4532  targetCoordinatesCollection.push_back(_targetCoordinates);
4533  break;
4534  }
4536  {
4537  if(i < numTargetCoordinates)
4538  _targetCoordinates = targetCoordinatesCollection[i];
4539  else
4540  {
4541  _targetCoordinates = new MapProjectionCoordinates(
4543  targetCoordinateExists = false;
4544  }
4545  try
4546  {
4547  convert(
4550  sourceCoordinatesCollection[i],
4551  sourceAccuracyCollection[i],
4552  *_targetCoordinates, *_targetAccuracy);
4553  }
4555  {
4556  _targetCoordinates->setErrorMessage(e.getMessage());
4557  }
4558 
4559  if(!targetCoordinateExists)
4560  targetCoordinatesCollection.push_back(_targetCoordinates);
4561  break;
4562  }
4564  {
4565  if(i < numTargetCoordinates)
4566  _targetCoordinates = targetCoordinatesCollection[i];
4567  else
4568  {
4569  _targetCoordinates = new MapProjectionCoordinates(
4571  targetCoordinateExists = false;
4572  }
4573  try
4574  {
4575  convert(
4578  sourceCoordinatesCollection[i],
4579  sourceAccuracyCollection[i],
4580  *_targetCoordinates, *_targetAccuracy);
4581  }
4583  {
4584  _targetCoordinates->setErrorMessage(e.getMessage());
4585  }
4586 
4587  if(!targetCoordinateExists)
4588  targetCoordinatesCollection.push_back(_targetCoordinates);
4589  break;
4590  }
4592  {
4593  if(i < numTargetCoordinates)
4594  _targetCoordinates = targetCoordinatesCollection[i];
4595  else
4596  {
4597  _targetCoordinates = new MapProjectionCoordinates(
4599  targetCoordinateExists = false;
4600  }
4601  try
4602  {
4603  convert(
4606  sourceCoordinatesCollection[i],
4607  sourceAccuracyCollection[i],
4608  *_targetCoordinates, *_targetAccuracy);
4609  }
4611  {
4612  _targetCoordinates->setErrorMessage(e.getMessage());
4613  }
4614 
4615  if(!targetCoordinateExists)
4616  targetCoordinatesCollection.push_back(_targetCoordinates);
4617  break;
4618  }
4620  {
4621  if(i < numTargetCoordinates)
4622  _targetCoordinates = targetCoordinatesCollection[i];
4623  else
4624  {
4625  _targetCoordinates = new MapProjectionCoordinates(
4627  targetCoordinateExists = false;
4628  }
4629  try
4630  {
4631  convert(
4634  sourceCoordinatesCollection[i],
4635  sourceAccuracyCollection[i],
4636  *_targetCoordinates, *_targetAccuracy);
4637  }
4639  {
4640  _targetCoordinates->setErrorMessage(e.getMessage());
4641  }
4642 
4643  if(!targetCoordinateExists)
4644  targetCoordinatesCollection.push_back(_targetCoordinates);
4645  break;
4646  }
4648  {
4649  if(i < numTargetCoordinates)
4650  _targetCoordinates = targetCoordinatesCollection[i];
4651  else
4652  {
4653  _targetCoordinates = new UPSCoordinates(
4655  targetCoordinateExists = false;
4656  }
4657  try
4658  {
4659  convert(
4662  _sourceCoordinates,
4663  _sourceAccuracy,
4664  *_targetCoordinates, *_targetAccuracy);
4665  }
4667  {
4668  _targetCoordinates->setErrorMessage(e.getMessage());
4669  }
4670 
4671  if(!targetCoordinateExists)
4672  targetCoordinatesCollection.push_back(_targetCoordinates);
4673  break;
4674  }
4676  {
4677  if(i < numTargetCoordinates)
4678  _targetCoordinates = targetCoordinatesCollection[i];
4679  else
4680  {
4681  _targetCoordinates = new UTMCoordinates(
4683  targetCoordinateExists = false;
4684  }
4685  try
4686  {
4687  convert(
4690  sourceCoordinatesCollection[i],
4691  sourceAccuracyCollection[i],
4692  *_targetCoordinates, *_targetAccuracy);
4693  }
4695  {
4696  _targetCoordinates->setErrorMessage(e.getMessage());
4697  }
4698 
4699  if(!targetCoordinateExists)
4700  targetCoordinatesCollection.push_back(_targetCoordinates);
4701  break;
4702  }
4704  {
4705  if(i < numTargetCoordinates)
4706  _targetCoordinates = targetCoordinatesCollection[i];
4707  else
4708  {
4709  _targetCoordinates = new MGRSorUSNGCoordinates(
4711  targetCoordinateExists = false;
4712  }
4713  try
4714  {
4715  convert(
4718  sourceCoordinatesCollection[i],
4719  sourceAccuracyCollection[i],
4720  *_targetCoordinates, *_targetAccuracy);
4721  }
4723  {
4724  _targetCoordinates->setErrorMessage(e.getMessage());
4725  }
4726 
4727  if(!targetCoordinateExists)
4728  targetCoordinatesCollection.push_back(_targetCoordinates);
4729  break;
4730  }
4732  {
4733  if(i < numTargetCoordinates)
4734  _targetCoordinates = targetCoordinatesCollection[i];
4735  else
4736  {
4737  _targetCoordinates = new MapProjectionCoordinates(
4739  targetCoordinateExists = false;
4740  }
4741  try
4742  {
4743  convert(
4746  sourceCoordinatesCollection[i],
4747  sourceAccuracyCollection[i],
4748  *_targetCoordinates, *_targetAccuracy);
4749  }
4751  {
4752  _targetCoordinates->setErrorMessage(e.getMessage());
4753  }
4754 
4755  if(!targetCoordinateExists)
4756  targetCoordinatesCollection.push_back(_targetCoordinates);
4757  break;
4758  }
4760  {
4761  if(i < numTargetCoordinates)
4762  _targetCoordinates = targetCoordinatesCollection[i];
4763  else
4764  {
4765  _targetCoordinates =
4767  targetCoordinateExists = false;
4768  }
4769  try
4770  {
4771  convert(
4774  sourceCoordinatesCollection[i],
4775  sourceAccuracyCollection[i],
4776  *_targetCoordinates, *_targetAccuracy);
4777  }
4779  {
4780  _targetCoordinates->setErrorMessage(e.getMessage());
4781  }
4782 
4783  if(!targetCoordinateExists)
4784  targetCoordinatesCollection.push_back(_targetCoordinates);
4785  break;
4786  }
4787  default:
4789  }
4790 
4791  if(!targetAccuracyExists)
4792  targetAccuracyCollection.push_back( _targetAccuracy );
4793  }
4794  else
4795  {
4796  if(i >= numTargetCoordinates)
4797  targetCoordinateExists = false;
4798 
4799  if( _sourceCoordinates )
4800  {
4801  if(!targetCoordinateExists)
4802  targetCoordinatesCollection.push_back(
4803  new CoordinateTuple( *_sourceCoordinates ) );
4804  else
4805  {
4806  _targetCoordinates = targetCoordinatesCollection[i];
4807  _targetCoordinates->set(
4808  _sourceCoordinates->coordinateType(),
4809  _sourceCoordinates->warningMessage(),
4810  _sourceCoordinates->errorMessage());
4811  }
4812  }
4813  else
4814  {
4815  if(!targetCoordinateExists)
4816  targetCoordinatesCollection.push_back( new CoordinateTuple() );
4817  }
4818 
4819  if(!targetAccuracyExists)
4820  {
4821  if( _sourceAccuracy )
4822  targetAccuracyCollection.push_back( _sourceAccuracy );
4823  else
4824  {
4825  Accuracy* __sourceAccuracy = new Accuracy();
4826  targetAccuracyCollection.push_back( __sourceAccuracy );
4827  }
4828  }
4829  }
4830  }
4831 
4832  if(numTargetCoordinates > num)
4833  {
4834  for(int i = num; i < numTargetCoordinates; i++)
4835  {
4836  delete targetCoordinatesCollection[i];
4837  targetCoordinatesCollection.pop_back();
4838  }
4839  }
4840  if(numTargetAccuracies > num)
4841  {
4842  for(int i = num; i < numTargetAccuracies; i++)
4843  {
4844  targetAccuracyCollection.pop_back();
4845  }
4846  }
4847 }
4848 
4849 // CLASSIFICATION: UNCLASSIFIED
void convertEllipsoidHeightToEGM2008GeoidHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
double linearError90()
Definition: Accuracy.cpp:86
CoordinateConversionService(const char *sourceDatumCode, MSP::CCS::CoordinateSystemParameters *sourceParameters, const char *targetDatumCode, MSP::CCS::CoordinateSystemParameters *targetParameters)
static GeoidLibrary * getInstance()
void set(char __GARSString[8])
GeodeticCoordinates * geodeticShiftToWGS84(const long sourceIndex, const GeodeticCoordinates *sourceCoordinates)
void convertEllipsoidToEGM84ThirtyMinBiLinearHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
double originLatitude() const
void set(double __circularError90, double __linearError90, double __sphericalError90)
Definition: Accuracy.cpp:54
void datumIndex(const char *code, long *index)
void convertEllipsoidToEGM84TenDegNaturalSplineHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
void convertEGM96FifteenMinBilinearGeoidToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
void set(char __MGRSString[21])
double falseNorthing() const
static const char * webmInvalidTargetCS
Definition: ErrorMessages.h:64
void set(char __hemisphere, double __easting, double __northing)
static const char * invalidType
static EllipsoidLibraryImplementation * getInstance()
double circularError90()
Definition: Accuracy.cpp:80
GeodeticCoordinates * geodeticShiftFromWGS84(const GeodeticCoordinates *sourceCoordinates, const long targetIndex)
void datumEllipsoidCode(const long index, char *code)
void convertEGM84ThirtyMinBiLinearToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
void convertEGM2008GeoidHeightToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
static const char * datum
void set(char __BNGString[21])
static const char * zone
Definition: ErrorMessages.h:53
void convertEllipsoidToEGM84TenDegBilinearHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
void setZone(long __zone)
void convertEGM84TenDegBilinearToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
void convertEllipsoidToEGM96VariableNaturalSplineHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
void setErrorMessage(const char *__errorMessage)
void 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)
const char * getDatum(const SourceOrTarget::Enum direction) const
void ellipsoidParameters(const long index, double *a, double *f)
static DatumLibraryImplementation * getInstance()
double centralMeridian() const
double falseEasting() const
void convertEllipsoidToEGM96FifteenMinBilinearGeoidHeight(double longitude, double latitude, double ellipsoidHeight, double *geoidHeight)
#define PI
Definition: MGRS.cpp:164
CoordinateConversionService & operator=(const CoordinateConversionService &ccs)
Accuracy * datumShiftError(const long sourceIndex, const long targetIndex, double longitude, double latitude, Accuracy *sourceAccuracy, Precision::Enum precision)
void set(double __easting, double __northing)
void convertTargetToSource(CoordinateTuple *targetCoordinates, Accuracy *targetAccuracy, CoordinateTuple &sourceCoordinates, Accuracy &sourceAccurac)
void set(MSP::CCS::CoordinateType::Enum __coordinateType, const char *__warningMessage, const char *__errorMessage)
virtual Precision::Enum precision() const
void validDatum(const long index, double longitude, double latitude, long *result)
double standardParallel1() const
void set(long __zone, char __hemisphere, double __easting, double __northing)
static void removeInstance()
static const char * invalidDatumCode
Definition: ErrorMessages.h:40
void setDatumLibraryImplementation(DatumLibraryImplementation *__datumLibraryImplementation)
void convertEGM84TenDegNaturalSplineToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
void setWarningMessage(const char *__warningMessage)
double sphericalError90()
Definition: Accuracy.cpp:92
CoordinateType::Enum coordinateType() const
const char * errorMessage() const
void set(char __GEOREFString[21])
void setEllipsoidLibraryImplementation(EllipsoidLibraryImplementation *__ellipsoidLibraryImplementation)
MSP::CCS::CoordinateSystemParameters * getCoordinateSystem(const SourceOrTarget::Enum direction) const
void convertEGM96VariableNaturalSplineToEllipsoidHeight(double longitude, double latitude, double geoidHeight, double *ellipsoidHeight)
void convertSourceToTarget(CoordinateTuple *sourceCoordinates, Accuracy *sourceAccuracy, CoordinateTuple &targetCoordinates, Accuracy &targetAccuracy)
void 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)
const char * warningMessage() const