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,
17  * MILLER, MOLLWEIDE, NEYS, NEW ZEALAND MAP GRID, OBLIQUE MERCATOR,
18  * ORTHOGRAPHIC, POLYCONIC, SINUSOIDAL, 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  */
90 
91 #include <stdio.h>
94 #include "CoordinateTuple.h"
95 #include "CoordinateType.h"
96 #include "EllipsoidLibrary.h"
98 #include "DatumLibrary.h"
100 #include "GeoidLibrary.h"
101 #include "Accuracy.h"
103 #include "GeodeticParameters.h"
111 #include "NeysParameters.h"
115 #include "UTMParameters.h"
116 #include "BNGCoordinates.h"
117 #include "CartesianCoordinates.h"
118 #include "GARSCoordinates.h"
119 #include "GeodeticCoordinates.h"
120 #include "GEOREFCoordinates.h"
122 #include "MGRSorUSNGCoordinates.h"
123 #include "UPSCoordinates.h"
124 #include "UTMCoordinates.h"
125 #include "AlbersEqualAreaConic.h"
126 #include "AzimuthalEquidistant.h"
127 #include "Bonne.h"
128 #include "BritishNationalGrid.h"
129 #include "Cassini.h"
130 #include "CylindricalEqualArea.h"
131 #include "Eckert4.h"
132 #include "Eckert6.h"
133 #include "EquidistantCylindrical.h"
134 #include "GARS.h"
135 #include "Geocentric.h"
136 #include "GEOREF.h"
137 #include "Gnomonic.h"
138 #include "LambertConformalConic.h"
139 #include "LocalCartesian.h"
140 #include "Mercator.h"
141 #include "MGRS.h"
142 #include "MillerCylindrical.h"
143 #include "Mollweide.h"
144 #include "Neys.h"
145 #include "NZMG.h"
146 #include "ObliqueMercator.h"
147 #include "Orthographic.h"
148 #include "PolarStereographic.h"
149 #include "Polyconic.h"
150 #include "Sinusoidal.h"
151 #include "Stereographic.h"
153 #include "TransverseMercator.h"
154 #include "UPS.h"
155 #include "USNG.h"
156 #include "UTM.h"
157 #include "VanDerGrinten.h"
158 #include "WebMercator.h"
160 #include "ErrorMessages.h"
161 #include "WarningMessages.h"
162 #include "CCSThreadMutex.h"
163 #include "CCSThreadLock.h"
164 
165 using namespace MSP::CCS;
166 using MSP::CCSThreadMutex;
167 using MSP::CCSThreadLock;
168 
169 // DEFINES
170 const double PI = 3.14159265358979323e0;
171 CCSThreadMutex CoordinateConversionService::mutex;
172 
173 
174 
175 CoordinateConversionService::CCSData::CCSData() :
176  refCount( 1 )
177 {
178  ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
179  ellipsoidLibrary = new EllipsoidLibrary( ellipsoidLibraryImplementation );
180  datumLibraryImplementation = DatumLibraryImplementation::getInstance();
181  datumLibrary = new DatumLibrary( datumLibraryImplementation );
182  geoidLibrary = GeoidLibrary::getInstance();
183 }
184 
185 
186 CoordinateConversionService::CCSData::~CCSData()
187 {
188  delete ellipsoidLibrary;
189  ellipsoidLibrary = 0;
190 
191  EllipsoidLibraryImplementation::removeInstance();
192  ellipsoidLibraryImplementation = 0;
193 
194  delete datumLibrary;
195  datumLibrary = 0;
196 
197  DatumLibraryImplementation::removeInstance();
198  datumLibraryImplementation = 0;
199 
200  GeoidLibrary::removeInstance();
201  geoidLibrary = 0;
202 
203  refCount = 0;
204 }
205 
206 
207 /************************************************************************/
208 /* FUNCTIONS
209  *
210  */
211 
212 CoordinateConversionService::CoordinateConversionService(
213  const char* sourceDatumCode,
214  MSP::CCS::CoordinateSystemParameters* sourceParameters,
215  const char* targetDatumCode,
216  MSP::CCS::CoordinateSystemParameters* targetParameters ) :
217  WGS84_datum_index( 0 )
218 {
219  //Instantiate the variables here so exceptions can be caught
220  try
221  {
222  ellipsoidLibraryImplementation = EllipsoidLibraryImplementation::getInstance();
223  datumLibraryImplementation = DatumLibraryImplementation::getInstance();
224  geoidLibrary = GeoidLibrary::getInstance();
225  ccsData = new CCSData();
226  }
228  {
229  //Manage the memory since there could be an instance
231  ellipsoidLibraryImplementation = 0;
232 
234  datumLibraryImplementation = 0;
235 
237  geoidLibrary = 0;
238 
239  throw e;
240  }
241 
242  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
243  datumLibraryImplementation = ccsData->datumLibraryImplementation;
244  geoidLibrary = ccsData->geoidLibrary;
245 
246  initCoordinateSystemState( SourceOrTarget::source );
247  initCoordinateSystemState( SourceOrTarget::target );
248 
249  /* Initialize Coordinate System Table */
250  strcpy(Coordinate_System_Table[0].Name, "Albers Equal Area Conic");
251  strcpy(Coordinate_System_Table[0].Code, "AC");
252  Coordinate_System_Table[0].coordinateSystem =
254 
255  strcpy(Coordinate_System_Table[1].Name, "Azimuthal Equidistant (S)");
256  strcpy(Coordinate_System_Table[1].Code, "AL");
257  Coordinate_System_Table[1].coordinateSystem =
259 
260  strcpy(Coordinate_System_Table[2].Name, "Bonne");
261  strcpy(Coordinate_System_Table[2].Code, "BF");
262  Coordinate_System_Table[2].coordinateSystem = CoordinateType::bonne;
263 
264  strcpy(Coordinate_System_Table[3].Name, "British National Grid (BNG)");
265  strcpy(Coordinate_System_Table[3].Code, "BN");
266  Coordinate_System_Table[3].coordinateSystem =
268 
269  strcpy(Coordinate_System_Table[4].Name, "Cassini");
270  strcpy(Coordinate_System_Table[4].Code, "CS");
271  Coordinate_System_Table[4].coordinateSystem =
273 
274  strcpy(Coordinate_System_Table[5].Name, "Cylindrical Equal Area");
275  strcpy(Coordinate_System_Table[5].Code, "LI");
276  Coordinate_System_Table[5].coordinateSystem =
278 
279  strcpy(Coordinate_System_Table[6].Name, "Eckert IV (S)");
280  strcpy(Coordinate_System_Table[6].Code, "EF");
281  Coordinate_System_Table[6].coordinateSystem =
283 
284  strcpy(Coordinate_System_Table[7].Name, "Eckert VI (S)");
285  strcpy(Coordinate_System_Table[7].Code, "ED");
286  Coordinate_System_Table[7].coordinateSystem =
288 
289  strcpy(Coordinate_System_Table[8].Name, "Equidistant Cylindrical (S)");
290  strcpy(Coordinate_System_Table[8].Code, "CP");
291  Coordinate_System_Table[8].coordinateSystem =
293 
294  strcpy(Coordinate_System_Table[9].Name, "Geocentric");
295  strcpy(Coordinate_System_Table[9].Code, "GC");
296  Coordinate_System_Table[9].coordinateSystem =
298 
299  strcpy(Coordinate_System_Table[10].Name, "Geodetic");
300  strcpy(Coordinate_System_Table[10].Code, "GD");
301  Coordinate_System_Table[10].coordinateSystem = CoordinateType::geodetic;
302 
303  strcpy(Coordinate_System_Table[11].Name, "GEOREF");
304  strcpy(Coordinate_System_Table[11].Code, "GE");
305  Coordinate_System_Table[11].coordinateSystem = CoordinateType::georef;
306 
307  strcpy(Coordinate_System_Table[12].Name,
308  "Global Area Reference System (GARS)");
309  strcpy(Coordinate_System_Table[12].Code, "GA");
310  Coordinate_System_Table[12].coordinateSystem =
312 
313  strcpy(Coordinate_System_Table[13].Name, "Gnomonic (S)");
314  strcpy(Coordinate_System_Table[13].Code, "GN");
315  Coordinate_System_Table[13].coordinateSystem = CoordinateType::gnomonic;
316 
317  strcpy(Coordinate_System_Table[14].Name,
318  "Lambert Conformal Conic (1 Standard Parallel)");
319  strcpy(Coordinate_System_Table[14].Code, "L1");
320  Coordinate_System_Table[14].coordinateSystem =
322 
323  strcpy(Coordinate_System_Table[15].Name,
324  "Lambert Conformal Conic (2 Standard Parallel)");
325  strcpy(Coordinate_System_Table[15].Code, "L2");
326  Coordinate_System_Table[15].coordinateSystem =
328 
329  strcpy(Coordinate_System_Table[16].Name, "Local Cartesian");
330  strcpy(Coordinate_System_Table[16].Code, "LC");
331  Coordinate_System_Table[16].coordinateSystem = CoordinateType::localCartesian;
332 
333  strcpy(Coordinate_System_Table[17].Name, "Mercator (Standard Parallel)");
334  strcpy(Coordinate_System_Table[17].Code, "MC");
335  Coordinate_System_Table[17].coordinateSystem =
337 
338  strcpy(Coordinate_System_Table[18].Name, "Mercator (Scale Factor)");
339  strcpy(Coordinate_System_Table[18].Code, "MF");
340  Coordinate_System_Table[18].coordinateSystem =
342 
343  strcpy(Coordinate_System_Table[19].Name, "Military Grid Reference System (MGRS)");
344  strcpy(Coordinate_System_Table[19].Code, "MG");
345  Coordinate_System_Table[19].coordinateSystem =
347 
348  strcpy(Coordinate_System_Table[20].Name, "Miller Cylindrical (S)");
349  strcpy(Coordinate_System_Table[20].Code, "MH");
350  Coordinate_System_Table[20].coordinateSystem =
352 
353  strcpy(Coordinate_System_Table[21].Name, "Mollweide (S)");
354  strcpy(Coordinate_System_Table[21].Code, "MP");
355  Coordinate_System_Table[21].coordinateSystem = CoordinateType::mollweide;
356 
357  strcpy(Coordinate_System_Table[22].Name, "New Zealand Map Grid (NZMG)");
358  strcpy(Coordinate_System_Table[22].Code, "NT");
359  Coordinate_System_Table[22].coordinateSystem =
361 
362  strcpy(Coordinate_System_Table[23].Name,
363  "Ney's (Modified Lambert Conformal Conic)");
364  strcpy(Coordinate_System_Table[23].Code, "NY");
365  Coordinate_System_Table[23].coordinateSystem = CoordinateType::neys;
366 
367  strcpy(Coordinate_System_Table[24].Name, "Oblique Mercator");
368  strcpy(Coordinate_System_Table[24].Code, "OC");
369  Coordinate_System_Table[24].coordinateSystem =
371 
372  strcpy(Coordinate_System_Table[25].Name, "Orthographic (S)");
373  strcpy(Coordinate_System_Table[25].Code, "OD");
374  Coordinate_System_Table[25].coordinateSystem = CoordinateType::orthographic;
375 
376  strcpy(Coordinate_System_Table[26].Name,
377  "Polar Stereographic (Standard Parallel)");
378  strcpy(Coordinate_System_Table[26].Code, "PG");
379  Coordinate_System_Table[26].coordinateSystem =
381 
382  strcpy(Coordinate_System_Table[27].Name, "Polar Stereographic (Scale Factor)");
383  strcpy(Coordinate_System_Table[27].Code, "PF");
384  Coordinate_System_Table[27].coordinateSystem =
386 
387  strcpy(Coordinate_System_Table[28].Name, "Polyconic");
388  strcpy(Coordinate_System_Table[28].Code, "PH");
389  Coordinate_System_Table[28].coordinateSystem = CoordinateType::polyconic;
390 
391  strcpy(Coordinate_System_Table[29].Name, "Sinusoidal");
392  strcpy(Coordinate_System_Table[29].Code, "SA");
393  Coordinate_System_Table[20].coordinateSystem = CoordinateType::sinusoidal;
394 
395  strcpy(Coordinate_System_Table[30].Name, "Stereographic (S)");
396  strcpy(Coordinate_System_Table[30].Code, "SD");
397  Coordinate_System_Table[30].coordinateSystem = CoordinateType::stereographic;
398 
399  strcpy(Coordinate_System_Table[31].Name, "Transverse Cylindrical Equal Area");
400  strcpy(Coordinate_System_Table[31].Code, "TX");
401  Coordinate_System_Table[31].coordinateSystem =
403 
404  strcpy(Coordinate_System_Table[32].Name, "Transverse Mercator");
405  strcpy(Coordinate_System_Table[32].Code, "TC");
406  Coordinate_System_Table[32].coordinateSystem =
408 
409  strcpy(Coordinate_System_Table[33].Name,
410  "Universal Polar Stereographic (UPS)");
411  strcpy(Coordinate_System_Table[33].Code, "UP");
412  Coordinate_System_Table[33].coordinateSystem =
414 
415  strcpy(Coordinate_System_Table[34].Name,
416  "Universal Transverse Mercator (UTM)");
417  strcpy(Coordinate_System_Table[34].Code, "UT");
418  Coordinate_System_Table[34].coordinateSystem =
420 
421  strcpy(Coordinate_System_Table[35].Name,
422  "United States National Grid (USNG)");
423  strcpy(Coordinate_System_Table[35].Code, "US");
424  Coordinate_System_Table[35].coordinateSystem =
426 
427  strcpy(Coordinate_System_Table[36].Name, "Van der Grinten");
428  strcpy(Coordinate_System_Table[36].Code, "VA");
429  Coordinate_System_Table[36].coordinateSystem = CoordinateType::vanDerGrinten;
430 
431  strcpy(Coordinate_System_Table[37].Name, "Web Mercator");
432  strcpy(Coordinate_System_Table[37].Code, "WM");
433  Coordinate_System_Table[37].coordinateSystem = CoordinateType::webMercator;
434 
435  setDataLibraries();
436 
437  setDatum(SourceOrTarget::source, sourceDatumCode);
438  try
439  {
440  setCoordinateSystem(SourceOrTarget::source, sourceParameters);
441  }
443  {
445  "Input ",
446  Coordinate_System_Table[sourceParameters->coordinateType()].Name,
447  ": \n", e.getMessage() );
448  }
449 
450  setDatum(SourceOrTarget::target, targetDatumCode);
451 
452  try
453  {
454  setCoordinateSystem(SourceOrTarget::target, targetParameters);
455  }
457  {
459  "Output ",
460  Coordinate_System_Table[targetParameters->coordinateType()].Name,
461  ": \n", e.getMessage() );
462  }
463 
464  datumLibraryImplementation->datumIndex( "WGE", &WGS84_datum_index );
465 }
466 
467 
469  const CoordinateConversionService &ccs ) :
470  ccsData( ccs.ccsData )
471 {
472  CCSThreadLock lock(&mutex);
473 
474  ++ccsData->refCount;
475 
476  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
477  datumLibraryImplementation = ccsData->datumLibraryImplementation;
478  geoidLibrary = ccsData->geoidLibrary;
479 
480  coordinateSystemState[SourceOrTarget::source].coordinateType =
481  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
482  coordinateSystemState[SourceOrTarget::target].coordinateType =
483  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
484 
485  copyParameters( SourceOrTarget::source,
486  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType,
487  ccs.coordinateSystemState[SourceOrTarget::source].parameters );
488  copyParameters( SourceOrTarget::target,
489  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType,
490  ccs.coordinateSystemState[SourceOrTarget::target].parameters );
491 
492  coordinateSystemState[SourceOrTarget::source].datumIndex =
493  ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
494  coordinateSystemState[SourceOrTarget::target].datumIndex =
495  ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
496 
497  WGS84_datum_index = ccs.WGS84_datum_index;
498 }
499 
500 
502 {
503  CCSThreadLock lock(&mutex);
504 
505  if( --ccsData->refCount == 0 )
506  {
507  delete ccsData;
508  ccsData = 0;
509 
511  ellipsoidLibraryImplementation = 0;
512 
514  datumLibraryImplementation = 0;
515 
517  geoidLibrary = 0;
518  }
519 
520  deleteCoordinateSystem( SourceOrTarget::source );
521  deleteCoordinateSystem( SourceOrTarget::target );
522 }
523 
524 
526  const CoordinateConversionService &ccs )
527 {
528  CCSThreadLock lock(&mutex);
529 
530  if( ccsData == ccs.ccsData )
531  return *this;
532 
533  if( --ccsData->refCount == 0 )
534  delete ccsData;
535 
536  ccsData = ccs.ccsData;
537  ++ccsData->refCount;
538 
539  ellipsoidLibraryImplementation = ccsData->ellipsoidLibraryImplementation;
540  datumLibraryImplementation = ccsData->datumLibraryImplementation;
541  geoidLibrary = ccsData->geoidLibrary;
542 
543  coordinateSystemState[SourceOrTarget::source].coordinateType =
544  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType;
545  coordinateSystemState[SourceOrTarget::target].coordinateType =
546  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType;
547 
548  copyParameters( SourceOrTarget::source,
549  ccs.coordinateSystemState[SourceOrTarget::source].coordinateType,
550  ccs.coordinateSystemState[SourceOrTarget::source].parameters );
551  copyParameters( SourceOrTarget::target,
552  ccs.coordinateSystemState[SourceOrTarget::target].coordinateType,
553  ccs.coordinateSystemState[SourceOrTarget::target].parameters );
554 
555  coordinateSystemState[SourceOrTarget::source].datumIndex =
556  ccs.coordinateSystemState[SourceOrTarget::source].datumIndex;
557  coordinateSystemState[SourceOrTarget::target].datumIndex =
558  ccs.coordinateSystemState[SourceOrTarget::target].datumIndex;
559 
560  WGS84_datum_index = ccs.WGS84_datum_index;
561 
562  return *this;
563 }
564 
565 
567  CoordinateTuple* sourceCoordinates,
568  Accuracy* sourceAccuracy,
569  CoordinateTuple& targetCoordinates,
570  Accuracy& targetAccuracy )
571 {
572 /*
573  * The function convertSourceToTarget converts the current source coordinates
574  * in the coordinate system defined by the current source coordinate system
575  * parameters and source datum, into target coordinates in the coordinate
576  * system defined by the target coordinate system parameters and target datum.
577  */
578 
580  sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
581 }
582 
583 
585  CoordinateTuple* targetCoordinates,
586  Accuracy* targetAccuracy,
587  CoordinateTuple& sourceCoordinates,
588  Accuracy& sourceAccuracy )
589 {
590 /*
591  * The function convertTargetToSource converts the current target coordinates in the coordinate
592  * system defined by the current target coordinate system parameters and target datum,
593  * into source coordinates in the coordinate system defined by the source coordinate
594  * system parameters and source datum.
595  */
596 
597  convert(
599  targetCoordinates, targetAccuracy,
600  sourceCoordinates, sourceAccuracy );
601 }
602 
603 
605  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
606  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracy,
607  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
608  std::vector<MSP::CCS::Accuracy*>& targetAccuracy )
609 {
610 /*
611  * The function convertSourceToTargetCollection will convert a list of
612  * source coordinates to a list of target coordinates in a single step.
613  *
614  * sourceCoordinates : Coordinates to be converted (input)
615  * sourceAccuracy : Source circular, linear and spherical errors (input)
616  * targetCoordinates : Converted coordinates of the target CS (output)
617  * targetAccuracy : Target circular, linear and spherical errors (output)
618  */
619 
620  convertCollection(
621  sourceCoordinates, sourceAccuracy, targetCoordinates, targetAccuracy );
622 }
623 
624 
626  const std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
627  const std::vector<MSP::CCS::Accuracy*>& targetAccuracy,
628  std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
629  std::vector<MSP::CCS::Accuracy*>& sourceAccuracy )
630 {
631 /*
632  * The function convertTargetToSourceCollection will convert a list of target
633  * coordinates to a list of source coordinates in a single step.
634  *
635  * targetCoordinates : Converted coordinates of the target CS (input)
636  * targetAccuracy : Target circular, linear and spherical errors (input)
637  * sourceCoordinates : Coordinates of the source CS to be converted (output)
638  * sourceAccuracy : Source circular, linear and spherical errors (output)
639  */
640 
641  convertCollection(
642  targetCoordinates, targetAccuracy, sourceCoordinates, sourceAccuracy );
643 }
644 
645 
647 {
648  /*
649  * The function getEllipsoidLibrary returns the ellipsoid library
650  * which provides access to ellipsoidparameter information.
651  *
652  */
653 
654  return ccsData->ellipsoidLibrary;
655 }
656 
657 
659 {
660  /*
661  * The function getDatumLibrary returns the datum library
662  * which provides access to datum transformation and parameter information.
663  *
664  */
665 
666  return ccsData->datumLibrary;
667 }
668 
669 
671 {
672  /*
673  * The function getServiceVersion returns current service version.
674  */
675 
676  return 360; // update service version for msp 1.5
677 }
678 
679 
681  const SourceOrTarget::Enum direction ) const
682 {
683  /*
684  * The function getDatum returns the index of the current datum
685  *
686  * direction : Indicates whether the datum is for source or target (input)
687  */
688 
689  return coordinateSystemState[direction].datumCode;
690 }
691 
692 
695  const SourceOrTarget::Enum direction ) const
696 {
697  /*
698  * The function getCoordinateSystem returns the current coordinate system
699  * type.
700  *
701  * direction : Indicates whether the coordinate system is to be used for
702  * source or target (input)
703  */
704 
705  switch( coordinateSystemState[direction].coordinateType )
706  {
709  return coordinateSystemState[direction].parameters.mapProjection6Parameters;
718  return coordinateSystemState[direction].parameters.mapProjection4Parameters;
725  return coordinateSystemState[direction].parameters.mapProjection3Parameters;
727  return coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
729  return coordinateSystemState[direction].parameters.geodeticParameters;
733  return coordinateSystemState[direction].parameters.mapProjection5Parameters;
735  return coordinateSystemState[direction].parameters.localCartesianParameters;
737  return ((Mercator*)(coordinateSystemState[direction].coordinateSystem))->getStandardParallelParameters(); // gets the calculated scale factor
739  return coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
741  return coordinateSystemState[direction].parameters.neysParameters;
743  return coordinateSystemState[direction].parameters.obliqueMercatorParameters;
745  return coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
747  return coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
749  return coordinateSystemState[direction].parameters.utmParameters;
759  return coordinateSystemState[direction].parameters.coordinateSystemParameters;
760  default:
762  }
763 }
764 
765 
766 /************************************************************************/
767 /* PRIVATE FUNCTIONS
768  *
769  */
770 
771 void CoordinateConversionService::initCoordinateSystemState(
772  const SourceOrTarget::Enum direction )
773 {
774 /*
775  * The function initCoordinateSystemState initializes coordinateSystemState.
776  *
777  * direction : Indicates whether the coordinate system is to be used for
778  * source or target (input)
779  */
780 
781  CCSThreadLock lock(&mutex);
782 
783  coordinateSystemState[direction].datumIndex = 0;
784  coordinateSystemState[direction].coordinateType = CoordinateType::geodetic;
785  coordinateSystemState[direction].coordinateSystem = 0;
786 
787  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
788  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
789  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
790  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
791  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
792  coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
793  coordinateSystemState[direction].parameters.geodeticParameters = 0;
794  coordinateSystemState[direction].parameters.localCartesianParameters = 0;
795  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
796  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
797  coordinateSystemState[direction].parameters.neysParameters = 0;
798  coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
799  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
800  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
801  coordinateSystemState[direction].parameters.utmParameters = 0;
802 }
803 
804 
805 void CoordinateConversionService::setDataLibraries()
806 {
807  /*
808  * The function setDataLibraries sets the initial state of the engine in
809  * in preparation for coordinate conversion and/or datum transformation
810  * operations.
811  */
812 
813  try
814  {
815  datumLibraryImplementation->setEllipsoidLibraryImplementation(
816  ellipsoidLibraryImplementation );
817  ellipsoidLibraryImplementation->setDatumLibraryImplementation(
818  datumLibraryImplementation );
819  }
821  {
822  char message[256] = "Error initializing MSP CCS data: ";
823  strcpy( message, e.getMessage() );
824  throw CoordinateConversionException( message );
825  }
826 }
827 
828 
829 void CoordinateConversionService::setDatum(
830  const SourceOrTarget::Enum direction,
831  const char* datumCode )
832 {
833  /*
834  * The function setDatum sets the datum to the
835  * datum corresponding to the specified index.
836  *
837  * direction : Indicates whether the datum is for source or target (input)
838  * datumCode : Identifies the code of the datum to be used (input)
839  */
840 
841  CCSThreadLock lock(&mutex);
842 
843  if( !datumCode )
845 
846  strcpy( coordinateSystemState[direction].datumCode, datumCode );
847 
848  long datumIndex = 0;
849  datumLibraryImplementation->datumIndex( datumCode, &datumIndex );
850  coordinateSystemState[direction].datumIndex = datumIndex;
851 }
852 
853 
854 void CoordinateConversionService::setCoordinateSystem(
855  const SourceOrTarget::Enum direction,
857 {
858  /*
859  * The function setCoordinateSystem sets the coordinate system.
860  *
861  * direction : Indicates whether the coordinate system is to be used for
862  * source or target (input)
863  * parameters : Coordinate system parameters to be used (input)
864  */
865 
866  CCSThreadLock lock(&mutex);
867 
868  coordinateSystemState[direction].coordinateSystem = 0;
869 
870  switch( parameters->coordinateType() )
871  {
873  coordinateSystemState[direction].coordinateType =
875  coordinateSystemState[direction].parameters.mapProjection6Parameters =
877  *dynamic_cast< MapProjection6Parameters* >( parameters ) );
878  break;
880  coordinateSystemState[direction].coordinateType =
882  coordinateSystemState[direction].parameters.mapProjection4Parameters =
884  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
885  break;
887  coordinateSystemState[direction].coordinateType = CoordinateType::bonne;
888  coordinateSystemState[direction].parameters.mapProjection4Parameters =
890  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
891  break;
893  coordinateSystemState[direction].coordinateType =
895  coordinateSystemState[direction].parameters.coordinateSystemParameters =
897  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
898  break;
900  coordinateSystemState[direction].coordinateType = CoordinateType::cassini;
901  coordinateSystemState[direction].parameters.mapProjection4Parameters =
903  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
904  break;
906  coordinateSystemState[direction].coordinateType =
908  coordinateSystemState[direction].parameters.mapProjection4Parameters =
910  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
911  break;
913  coordinateSystemState[direction].coordinateType = CoordinateType::eckert4;
914  coordinateSystemState[direction].parameters.mapProjection3Parameters =
916  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
917  break;
919  coordinateSystemState[direction].coordinateType = CoordinateType::eckert6;
920  coordinateSystemState[direction].parameters.mapProjection3Parameters =
922  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
923  break;
925  coordinateSystemState[direction].coordinateType =
927  coordinateSystemState[direction].parameters.equidistantCylindricalParameters =
929  *dynamic_cast< EquidistantCylindricalParameters* >( parameters ) );
930  break;
932  coordinateSystemState[direction].coordinateType =
934  coordinateSystemState[direction].parameters.coordinateSystemParameters =
936  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
937  break;
939  coordinateSystemState[direction].coordinateType =
941  coordinateSystemState[direction].parameters.geodeticParameters =
942  new GeodeticParameters(
943  *dynamic_cast< GeodeticParameters* >( parameters ) );
944  break;
946  coordinateSystemState[direction].coordinateType = CoordinateType::georef;
947  coordinateSystemState[direction].parameters.coordinateSystemParameters =
949  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
950  break;
952  coordinateSystemState[direction].coordinateType =
954  coordinateSystemState[direction].parameters.coordinateSystemParameters =
956  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
957  break;
959  coordinateSystemState[direction].coordinateType =
961  coordinateSystemState[direction].parameters.mapProjection4Parameters =
963  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
964  break;
966  coordinateSystemState[direction].coordinateType = CoordinateType::lambertConformalConic1Parallel;
967  coordinateSystemState[direction].parameters.mapProjection5Parameters =
969  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
970  break;
972  coordinateSystemState[direction].coordinateType =
974  coordinateSystemState[direction].parameters.mapProjection6Parameters =
976  *dynamic_cast< MapProjection6Parameters* >( parameters ) );
977  break;
979  coordinateSystemState[direction].coordinateType =
981  coordinateSystemState[direction].parameters.localCartesianParameters =
983  *dynamic_cast< LocalCartesianParameters* >( parameters ) );
984  break;
986  coordinateSystemState[direction].coordinateType =
988  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters =
990  *dynamic_cast< MercatorStandardParallelParameters* >( parameters ));
991  break;
993  coordinateSystemState[direction].coordinateType =
995  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters =
997  *dynamic_cast< MercatorScaleFactorParameters* >( parameters ) );
998  break;
1000  coordinateSystemState[direction].coordinateType =
1002  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1004  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1005  break;
1007  coordinateSystemState[direction].coordinateType = CoordinateType::millerCylindrical;
1008  coordinateSystemState[direction].parameters.mapProjection3Parameters =
1010  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
1011  break;
1013  coordinateSystemState[direction].coordinateType =
1015  coordinateSystemState[direction].parameters.mapProjection3Parameters =
1017  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
1018  break;
1020  coordinateSystemState[direction].coordinateType =
1022  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1024  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1025  break;
1026  case CoordinateType::neys:
1027  coordinateSystemState[direction].coordinateType = CoordinateType::neys;
1028  coordinateSystemState[direction].parameters.neysParameters =
1029  new NeysParameters( *dynamic_cast< NeysParameters* >( parameters ) );
1030  break;
1032  coordinateSystemState[direction].coordinateType =
1034  coordinateSystemState[direction].parameters.obliqueMercatorParameters =
1036  *dynamic_cast< ObliqueMercatorParameters* >( parameters ) );
1037  break;
1039  coordinateSystemState[direction].coordinateType =
1041  coordinateSystemState[direction].parameters.mapProjection4Parameters =
1043  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
1044  break;
1046  coordinateSystemState[direction].coordinateType =
1048  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters =
1050  *dynamic_cast< PolarStereographicStandardParallelParameters* >(
1051  parameters ) );
1052  break;
1054  coordinateSystemState[direction].coordinateType =
1056  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters =
1058  *dynamic_cast< PolarStereographicScaleFactorParameters* >( parameters ) );
1059  break;
1061  coordinateSystemState[direction].coordinateType =
1063  coordinateSystemState[direction].parameters.mapProjection4Parameters =
1065  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
1066  break;
1068  coordinateSystemState[direction].coordinateType =
1070  coordinateSystemState[direction].parameters.mapProjection3Parameters =
1072  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
1073  break;
1075  coordinateSystemState[direction].coordinateType =
1077  coordinateSystemState[direction].parameters.mapProjection4Parameters =
1079  *dynamic_cast< MapProjection4Parameters* >( parameters ) );
1080  break;
1082  coordinateSystemState[direction].coordinateType =
1084  coordinateSystemState[direction].parameters.mapProjection5Parameters =
1086  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
1087  break;
1089  coordinateSystemState[direction].coordinateType =
1091  coordinateSystemState[direction].parameters.mapProjection5Parameters =
1093  *dynamic_cast< MapProjection5Parameters* >( parameters ) );
1094  break;
1096  coordinateSystemState[direction].coordinateType =
1098  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1100  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1101  break;
1103  coordinateSystemState[direction].coordinateType =
1105  coordinateSystemState[direction].parameters.utmParameters =
1106  new UTMParameters( *dynamic_cast< UTMParameters* >( parameters ) );
1107  break;
1109  coordinateSystemState[direction].coordinateType =
1111  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1113  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1114  break;
1116  coordinateSystemState[direction].coordinateType =
1118  coordinateSystemState[direction].parameters.mapProjection3Parameters =
1120  *dynamic_cast< MapProjection3Parameters* >( parameters ) );
1121  break;
1123  coordinateSystemState[direction].coordinateType =
1125  coordinateSystemState[direction].parameters.coordinateSystemParameters =
1127  *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
1128  break;
1129  default:
1131  }
1132 
1133  setParameters( direction );
1134 }
1135 
1136 void CoordinateConversionService::setParameters(
1137  const SourceOrTarget::Enum direction )
1138 {
1139 /*
1140  * The function setParameters calls the setParameters function of the source
1141  * or target coordinate system.
1142  *
1143  * direction : Indicates whether the coordinate system is to be used for
1144  * source or target (input)
1145  */
1146 
1147 
1148  Coordinate_State_Row* row = &coordinateSystemState[direction];
1149 
1150  char ellipsoidCode[3];
1151  long ellipsoidIndex;
1152  double semiMajorAxis;
1153  double flattening;
1154 
1155  datumLibraryImplementation->datumEllipsoidCode(
1156  row->datumIndex, ellipsoidCode );
1157 
1158  ellipsoidLibraryImplementation->ellipsoidIndex(
1159  ellipsoidCode, &ellipsoidIndex );
1160 
1161  ellipsoidLibraryImplementation->ellipsoidParameters(
1162  ellipsoidIndex, &semiMajorAxis, &flattening );
1163 
1164  switch( coordinateSystemState[direction].coordinateType )
1165  {
1167  {
1168  MapProjection6Parameters* param =
1169  row->parameters.mapProjection6Parameters;
1170 
1171  coordinateSystemState[direction].coordinateSystem =
1173  semiMajorAxis, flattening,
1174  param->centralMeridian(),
1175  param->originLatitude(),
1176  param->standardParallel1(),
1177  param->standardParallel2(),
1178  param->falseEasting(),
1179  param->falseNorthing() );
1180  break;
1181  }
1183  {
1184  MapProjection4Parameters* param =
1185  row->parameters.mapProjection4Parameters;
1186 
1187  coordinateSystemState[direction].coordinateSystem =
1189  semiMajorAxis, flattening,
1190  param->centralMeridian(),
1191  param->originLatitude(),
1192  param->falseEasting(),
1193  param->falseNorthing() );
1194  break;
1195  }
1196  case CoordinateType::bonne:
1197  {
1198  MapProjection4Parameters* param = row->parameters.mapProjection4Parameters;
1199 
1200  coordinateSystemState[direction].coordinateSystem = new Bonne(
1201  semiMajorAxis, flattening,
1202  param->centralMeridian(),
1203  param->originLatitude(),
1204  param->falseEasting(),
1205  param->falseNorthing() );
1206  break;
1207  }
1209  {
1210  coordinateSystemState[direction].coordinateSystem =
1211  new BritishNationalGrid( ellipsoidCode );
1212 
1213  break;
1214  }
1216  {
1217  MapProjection4Parameters* param =
1218  row->parameters.mapProjection4Parameters;
1219 
1220  coordinateSystemState[direction].coordinateSystem = new Cassini(
1221  semiMajorAxis, flattening,
1222  param->centralMeridian(),
1223  param->originLatitude(),
1224  param->falseEasting(),
1225  param->falseNorthing() );
1226  break;
1227  }
1229  {
1230  MapProjection4Parameters* param =
1231  row->parameters.mapProjection4Parameters;
1232 
1233  coordinateSystemState[direction].coordinateSystem =
1235  semiMajorAxis, flattening,
1236  param->centralMeridian(),
1237  param->originLatitude(),
1238  param->falseEasting(),
1239  param->falseNorthing() );
1240  break;
1241  }
1243  {
1244  MapProjection3Parameters* param =
1245  row->parameters.mapProjection3Parameters;
1246 
1247  coordinateSystemState[direction].coordinateSystem = new Eckert4(
1248  semiMajorAxis, flattening,
1249  param->centralMeridian(),
1250  param->falseEasting(),
1251  param->falseNorthing() );
1252  break;
1253  }
1255  {
1256  MapProjection3Parameters* param =
1257  row->parameters.mapProjection3Parameters;
1258 
1259  coordinateSystemState[direction].coordinateSystem = new Eckert6(
1260  semiMajorAxis, flattening,
1261  param->centralMeridian(),
1262  param->falseEasting(),
1263  param->falseNorthing() );
1264  break;
1265  }
1267  {
1269  row->parameters.equidistantCylindricalParameters;
1270 
1271  coordinateSystemState[direction].coordinateSystem =
1273  semiMajorAxis,flattening,
1274  param->centralMeridian(),
1275  param->standardParallel(),
1276  param->falseEasting(),
1277  param->falseNorthing() );
1278  break;
1279  }
1281  {
1282  coordinateSystemState[direction].coordinateSystem =
1283  new Geocentric( semiMajorAxis, flattening );
1284  break;
1285  }
1287  coordinateSystemState[direction].coordinateSystem = 0;
1288  break;
1290  coordinateSystemState[direction].coordinateSystem = new GEOREF();
1291  break;
1293  coordinateSystemState[direction].coordinateSystem = new GARS();
1294  break;
1296  {
1297  MapProjection4Parameters* param =
1298  row->parameters.mapProjection4Parameters;
1299 
1300  coordinateSystemState[direction].coordinateSystem = new Gnomonic(
1301  semiMajorAxis, flattening,
1302  param->centralMeridian(),
1303  param->originLatitude(),
1304  param->falseEasting(),
1305  param->falseNorthing() );
1306  break;
1307  }
1309  {
1310  MapProjection5Parameters* param = row->parameters.mapProjection5Parameters;
1311 
1312  coordinateSystemState[direction].coordinateSystem =
1314  semiMajorAxis, flattening,
1315  param->centralMeridian(),
1316  param->originLatitude(),
1317  param->falseEasting(),
1318  param->falseNorthing(),
1319  param->scaleFactor() );
1320  break;
1321  }
1323  {
1324  MapProjection6Parameters* param =
1325  row->parameters.mapProjection6Parameters;
1326 
1327  coordinateSystemState[direction].coordinateSystem =
1329  semiMajorAxis, flattening,
1330  param->centralMeridian(),
1331  param->originLatitude(),
1332  param->standardParallel1(),
1333  param->standardParallel2(),
1334  param->falseEasting(),
1335  param->falseNorthing() );
1336  break;
1337  }
1339  {
1340  LocalCartesianParameters* param =
1341  row->parameters.localCartesianParameters;
1342 
1343  coordinateSystemState[direction].coordinateSystem = new LocalCartesian(
1344  semiMajorAxis, flattening,
1345  param->longitude(),
1346  param->latitude(),
1347  param->height(),
1348  param->orientation() );
1349  break;
1350  }
1352  {
1354  row->parameters.mercatorStandardParallelParameters;
1355  double scaleFactor;
1356  coordinateSystemState[direction].coordinateSystem = new Mercator(
1357  semiMajorAxis, flattening,
1358  param->centralMeridian(),
1359  param->standardParallel(),
1360  param->falseEasting(),
1361  param->falseNorthing(),
1362  &scaleFactor );
1363 
1364  param->setScaleFactor( scaleFactor );
1365 
1366  break;
1367  }
1369  {
1371  row->parameters.mercatorScaleFactorParameters;
1372 
1373  coordinateSystemState[direction].coordinateSystem = new Mercator(
1374  semiMajorAxis, flattening,
1375  param->centralMeridian(),
1376  param->falseEasting(),
1377  param->falseNorthing(),
1378  param->scaleFactor() );
1379 
1380  break;
1381  }
1383  {
1384  coordinateSystemState[direction].coordinateSystem = new MGRS(
1385  semiMajorAxis, flattening, ellipsoidCode );
1386 
1387  break;
1388  }
1390  {
1391  MapProjection3Parameters* param =
1392  row->parameters.mapProjection3Parameters;
1393 
1394  coordinateSystemState[direction].coordinateSystem =
1395  new MillerCylindrical(
1396  semiMajorAxis, flattening,
1397  param->centralMeridian(),
1398  param->falseEasting(),
1399  param->falseNorthing() );
1400  break;
1401  }
1403  {
1404  MapProjection3Parameters* param =
1405  row->parameters.mapProjection3Parameters;
1406 
1407  coordinateSystemState[direction].coordinateSystem = new Mollweide(
1408  semiMajorAxis,flattening,
1409  param->centralMeridian(),
1410  param->falseEasting(),
1411  param->falseNorthing() );
1412  break;
1413  }
1415  {
1416  coordinateSystemState[direction].coordinateSystem =
1417  new NZMG( ellipsoidCode );
1418 
1419  break;
1420  }
1421  case CoordinateType::neys:
1422  {
1423  NeysParameters* param = row->parameters.neysParameters;
1424 
1425  coordinateSystemState[direction].coordinateSystem = new Neys(
1426  semiMajorAxis, flattening,
1427  param->centralMeridian(),
1428  param->originLatitude(),
1429  param->standardParallel1(),
1430  param->falseEasting(),
1431  param->falseNorthing() );
1432  break;
1433  }
1435  {
1436  ObliqueMercatorParameters* param =
1437  row->parameters.obliqueMercatorParameters;
1438 
1439  coordinateSystemState[direction].coordinateSystem = new ObliqueMercator(
1440  semiMajorAxis, flattening,
1441  param->originLatitude(),
1442  param->longitude1(),
1443  param->latitude1(),
1444  param->longitude2(),
1445  param->latitude2(),
1446  param->falseEasting(),
1447  param->falseNorthing(),
1448  param->scaleFactor() );
1449  break;
1450  }
1452  {
1453  MapProjection4Parameters* param =
1454  row->parameters.mapProjection4Parameters;
1455 
1456  coordinateSystemState[direction].coordinateSystem = new Orthographic(
1457  semiMajorAxis, flattening,
1458  param->centralMeridian(),
1459  param->originLatitude(),
1460  param->falseEasting(),
1461  param->falseNorthing() );
1462  break;
1463  }
1465  {
1467  row->parameters.polarStereographicStandardParallelParameters;
1468 
1469  coordinateSystemState[direction].coordinateSystem =
1470  new PolarStereographic(
1471  semiMajorAxis, flattening,
1472  param->centralMeridian(),
1473  param->standardParallel(),
1474  param->falseEasting(),
1475  param->falseNorthing() );
1476 
1477  break;
1478  }
1480  {
1482  row->parameters.polarStereographicScaleFactorParameters;
1483 
1484  coordinateSystemState[direction].coordinateSystem =
1485  new PolarStereographic(
1486  semiMajorAxis, flattening,
1487  param->centralMeridian(),
1488  param->scaleFactor(),
1489  param->hemisphere(),
1490  param->falseEasting(),
1491  param->falseNorthing() );
1492  break;
1493  }
1495  {
1496  MapProjection4Parameters* param =
1497  row->parameters.mapProjection4Parameters;
1498 
1499  coordinateSystemState[direction].coordinateSystem = new Polyconic(
1500  semiMajorAxis, flattening,
1501  param->centralMeridian(),
1502  param->originLatitude(),
1503  param->falseEasting(),
1504  param->falseNorthing() );
1505  break;
1506  }
1508  {
1509  MapProjection3Parameters* param =
1510  row->parameters.mapProjection3Parameters;
1511 
1512  coordinateSystemState[direction].coordinateSystem = new Sinusoidal(
1513  semiMajorAxis, flattening,
1514  param->centralMeridian(),
1515  param->falseEasting(),
1516  param->falseNorthing() );
1517  break;
1518  }
1520  {
1521  MapProjection4Parameters* param =
1522  row->parameters.mapProjection4Parameters;
1523 
1524  coordinateSystemState[direction].coordinateSystem = new Stereographic(
1525  semiMajorAxis, flattening,
1526  param->centralMeridian(),
1527  param->originLatitude(),
1528  param->falseEasting(),
1529  param->falseNorthing() );
1530  break;
1531  }
1533  {
1534  MapProjection5Parameters* param =
1535  row->parameters.mapProjection5Parameters;
1536 
1537  coordinateSystemState[direction].coordinateSystem =
1539  semiMajorAxis, flattening,
1540  param->centralMeridian(),
1541  param->originLatitude(),
1542  param->falseEasting(),
1543  param->falseNorthing(),
1544  param->scaleFactor() );
1545  break;
1546  }
1548  {
1549  MapProjection5Parameters* param =
1550  row->parameters.mapProjection5Parameters;
1551 
1552  coordinateSystemState[direction].coordinateSystem =
1553  new TransverseMercator(
1554  semiMajorAxis, flattening,
1555  param->centralMeridian(),
1556  param->originLatitude(),
1557  param->falseEasting(),
1558  param->falseNorthing(),
1559  param->scaleFactor(),
1560  ellipsoidCode);
1561  break;
1562  }
1564  {
1565  coordinateSystemState[direction].coordinateSystem = new UPS(
1566  semiMajorAxis, flattening );
1567 
1568  break;
1569  }
1571  {
1572  if( direction == SourceOrTarget::target )
1573  {
1574  UTMParameters* param = row->parameters.utmParameters;
1575 
1576  if((param->override() != 0) && (param->zone() == 0))
1578  else
1579  {
1580  if(param->override() == 0)
1581  param->setZone( 0 );
1582  }
1583 
1584  coordinateSystemState[direction].coordinateSystem = new UTM(
1585  semiMajorAxis, flattening, ellipsoidCode, param->zone() );
1586  }
1587  else
1588  coordinateSystemState[direction].coordinateSystem = new UTM(
1589  semiMajorAxis, flattening, ellipsoidCode, 0 );
1590 
1591  break;
1592  }
1594  {
1595  coordinateSystemState[direction].coordinateSystem = new USNG(
1596  semiMajorAxis, flattening, ellipsoidCode );
1597 
1598  break;
1599  }
1601  {
1602  MapProjection3Parameters* param =
1603  row->parameters.mapProjection3Parameters;
1604 
1605  coordinateSystemState[direction].coordinateSystem = new VanDerGrinten(
1606  semiMajorAxis, flattening,
1607  param->centralMeridian(),
1608  param->falseEasting(),
1609  param->falseNorthing() );
1610  break;
1611  }
1613  {
1614  coordinateSystemState[direction].coordinateSystem =
1615  new WebMercator( ellipsoidCode );
1616  break;
1617  }
1618  default:
1619  break;
1620  }
1621 }
1622 
1623 
1624 void CoordinateConversionService::deleteCoordinateSystem(
1625  const SourceOrTarget::Enum direction )
1626 {
1627 /*
1628  * The function deleteCoordinateSystem frees memory of coordinateSystemState.
1629  *
1630  * direction : Indicates whether the coordinate system is to be used for
1631  * source or target (input)
1632  */
1633 
1634  switch( coordinateSystemState[direction].coordinateType )
1635  {
1637  if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
1638  {
1639  delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
1640  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
1641  }
1642  if( coordinateSystemState[direction].coordinateSystem )
1643  {
1644  delete ((AlbersEqualAreaConic*)(coordinateSystemState[direction].coordinateSystem));
1645  coordinateSystemState[direction].coordinateSystem = 0;
1646  }
1647  break;
1649  if( coordinateSystemState[direction].parameters.mapProjection6Parameters )
1650  {
1651  delete coordinateSystemState[direction].parameters.mapProjection6Parameters;
1652  coordinateSystemState[direction].parameters.mapProjection6Parameters = 0;
1653  }
1654  if( coordinateSystemState[direction].coordinateSystem )
1655  {
1656  delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
1657  coordinateSystemState[direction].coordinateSystem = 0;
1658  }
1659  break;
1661  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1662  {
1663  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1664  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1665  }
1666  if( coordinateSystemState[direction].coordinateSystem )
1667  {
1668  delete ((AzimuthalEquidistant*)(coordinateSystemState[direction].coordinateSystem));
1669  coordinateSystemState[direction].coordinateSystem = 0;
1670  }
1671  break;
1672  case CoordinateType::bonne:
1673  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1674  {
1675  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1676  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1677  }
1678  if( coordinateSystemState[direction].coordinateSystem )
1679  {
1680  delete ((Bonne*)(coordinateSystemState[direction].coordinateSystem));
1681  coordinateSystemState[direction].coordinateSystem = 0;
1682  }
1683  break;
1685  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1686  {
1687  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1688  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1689  }
1690  if( coordinateSystemState[direction].coordinateSystem )
1691  {
1692  delete ((Cassini*)(coordinateSystemState[direction].coordinateSystem));
1693  coordinateSystemState[direction].coordinateSystem = 0;
1694  }
1695  break;
1697  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1698  {
1699  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1700  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1701  }
1702  if( coordinateSystemState[direction].coordinateSystem )
1703  {
1704  delete ((CylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
1705  coordinateSystemState[direction].coordinateSystem = 0;
1706  }
1707  break;
1709  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1710  {
1711  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1712  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1713  }
1714  if( coordinateSystemState[direction].coordinateSystem )
1715  {
1716  delete ((Gnomonic*)(coordinateSystemState[direction].coordinateSystem));
1717  coordinateSystemState[direction].coordinateSystem = 0;
1718  }
1719  break;
1721  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1722  {
1723  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1724  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1725  }
1726  if( coordinateSystemState[direction].coordinateSystem )
1727  {
1728  delete ((Orthographic*)(coordinateSystemState[direction].coordinateSystem));
1729  coordinateSystemState[direction].coordinateSystem = 0;
1730  }
1731  break;
1733  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1734  {
1735  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1736  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1737  }
1738  if( coordinateSystemState[direction].coordinateSystem )
1739  {
1740  delete ((Polyconic*)(coordinateSystemState[direction].coordinateSystem));
1741  coordinateSystemState[direction].coordinateSystem = 0;
1742  }
1743  break;
1745  if( coordinateSystemState[direction].parameters.mapProjection4Parameters )
1746  {
1747  delete coordinateSystemState[direction].parameters.mapProjection4Parameters;
1748  coordinateSystemState[direction].parameters.mapProjection4Parameters = 0;
1749  }
1750  if( coordinateSystemState[direction].coordinateSystem )
1751  {
1752  delete ((Stereographic*)(coordinateSystemState[direction].coordinateSystem));
1753  coordinateSystemState[direction].coordinateSystem = 0;
1754  }
1755  break;
1757  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1758  {
1759  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1760  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1761  }
1762  if( coordinateSystemState[direction].coordinateSystem )
1763  {
1764  delete ((BritishNationalGrid*)(coordinateSystemState[direction].coordinateSystem));
1765  coordinateSystemState[direction].coordinateSystem = 0;
1766  }
1767  break;
1769  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1770  {
1771  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1772  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1773  }
1774  if( coordinateSystemState[direction].coordinateSystem )
1775  {
1776  delete ((Eckert4*)(coordinateSystemState[direction].coordinateSystem));
1777  coordinateSystemState[direction].coordinateSystem = 0;
1778  }
1779  break;
1781  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1782  {
1783  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1784  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1785  }
1786  if( coordinateSystemState[direction].coordinateSystem )
1787  {
1788  delete ((Eckert6*)(coordinateSystemState[direction].coordinateSystem));
1789  coordinateSystemState[direction].coordinateSystem = 0;
1790  }
1791  break;
1793  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1794  {
1795  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1796  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1797  }
1798  if( coordinateSystemState[direction].coordinateSystem )
1799  {
1800  delete ((MillerCylindrical*)(coordinateSystemState[direction].coordinateSystem));
1801  coordinateSystemState[direction].coordinateSystem = 0;
1802  }
1803  break;
1805  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1806  {
1807  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1808  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1809  }
1810  if( coordinateSystemState[direction].coordinateSystem )
1811  {
1812  delete ((Mollweide*)(coordinateSystemState[direction].coordinateSystem));
1813  coordinateSystemState[direction].coordinateSystem = 0;
1814  }
1815  break;
1817  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1818  {
1819  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1820  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1821  }
1822  if( coordinateSystemState[direction].coordinateSystem )
1823  {
1824  delete ((Sinusoidal*)(coordinateSystemState[direction].coordinateSystem));
1825  coordinateSystemState[direction].coordinateSystem = 0;
1826  }
1827  break;
1829  if( coordinateSystemState[direction].parameters.mapProjection3Parameters )
1830  {
1831  delete coordinateSystemState[direction].parameters.mapProjection3Parameters;
1832  coordinateSystemState[direction].parameters.mapProjection3Parameters = 0;
1833  }
1834  if( coordinateSystemState[direction].coordinateSystem )
1835  {
1836  delete ((VanDerGrinten*)(coordinateSystemState[direction].coordinateSystem));
1837  coordinateSystemState[direction].coordinateSystem = 0;
1838  }
1839  break;
1841  if( coordinateSystemState[direction].parameters.equidistantCylindricalParameters )
1842  {
1843  delete coordinateSystemState[direction].parameters.equidistantCylindricalParameters;
1844  coordinateSystemState[direction].parameters.equidistantCylindricalParameters = 0;
1845  }
1846  if( coordinateSystemState[direction].coordinateSystem )
1847  {
1848  delete ((EquidistantCylindrical*)(coordinateSystemState[direction].coordinateSystem));
1849  coordinateSystemState[direction].coordinateSystem = 0;
1850  }
1851  break;
1853  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1854  {
1855  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1856  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1857  }
1858  if( coordinateSystemState[direction].coordinateSystem )
1859  {
1860  delete ((Geocentric*)(coordinateSystemState[direction].coordinateSystem));
1861  coordinateSystemState[direction].coordinateSystem = 0;
1862  }
1863  break;
1865  if( coordinateSystemState[direction].parameters.geodeticParameters )
1866  {
1867  delete coordinateSystemState[direction].parameters.geodeticParameters;
1868  coordinateSystemState[direction].parameters.geodeticParameters = 0;
1869  }
1870  break;
1872  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1873  {
1874  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1875  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1876  }
1877  if( coordinateSystemState[direction].coordinateSystem )
1878  {
1879  delete ((GEOREF*)(coordinateSystemState[direction].coordinateSystem));
1880  coordinateSystemState[direction].coordinateSystem = 0;
1881  }
1882  break;
1884  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1885  {
1886  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1887  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1888  }
1889  if( coordinateSystemState[direction].coordinateSystem )
1890  {
1891  delete ((GARS*)(coordinateSystemState[direction].coordinateSystem));
1892  coordinateSystemState[direction].coordinateSystem = 0;
1893  }
1894  break;
1896  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1897  {
1898  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1899  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1900  }
1901  if( coordinateSystemState[direction].coordinateSystem )
1902  {
1903  delete ((LambertConformalConic*)(coordinateSystemState[direction].coordinateSystem));
1904  coordinateSystemState[direction].coordinateSystem = 0;
1905  }
1906  break;
1908  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1909  {
1910  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1911  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1912  }
1913  if( coordinateSystemState[direction].coordinateSystem )
1914  {
1915  delete ((TransverseCylindricalEqualArea*)(coordinateSystemState[direction].coordinateSystem));
1916  coordinateSystemState[direction].coordinateSystem = 0;
1917  }
1918  break;
1920  if( coordinateSystemState[direction].parameters.mapProjection5Parameters )
1921  {
1922  delete coordinateSystemState[direction].parameters.mapProjection5Parameters;
1923  coordinateSystemState[direction].parameters.mapProjection5Parameters = 0;
1924  }
1925  if( coordinateSystemState[direction].coordinateSystem )
1926  {
1927  delete ((TransverseMercator*)(coordinateSystemState[direction].coordinateSystem));
1928  coordinateSystemState[direction].coordinateSystem = 0;
1929  }
1930  break;
1932  if( coordinateSystemState[direction].parameters.localCartesianParameters )
1933  {
1934  delete coordinateSystemState[direction].parameters.localCartesianParameters;
1935  coordinateSystemState[direction].parameters.localCartesianParameters = 0;
1936  }
1937  if( coordinateSystemState[direction].coordinateSystem )
1938  {
1939  delete ((LocalCartesian*)(coordinateSystemState[direction].coordinateSystem));
1940  coordinateSystemState[direction].coordinateSystem = 0;
1941  }
1942  break;
1944  if( coordinateSystemState[direction].parameters.mercatorStandardParallelParameters )
1945  {
1946  delete coordinateSystemState[direction].parameters.mercatorStandardParallelParameters;
1947  coordinateSystemState[direction].parameters.mercatorStandardParallelParameters = 0;
1948  }
1949  if( coordinateSystemState[direction].coordinateSystem )
1950  {
1951  delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
1952  coordinateSystemState[direction].coordinateSystem = 0;
1953  }
1954  break;
1956  if( coordinateSystemState[direction].parameters.mercatorScaleFactorParameters )
1957  {
1958  delete coordinateSystemState[direction].parameters.mercatorScaleFactorParameters;
1959  coordinateSystemState[direction].parameters.mercatorScaleFactorParameters = 0;
1960  }
1961  if( coordinateSystemState[direction].coordinateSystem )
1962  {
1963  delete ((Mercator*)(coordinateSystemState[direction].coordinateSystem));
1964  coordinateSystemState[direction].coordinateSystem = 0;
1965  }
1966  break;
1968  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1969  {
1970  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1971  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1972  }
1973  if( coordinateSystemState[direction].coordinateSystem )
1974  {
1975  delete ((MGRS*)(coordinateSystemState[direction].coordinateSystem));
1976  coordinateSystemState[direction].coordinateSystem = 0;
1977  }
1978  break;
1980  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1981  {
1982  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1983  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1984  }
1985  if( coordinateSystemState[direction].coordinateSystem )
1986  {
1987  delete ((USNG*)(coordinateSystemState[direction].coordinateSystem));
1988  coordinateSystemState[direction].coordinateSystem = 0;
1989  }
1990  break;
1992  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
1993  {
1994  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
1995  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
1996  }
1997  if( coordinateSystemState[direction].coordinateSystem )
1998  {
1999  delete ((NZMG*)(coordinateSystemState[direction].coordinateSystem));
2000  coordinateSystemState[direction].coordinateSystem = 0;
2001  }
2002  break;
2003  case CoordinateType::neys:
2004  if( coordinateSystemState[direction].parameters.neysParameters )
2005  {
2006  delete coordinateSystemState[direction].parameters.neysParameters;
2007  coordinateSystemState[direction].parameters.neysParameters = 0;
2008  }
2009  if( coordinateSystemState[direction].coordinateSystem )
2010  {
2011  delete ((Neys*)(coordinateSystemState[direction].coordinateSystem));
2012  coordinateSystemState[direction].coordinateSystem = 0;
2013  }
2014  break;
2016  if( coordinateSystemState[direction].parameters.obliqueMercatorParameters )
2017  {
2018  delete coordinateSystemState[direction].parameters.obliqueMercatorParameters;
2019  coordinateSystemState[direction].parameters.obliqueMercatorParameters = 0;
2020  }
2021  if( coordinateSystemState[direction].coordinateSystem )
2022  {
2023  delete ((ObliqueMercator*)(coordinateSystemState[direction].coordinateSystem));
2024  coordinateSystemState[direction].coordinateSystem = 0;
2025  }
2026  break;
2028  if( coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters )
2029  {
2030  delete coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters;
2031  coordinateSystemState[direction].parameters.polarStereographicStandardParallelParameters = 0;
2032  }
2033  if( coordinateSystemState[direction].coordinateSystem )
2034  {
2035  delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
2036  coordinateSystemState[direction].coordinateSystem = 0;
2037  }
2038  break;
2040  if( coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters )
2041  {
2042  delete coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters;
2043  coordinateSystemState[direction].parameters.polarStereographicScaleFactorParameters = 0;
2044  }
2045  if( coordinateSystemState[direction].coordinateSystem )
2046  {
2047  delete ((PolarStereographic*)(coordinateSystemState[direction].coordinateSystem));
2048  coordinateSystemState[direction].coordinateSystem = 0;
2049  }
2050  break;
2052  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
2053  {
2054  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
2055  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
2056  }
2057  if( coordinateSystemState[direction].coordinateSystem )
2058  {
2059  delete ((UPS*)(coordinateSystemState[direction].coordinateSystem));
2060  coordinateSystemState[direction].coordinateSystem = 0;
2061  }
2062  break;
2064  if( coordinateSystemState[direction].parameters.utmParameters )
2065  {
2066  delete coordinateSystemState[direction].parameters.utmParameters;
2067  coordinateSystemState[direction].parameters.utmParameters = 0;
2068  }
2069  if( coordinateSystemState[direction].coordinateSystem )
2070  {
2071  delete ((UTM*)(coordinateSystemState[direction].coordinateSystem));
2072  coordinateSystemState[direction].coordinateSystem = 0;
2073  }
2074  break;
2076  if( coordinateSystemState[direction].parameters.coordinateSystemParameters )
2077  {
2078  delete coordinateSystemState[direction].parameters.coordinateSystemParameters;
2079  coordinateSystemState[direction].parameters.coordinateSystemParameters = 0;
2080  }
2081  if( coordinateSystemState[direction].coordinateSystem )
2082  {
2083  delete ((WebMercator*)(coordinateSystemState[direction].coordinateSystem));
2084  coordinateSystemState[direction].coordinateSystem = 0;
2085  }
2086  break;
2087  default:
2088  break;
2089  }
2090 }
2091 
2092 
2093 void CoordinateConversionService::copyParameters(
2094  SourceOrTarget::Enum direction,
2095  CoordinateType::Enum coordinateType,
2096  Parameters parameters )
2097 {
2098 /*
2099  * The function copyParameters uses the input parameters to set the value of the
2100  * current parameters.
2101  *
2102  * direction : Indicates whether the coordinate system is to be used for
2103  * source or target (input)
2104  * coordinateType : Coordinate system type (input)
2105  * parameters : Coordinate system parameters to copy (input)
2106  */
2107 
2108  initCoordinateSystemState( direction );
2109 
2110  switch( coordinateType )
2111  {
2114  setCoordinateSystem( direction, parameters.mapProjection6Parameters );
2115  break;
2117  case CoordinateType::bonne:
2124  setCoordinateSystem( direction, parameters.mapProjection4Parameters );
2125  break;
2132  setCoordinateSystem( direction, parameters.mapProjection3Parameters );
2133  break;
2135  setCoordinateSystem( direction, parameters.equidistantCylindricalParameters );
2136  break;
2138  setCoordinateSystem( direction, parameters.geodeticParameters );
2139  break;
2143  setCoordinateSystem( direction, parameters.mapProjection5Parameters );
2144  break;
2146  setCoordinateSystem( direction, parameters.localCartesianParameters );
2147  break;
2149  setCoordinateSystem( direction, parameters.mercatorStandardParallelParameters );
2150  break;
2152  setCoordinateSystem( direction, parameters.mercatorScaleFactorParameters );
2153  break;
2154  case CoordinateType::neys:
2155  setCoordinateSystem( direction, parameters.neysParameters );
2156  break;
2158  setCoordinateSystem( direction, parameters.obliqueMercatorParameters );
2159  break;
2161  setCoordinateSystem( direction, parameters.polarStereographicStandardParallelParameters );
2162  break;
2164  setCoordinateSystem( direction, parameters.polarStereographicScaleFactorParameters );
2165  break;
2167  setCoordinateSystem( direction, parameters.utmParameters );
2168  break;
2178  setCoordinateSystem( direction, parameters.coordinateSystemParameters );
2179  break;
2180  default:
2181  break;
2182  }
2183 }
2184 
2185 
2186 void CoordinateConversionService::convert(
2187  SourceOrTarget::Enum sourceDirection,
2188  SourceOrTarget::Enum targetDirection,
2189  CoordinateTuple* sourceCoordinates,
2190  Accuracy* sourceAccuracy,
2191  CoordinateTuple& targetCoordinates,
2192  Accuracy& targetAccuracy )
2193 {
2194 /*
2195  * The function convert converts the current source coordinates in the coordinate
2196  * system defined by the current source coordinate system parameters and source datum,
2197  * into target coordinates in the coordinate system defined by the target coordinate
2198  * system parameters and target datum.
2199  *
2200  * sourceDirection: Indicates which set of coordinates and parameters to use as the source (input)
2201  * targetDirection: Indicates which set of coordinates and parameters to use as the target (input)
2202  */
2203 
2204  CCSThreadLock lock(&mutex);
2205 
2206  GeodeticCoordinates* _convertedGeodetic = 0;
2207  GeodeticCoordinates* _wgs84Geodetic = 0;
2208  GeodeticCoordinates* _shiftedGeodetic = 0;
2209 
2210  bool special = false;
2211 
2212  Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
2213  Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
2214 
2215  char sourceWarningMessage[256] = "";
2216  char targetWarningMessage[256] = "";
2217 
2218  if ( // NGA only allows Web Mercator conversions to geodetic
2219  (source->coordinateType == CoordinateType::webMercator) &&
2220  (target->coordinateType != CoordinateType::geodetic) )
2221  {
2223  }
2224 
2225  try
2226  {
2227  try
2228  {
2229  /********************************************************/
2230  /* Check for special cases when there is no datum shift */
2231  /********************************************************/
2232  if (source->datumIndex == target->datumIndex)
2233  {
2234  if((source->coordinateType == CoordinateType::geocentric) &&
2235  (target->coordinateType == CoordinateType::localCartesian))
2236  {
2237  special = true;
2238 
2239  CartesianCoordinates* coordinates =
2240  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2241 
2242  CartesianCoordinates* cartesianCoordinates =
2243  ((LocalCartesian*)(
2244  target->coordinateSystem))->convertFromGeocentric(
2245  coordinates );
2246  (dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ) =
2247  *dynamic_cast< CartesianCoordinates* >( cartesianCoordinates );
2248  delete cartesianCoordinates;
2249  }
2250  else if((source->coordinateType == CoordinateType::localCartesian) &&
2251  (target->coordinateType == CoordinateType::geocentric))
2252  {
2253  special = true;
2254 
2255  CartesianCoordinates* coordinates =
2256  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2257 
2258  CartesianCoordinates* cartesianCoordinates =
2259  ((LocalCartesian*)(source->coordinateSystem))->convertToGeocentric(
2260  coordinates );
2261  (dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ) =
2262  *dynamic_cast< CartesianCoordinates* >( cartesianCoordinates );
2263  delete cartesianCoordinates;
2264  }
2265  else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
2266  (target->coordinateType == CoordinateType::universalTransverseMercator) &&
2267  (target->parameters.utmParameters->override() == 0))
2268  {
2269  special = true;
2270 
2271  MGRSorUSNGCoordinates* coordinates =
2272  dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2273 
2274  UTMCoordinates* utmCoordinates =
2275  ((MGRS*)(source->coordinateSystem))->convertToUTM( coordinates );
2276  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) =
2277  *dynamic_cast< UTMCoordinates* >( utmCoordinates );
2278  delete utmCoordinates;
2279  }
2280  }
2281  else if ((source->coordinateType == CoordinateType::militaryGridReferenceSystem) &&
2282  (target->coordinateType == CoordinateType::universalPolarStereographic))
2283  {
2284  special = true;
2285 
2286  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2287 
2288  UPSCoordinates* upsCoordinates = ((MGRS*)(source->coordinateSystem))->convertToUPS( coordinates );
2289  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
2290  delete upsCoordinates;
2291  }
2292  else if ((source->coordinateType == CoordinateType::universalTransverseMercator) &&
2293  (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
2294  {
2295  special = true;
2296 
2297  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2298  if (temp_precision < 0)
2299  temp_precision = Precision::degree;
2300  if (temp_precision > 5)
2301  temp_precision = Precision::tenthOfSecond;
2302 
2303  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
2304 
2305  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
2306  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2307  delete mgrsOrUSNGCoordinates;
2308  }
2309  else if ((source->coordinateType == CoordinateType::universalPolarStereographic) && (target->coordinateType == CoordinateType::militaryGridReferenceSystem))
2310  {
2311  special = true;
2312 
2313  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2314  if (temp_precision < 0)
2315  temp_precision = Precision::degree;
2316  if (temp_precision > 5)
2317  temp_precision = Precision::tenthOfSecond;
2318 
2319  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
2320 
2321  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((MGRS*)(target->coordinateSystem))->convertFromUPS( coordinates, temp_precision );
2322  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2323  delete mgrsOrUSNGCoordinates;
2324  }
2325  else if ((source->coordinateType == CoordinateType::usNationalGrid) &&
2326  (target->coordinateType == CoordinateType::universalTransverseMercator) && (target->parameters.utmParameters->override() == 0))
2327  {
2328  special = true;
2329 
2330  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2331 
2332  UTMCoordinates* utmCoordinates = ((USNG*)(source->coordinateSystem))->convertToUTM( coordinates );
2333  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UTMCoordinates* >( utmCoordinates );
2334  delete utmCoordinates;
2335  }
2336  else if ((source->coordinateType == CoordinateType::usNationalGrid) && (target->coordinateType == CoordinateType::universalPolarStereographic))
2337  {
2338  special = true;
2339 
2340  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2341 
2342  UPSCoordinates* upsCoordinates = ((USNG*)(source->coordinateSystem))->convertToUPS( coordinates );
2343  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ) = *dynamic_cast< UPSCoordinates* >( upsCoordinates );
2344  delete upsCoordinates;
2345  }
2346  else if ((source->coordinateType == CoordinateType::universalTransverseMercator) && (target->coordinateType == CoordinateType::usNationalGrid))
2347  {
2348  special = true;
2349 
2350  Precision::Enum temp_precision = ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).precision();
2351  if (temp_precision < 0)
2352  temp_precision = Precision::degree;
2353  if (temp_precision > 5)
2354  temp_precision = Precision::tenthOfSecond;
2355 
2356  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
2357 
2358  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates = ((USNG*)(target->coordinateSystem))->convertFromUTM( coordinates, temp_precision );
2359  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) = *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2360  delete mgrsOrUSNGCoordinates;
2361  }
2362  else if((source->coordinateType == CoordinateType::universalPolarStereographic) &&
2363  (target->coordinateType == CoordinateType::usNationalGrid))
2364  {
2365  special = true;
2366 
2367  Precision::Enum temp_precision =
2368  ( dynamic_cast< MGRSorUSNGCoordinates& >(
2369  targetCoordinates ) ).precision();
2370  if (temp_precision < 0)
2371  temp_precision = Precision::degree;
2372  if (temp_precision > 5)
2373  temp_precision = Precision::tenthOfSecond;
2374 
2375  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >(
2376  sourceCoordinates );
2377 
2378  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates =
2379  ((USNG*)(target->coordinateSystem))->convertFromUPS(
2380  coordinates, temp_precision );
2381  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ) =
2382  *dynamic_cast< MGRSorUSNGCoordinates* >( mgrsOrUSNGCoordinates );
2383  delete mgrsOrUSNGCoordinates;
2384  }
2385  else if ((source->coordinateType == CoordinateType::transverseMercator) &&
2386  (target->coordinateType == CoordinateType::britishNationalGrid))
2387  {
2388  MapProjection5Parameters* param =
2389  source->parameters.mapProjection5Parameters;
2390 
2391  if ((param->centralMeridian() == -2.0 * PI / 180) &&
2392  (param->originLatitude() == 49.0 * PI / 180) &&
2393  (param->scaleFactor() == .9996012717) &&
2394  (param->falseEasting() == 400000.0) &&
2395  (param->falseNorthing() == -100000.0))
2396  {
2397  special = true;
2398 
2399  Precision::Enum temp_precision = ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).precision();
2400  if (temp_precision < 0)
2401  temp_precision = Precision::degree;
2402  if (temp_precision > 5)
2403  temp_precision = Precision::tenthOfSecond;
2404 
2405  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2406 
2407  BNGCoordinates* bngCoordinates =
2408  ((BritishNationalGrid*)(target->coordinateSystem))->
2409  convertFromTransverseMercator( coordinates, temp_precision );
2410  ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ) =
2411  *dynamic_cast< BNGCoordinates* >( bngCoordinates );
2412  delete bngCoordinates;
2413  }
2414  else
2415  special = false;
2416  }
2417  else if((source->coordinateType == CoordinateType::britishNationalGrid) &&
2418  (target->coordinateType == CoordinateType::transverseMercator))
2419  {
2420  MapProjection5Parameters* param =
2421  target->parameters.mapProjection5Parameters;
2422 
2423  if ((param->centralMeridian() == -2.0 * PI / 180) &&
2424  (param->originLatitude() == 49.0 * PI / 180) &&
2425  (param->scaleFactor() == .9996012717) &&
2426  (param->falseEasting() == 400000.0) &&
2427  (param->falseNorthing() == -100000.0))
2428  {
2429  special = true;
2430 
2431  BNGCoordinates* coordinates =
2432  dynamic_cast< BNGCoordinates* >( sourceCoordinates );
2433 
2434  MapProjectionCoordinates* mapProjectionCoordinates =
2435  ((BritishNationalGrid*)(
2436  source->coordinateSystem))->convertToTransverseMercator(
2437  coordinates );
2438  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ) =
2439  *dynamic_cast< MapProjectionCoordinates* >(
2440  mapProjectionCoordinates );
2441  delete mapProjectionCoordinates;
2442  }
2443  else
2444  special = false;
2445  }
2446  }
2448  {
2450  "Input ",
2451  Coordinate_System_Table[source->coordinateType].Name,
2452  ": \n", e.getMessage() );
2453  }
2454 
2455  if( !special )
2456  {
2457  /**********************************************************/
2458  /* First coordinate conversion stage, convert to Geodetic */
2459  /**********************************************************/
2460 
2461  _convertedGeodetic = convertSourceToGeodetic(
2462  sourceDirection, sourceCoordinates, sourceWarningMessage );
2463 
2464  /******************************/
2465  /* Datum Transformation Stage */
2466  /******************************/
2467 
2468  HeightType::Enum input_height_type;
2469  HeightType::Enum output_height_type;
2470 
2471  if (source->coordinateType == CoordinateType::geodetic)
2472  input_height_type = source->parameters.geodeticParameters->heightType();
2473  else if ((source->coordinateType == CoordinateType::geocentric) || (source->coordinateType == CoordinateType::localCartesian))
2474  input_height_type = HeightType::ellipsoidHeight;
2475  else
2476  input_height_type = HeightType::noHeight;
2477 
2478  if (target->coordinateType == CoordinateType::geodetic)
2479  output_height_type = target->parameters.geodeticParameters->heightType();
2480  else if ((target->coordinateType == CoordinateType::geocentric) || (target->coordinateType == CoordinateType::localCartesian))
2481  output_height_type = HeightType::ellipsoidHeight;
2482  else
2483  output_height_type = HeightType::noHeight;
2484 
2485  if ((source->datumIndex == target->datumIndex) &&
2486  ((input_height_type == output_height_type) ||
2487  (input_height_type == HeightType::noHeight) ||
2488  (output_height_type == HeightType::noHeight)))
2489  { /* Copy coordinate tuple */
2490  _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
2491  _shiftedGeodetic = new GeodeticCoordinates( *_convertedGeodetic );
2492 
2493  if ((input_height_type == HeightType::noHeight) ||
2494  (output_height_type == HeightType::noHeight))
2495  {
2496  _shiftedGeodetic->setHeight( 0 );
2497  }
2498 
2499  if(source->datumIndex != WGS84_datum_index &&
2500  target->datumIndex != WGS84_datum_index)
2501  {
2502  long valid = 0;
2503 
2504  /* check source datum validity */
2505  datumLibraryImplementation->validDatum(
2506  source->datumIndex, _wgs84Geodetic->longitude(),
2507  _wgs84Geodetic->latitude(), &valid );
2508  if( !valid )
2509  {
2510  strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
2511  }
2512 
2513  /* check target datum validity */
2514  datumLibraryImplementation->validDatum(
2515  target->datumIndex, _wgs84Geodetic->longitude(),
2516  _wgs84Geodetic->latitude(), &valid );
2517  if( !valid )
2518  {
2519  strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
2520  }
2521  }
2522  }
2523  else
2524  { /* Shift to WGS84, apply geoid correction, shift to target datum */
2525  if (source->datumIndex != WGS84_datum_index)
2526  {
2527  _wgs84Geodetic = datumLibraryImplementation->geodeticShiftToWGS84(
2528  source->datumIndex, _convertedGeodetic );
2529 
2530  switch(input_height_type)
2531  {
2538  _wgs84Geodetic->setHeight( _convertedGeodetic->height() );
2539  break;
2540  case HeightType::noHeight:
2541  _wgs84Geodetic->setHeight( 0.0 );
2542  break;
2544  default:
2545  break;
2546  }
2547 
2548  /* check source datum validity */
2549  long sourceValid = 0;
2550 
2551  datumLibraryImplementation->validDatum(
2552  source->datumIndex, _wgs84Geodetic->longitude(),
2553  _wgs84Geodetic->latitude(), &sourceValid );
2554  if( !sourceValid )
2555  {
2556  strcat( sourceWarningMessage, MSP::CCS::WarningMessages::datum );
2557  }
2558  }
2559  else
2560  { /* Copy coordinate tuple */
2561  _wgs84Geodetic = new GeodeticCoordinates( *_convertedGeodetic );
2562  if( input_height_type == HeightType::noHeight )
2563  _wgs84Geodetic->setHeight( 0.0 );
2564  }
2565 
2566  if(input_height_type != output_height_type)
2567  {
2568  double tempHeight;
2569 
2570  /* Convert the source height value to an ellipsoid height value */
2571  switch(input_height_type)
2572  {
2575  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2576  _wgs84Geodetic->height(), &tempHeight);
2577  break;
2580  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2581  _wgs84Geodetic->height(), &tempHeight);
2582  break;
2585  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2586  _wgs84Geodetic->height(), &tempHeight );
2587  break;
2590  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2591  _wgs84Geodetic->height(), &tempHeight );
2592  break;
2595  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2596  _wgs84Geodetic->height(), &tempHeight );
2597  break;
2600  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2601  _wgs84Geodetic->height(), &tempHeight );
2602  break;
2604  default:
2605  tempHeight = _wgs84Geodetic->height();
2606  break;
2607  }
2608 
2609  double correctedHeight;
2610 
2611  /* Convert the ellipsoid height value to the target height value */
2612  switch(output_height_type)
2613  {
2616  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2617  tempHeight, &correctedHeight );
2618  break;
2621  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2622  tempHeight, &correctedHeight );
2623  break;
2626  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2627  tempHeight, &correctedHeight );
2628  break;
2631  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2632  tempHeight, &correctedHeight );
2633  break;
2636  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2637  tempHeight, &correctedHeight );
2638  break;
2641  _wgs84Geodetic->longitude(), _wgs84Geodetic->latitude(),
2642  tempHeight, &correctedHeight );
2643  break;
2645  default:
2646  correctedHeight = tempHeight;
2647  break;
2648  }
2649 
2650  /* Set the target height */
2651  _wgs84Geodetic->setHeight( correctedHeight );
2652  }
2653 
2654  if (target->datumIndex != WGS84_datum_index)
2655  {
2656  _shiftedGeodetic =
2657  datumLibraryImplementation->geodeticShiftFromWGS84(
2658  _wgs84Geodetic, target->datumIndex );
2659 
2660  switch(output_height_type)
2661  {
2668  _shiftedGeodetic->setHeight( _wgs84Geodetic->height() );
2669  break;
2670  case HeightType::noHeight:
2671  _shiftedGeodetic->setHeight( 0.0 );
2672  break;
2674  default:
2675  break;
2676  }
2677 
2678  /* check target datum validity */
2679  long targetValid = 0;
2680 
2681  datumLibraryImplementation->validDatum(
2682  target->datumIndex, _wgs84Geodetic->longitude(),
2683  _wgs84Geodetic->latitude(), &targetValid );
2684  if( !targetValid )
2685  {
2686  strcat( targetWarningMessage, MSP::CCS::WarningMessages::datum );
2687  }
2688  }
2689  else
2690  { /* Copy coordinate tuple */
2691  _shiftedGeodetic = new GeodeticCoordinates( *_wgs84Geodetic );
2692  if( output_height_type == HeightType::noHeight )
2693  _shiftedGeodetic->setHeight( 0.0 );
2694  }
2695  }
2696 
2697  /* calculate conversion errors */
2698  if( strlen( sourceWarningMessage ) > 0 ||
2699  strlen( targetWarningMessage ) > 0 )
2700  targetAccuracy.set(-1.0, -1.0, -1.0);
2701  else
2702  {
2703  Precision::Enum precS = sourceCoordinates->precision();
2704  Precision::Enum precT = targetCoordinates.precision();
2705  Precision::Enum prec = precS;
2706  if( precT < prec )
2707  {
2708  prec = precT;
2709  }
2710 
2711  Accuracy* _targetAccuracy =
2712  datumLibraryImplementation->datumShiftError(
2713  source->datumIndex, target->datumIndex,
2714  _wgs84Geodetic->longitude(),
2715  _wgs84Geodetic->latitude(), sourceAccuracy, prec );
2716 
2717  targetAccuracy.set(
2718  _targetAccuracy->circularError90(),
2719  _targetAccuracy->linearError90(),
2720  _targetAccuracy->sphericalError90() );
2721 
2722  delete _targetAccuracy;
2723  }
2724 
2725  /*************************************************************/
2726  /* Second coordinate conversion stage, convert from Geodetic */
2727  /*************************************************************/
2728 
2729  convertGeodeticToTarget(
2730  targetDirection, _shiftedGeodetic,
2731  targetCoordinates, targetWarningMessage );
2732 
2733  // Format and set the warning message in the target coordinates
2734  char warningMessage[500] = "";
2735  bool warning = false;
2736  if( strlen( sourceWarningMessage ) > 0 )
2737  {
2738  strcpy( warningMessage, "Input " );
2739  strcat( warningMessage,
2740  Coordinate_System_Table[source->coordinateType].Name );
2741  strcat( warningMessage, ": \n" );
2742  strcat( warningMessage, sourceWarningMessage );
2743  warning = true;
2744  }
2745 
2746  if( strlen( targetWarningMessage ) > 0 )
2747  {
2748  if( strlen( warningMessage ) > 0 )
2749  strcat( warningMessage, "\nOutput " );
2750  else
2751  strcpy( warningMessage, "Output " );
2752 
2753  strcat( warningMessage,
2754  Coordinate_System_Table[target->coordinateType].Name );
2755  strcat( warningMessage, ": \n" );
2756  strcat( warningMessage, targetWarningMessage );
2757  warning = true;
2758  }
2759 
2760  if( warning )
2761  {
2762  warningMessage[strlen( warningMessage )] = '\0';
2763  targetCoordinates.setWarningMessage(warningMessage);
2764  }
2765  } /* if (!special) */
2766  }
2768  {
2769  targetAccuracy.set(-1.0, -1.0, -1.0);
2770 
2771  /* since initialized to 0 at the top is safe to
2772  cleanup memory before rethrowing the exception */
2773  delete _convertedGeodetic;
2774  delete _shiftedGeodetic;
2775  delete _wgs84Geodetic;
2776 
2778  }
2779 
2780  // cleanup memory before returning
2781  delete _convertedGeodetic;
2782  delete _shiftedGeodetic;
2783  delete _wgs84Geodetic;
2784 
2785 }
2786 
2787 
2788 GeodeticCoordinates* CoordinateConversionService::convertSourceToGeodetic(
2789  SourceOrTarget::Enum sourceDirection,
2790  CoordinateTuple* sourceCoordinates,
2791  char* sourceWarningMessage )
2792 {
2793  Coordinate_State_Row* source = &coordinateSystemState[sourceDirection];
2794 
2795  /**********************************************************/
2796  /* First coordinate conversion stage, convert to Geodetic */
2797  /**********************************************************/
2798  try
2799  {
2800  switch (source->coordinateType)
2801  {
2803  {
2804  CartesianCoordinates* coordinates =
2805  dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2806 
2807  return ((Geocentric*)(source->coordinateSystem))->convertToGeodetic(
2808  coordinates );
2809  }
2811  {
2812  GeodeticCoordinates* _convertedGeodetic =
2813  new GeodeticCoordinates(
2814  *dynamic_cast< GeodeticCoordinates* >( sourceCoordinates ) );
2815 
2816  if( source->parameters.geodeticParameters->heightType() == HeightType::noHeight )
2817  _convertedGeodetic->setHeight( 0.0 );
2818 
2819  return _convertedGeodetic;
2820  }
2822  {
2823  GEOREFCoordinates* coordinates = dynamic_cast< GEOREFCoordinates* >(
2824  sourceCoordinates );
2825 
2826  return ((GEOREF*)(source->coordinateSystem))->convertToGeodetic(
2827  coordinates );
2828  }
2830  {
2831  MapProjectionCoordinates* coordinates =
2832  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2833 
2834  return ((AlbersEqualAreaConic*)(
2835  source->coordinateSystem))->convertToGeodetic( coordinates );
2836  }
2838  {
2839  MapProjectionCoordinates* coordinates =
2840  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2841 
2842  return ((AzimuthalEquidistant*)(
2843  source->coordinateSystem))->convertToGeodetic( coordinates );
2844  }
2846  {
2847  BNGCoordinates* coordinates = dynamic_cast< BNGCoordinates* >( sourceCoordinates );
2848 
2849  return ((BritishNationalGrid*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2850  }
2851  case CoordinateType::bonne:
2852  {
2853  MapProjectionCoordinates* coordinates =
2854  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2855 
2856  return ((Bonne*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2857  }
2859  {
2860  MapProjectionCoordinates* coordinates =
2861  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2862 
2863  GeodeticCoordinates* _convertedGeodetic =
2864  ((Cassini*)(source->coordinateSystem))->convertToGeodetic(
2865  coordinates );
2866 
2867  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2868  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2869 
2870  return _convertedGeodetic;
2871  }
2873  {
2874  MapProjectionCoordinates* coordinates =
2875  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2876 
2877  return ((CylindricalEqualArea*)(
2878  source->coordinateSystem))->convertToGeodetic( coordinates);
2879  }
2881  {
2882  MapProjectionCoordinates* coordinates =
2883  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2884 
2885  return ((Eckert4*)(source->coordinateSystem))->convertToGeodetic(
2886  coordinates );
2887  }
2889  {
2890  MapProjectionCoordinates* coordinates =
2891  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2892 
2893  return ((Eckert6*)(source->coordinateSystem))->convertToGeodetic(
2894  coordinates );
2895  }
2897  {
2898  MapProjectionCoordinates* coordinates =
2899  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2900 
2901  return ((EquidistantCylindrical*)(
2902  source->coordinateSystem))->convertToGeodetic( coordinates );
2903  }
2905  {
2906  GARSCoordinates* coordinates = dynamic_cast< GARSCoordinates* >( sourceCoordinates );
2907 
2908  return ((GARS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2909  }
2911  {
2912  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2913 
2914  return ((Gnomonic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2915  }
2917  {
2918  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2919 
2920  return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2921  }
2923  {
2924  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2925 
2926  return ((LambertConformalConic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2927  }
2929  {
2930  CartesianCoordinates* coordinates = dynamic_cast< CartesianCoordinates* >( sourceCoordinates );
2931 
2932  return ((LocalCartesian*)(source->coordinateSystem))->convertToGeodetic( coordinates);
2933  }
2936  {
2937  MapProjectionCoordinates* coordinates =
2938  dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2939 
2940  return ((Mercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2941  }
2943  {
2944  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
2945 
2946  GeodeticCoordinates* _convertedGeodetic = ((MGRS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2947 
2948  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2949  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2950 
2951  return _convertedGeodetic;
2952  }
2954  {
2955  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2956 
2957  return ((MillerCylindrical*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2958  }
2960  {
2961  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2962 
2963  return ((Mollweide*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2964  }
2965  case CoordinateType::neys:
2966  {
2967  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2968 
2969  return ((Neys*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2970  }
2972  {
2973  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2974 
2975  return ((NZMG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2976  }
2978  {
2979  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2980 
2981  GeodeticCoordinates* _convertedGeodetic = ((ObliqueMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2982 
2983  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
2984  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
2985 
2986  return _convertedGeodetic;
2987  }
2989  {
2990  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2991 
2992  return ((Orthographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
2993  }
2996  {
2997  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
2998 
2999  return ((PolarStereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3000  }
3002  {
3003  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3004 
3005  return ((Polyconic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3006  }
3008  {
3009  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3010 
3011  return ((Sinusoidal*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3012  }
3014  {
3015  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3016 
3017  return ((Stereographic*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3018  }
3020  {
3021  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3022 
3023  return ((TransverseCylindricalEqualArea*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3024  }
3026  {
3027  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3028 
3029  GeodeticCoordinates* _convertedGeodetic = ((TransverseMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3030 
3031  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
3032  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
3033 
3034  return _convertedGeodetic;
3035  }
3037  {
3038  UPSCoordinates* coordinates = dynamic_cast< UPSCoordinates* >( sourceCoordinates );
3039 
3040  return ((UPS*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3041  }
3043  {
3044  MGRSorUSNGCoordinates* coordinates = dynamic_cast< MGRSorUSNGCoordinates* >( sourceCoordinates );
3045 
3046  GeodeticCoordinates* _convertedGeodetic = ((USNG*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3047 
3048  if( strlen( _convertedGeodetic->warningMessage() ) > 0)
3049  strcat( sourceWarningMessage, _convertedGeodetic->warningMessage() );
3050 
3051  return _convertedGeodetic;
3052  }
3054  {
3055  UTMCoordinates* coordinates = dynamic_cast< UTMCoordinates* >( sourceCoordinates );
3056 
3057  return ((UTM*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3058  }
3060  {
3061  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3062 
3063  return ((VanDerGrinten*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3064  }
3066  {
3067  MapProjectionCoordinates* coordinates = dynamic_cast< MapProjectionCoordinates* >( sourceCoordinates );
3068 
3069  return ((WebMercator*)(source->coordinateSystem))->convertToGeodetic( coordinates );
3070  }
3071  }
3072  }
3074  {
3076  "Input ", Coordinate_System_Table[source->coordinateType].Name,
3077  ": \n", e.getMessage() );
3078  }
3079 }
3080 
3081 
3082 void CoordinateConversionService::convertGeodeticToTarget(
3083  SourceOrTarget::Enum targetDirection,
3084  GeodeticCoordinates* _shiftedGeodetic,
3085  CoordinateTuple& targetCoordinates,
3086  char* targetWarningMessage )
3087 {
3088  Coordinate_State_Row* target = &coordinateSystemState[targetDirection];
3089 
3090  /*************************************************************/
3091  /* Second coordinate conversion stage, convert from Geodetic */
3092  /*************************************************************/
3093  try
3094  {
3095  switch (target->coordinateType)
3096  {
3098  {
3099  CartesianCoordinates* coordinates =
3100  ((Geocentric*)(target->coordinateSystem))->convertFromGeodetic(
3101  _shiftedGeodetic );
3102 
3103  ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set(
3104  coordinates->x(), coordinates->y(), coordinates->z() );
3105 
3106  delete coordinates;
3107 
3108  break;
3109  }
3111  {
3112  if (target->parameters.geodeticParameters->heightType() == HeightType::noHeight)
3113  ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set(
3114  _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(), 0.0 );
3115  else
3116  ( dynamic_cast< GeodeticCoordinates& >( targetCoordinates ) ).set(
3117  _shiftedGeodetic->longitude(), _shiftedGeodetic->latitude(),
3118  _shiftedGeodetic->height() );
3119 
3120  break;
3121  }
3123  {
3124  Precision::Enum temp_precision =
3125  ( dynamic_cast< GEOREFCoordinates& >(
3126  targetCoordinates ) ).precision();
3127  if (temp_precision < 0)
3128  temp_precision = Precision::degree;
3129  if (temp_precision > 5)
3130  temp_precision = Precision::tenthOfSecond;
3131 
3132  GEOREFCoordinates* coordinates =
3133  ((GEOREF*)(target->coordinateSystem))->convertFromGeodetic(
3134  _shiftedGeodetic, temp_precision );
3135 
3136  ( dynamic_cast< GEOREFCoordinates& >( targetCoordinates ) ).set(
3137  coordinates->GEOREFString() );
3138 
3139  delete coordinates;
3140 
3141  break;
3142  }
3144  {
3145  MapProjectionCoordinates* coordinates =
3147  target->coordinateSystem))->convertFromGeodetic(
3148  _shiftedGeodetic );
3149 
3150  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3151  coordinates->easting(), coordinates->northing() );
3152 
3153  delete coordinates;
3154 
3155  break;
3156  }
3158  {
3159  MapProjectionCoordinates* coordinates =
3161  target->coordinateSystem))->convertFromGeodetic(
3162  _shiftedGeodetic );
3163 
3164  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3165  coordinates->easting(), coordinates->northing() );
3166 
3167  delete coordinates;
3168 
3169  break;
3170  }
3172  {
3173  Precision::Enum temp_precision =
3174  ( dynamic_cast< BNGCoordinates& >(targetCoordinates ) ).precision();
3175  if (temp_precision < 0)
3176  temp_precision = Precision::degree;
3177  if (temp_precision > 5)
3178  temp_precision = Precision::tenthOfSecond;
3179 
3180  BNGCoordinates* coordinates =
3181  ((BritishNationalGrid*)(
3182  target->coordinateSystem))->convertFromGeodetic(
3183  _shiftedGeodetic, temp_precision );
3184 
3185  ( dynamic_cast< BNGCoordinates& >( targetCoordinates ) ).set(
3186  coordinates->BNGString() );
3187 
3188  delete coordinates;
3189 
3190  break;
3191  }
3192  case CoordinateType::bonne:
3193  {
3194  MapProjectionCoordinates* coordinates =
3195  ((Bonne*)(target->coordinateSystem))->convertFromGeodetic(
3196  _shiftedGeodetic );
3197 
3198  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3199  coordinates->easting(), coordinates->northing() );
3200 
3201  delete coordinates;
3202 
3203  break;
3204  }
3206  {
3207  MapProjectionCoordinates* coordinates =
3208  ((Cassini*)(target->coordinateSystem))->convertFromGeodetic(
3209  _shiftedGeodetic );
3210 
3211  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3212  coordinates->easting(), coordinates->northing() );
3213 
3214  if( strlen( coordinates->warningMessage() ) > 0)
3215  {
3216  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3217  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3218  }
3219 
3220  delete coordinates;
3221 
3222  break;
3223  }
3225  {
3226  MapProjectionCoordinates* coordinates =
3228  target->coordinateSystem))->convertFromGeodetic(
3229  _shiftedGeodetic );
3230 
3231  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3232  coordinates->easting(), coordinates->northing() );
3233 
3234  delete coordinates;
3235 
3236  break;
3237  }
3239  {
3240  MapProjectionCoordinates* coordinates =
3241  ((Eckert4*)(target->coordinateSystem))->convertFromGeodetic(
3242  _shiftedGeodetic );
3243 
3244  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3245  coordinates->easting(), coordinates->northing() );
3246 
3247  delete coordinates;
3248 
3249  break;
3250  }
3252  {
3253  MapProjectionCoordinates* coordinates =
3254  ((Eckert6*)(target->coordinateSystem))->convertFromGeodetic(
3255  _shiftedGeodetic );
3256 
3257  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3258  coordinates->easting(), coordinates->northing() );
3259 
3260  delete coordinates;
3261 
3262  break;
3263  }
3265  {
3266  MapProjectionCoordinates* coordinates =
3268  target->coordinateSystem))->convertFromGeodetic(
3269  _shiftedGeodetic );
3270 
3271  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3272  coordinates->easting(), coordinates->northing() );
3273 
3274  delete coordinates;
3275 
3276  break;
3277  }
3279  {
3280  Precision::Enum temp_precision =
3281  (dynamic_cast< GARSCoordinates& >( targetCoordinates )).precision();
3282  if (temp_precision < 0)
3283  temp_precision = Precision::degree;
3284  if (temp_precision > 5)
3285  temp_precision = Precision::tenthOfSecond;
3286 
3287  GARSCoordinates* coordinates =
3288  ((GARS*)(target->coordinateSystem))->convertFromGeodetic(
3289  _shiftedGeodetic, temp_precision );
3290 
3291  ( dynamic_cast< GARSCoordinates& >( targetCoordinates ) ).set(
3292  coordinates->GARSString() );
3293 
3294  delete coordinates;
3295 
3296  break;
3297  }
3299  {
3300  MapProjectionCoordinates* coordinates =
3301  ((Gnomonic*)(target->coordinateSystem))->convertFromGeodetic(
3302  _shiftedGeodetic );
3303 
3304  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3305  coordinates->easting(), coordinates->northing() );
3306 
3307  delete coordinates;
3308 
3309  break;
3310  }
3312  {
3313  MapProjectionCoordinates* coordinates =
3315  target->coordinateSystem))->convertFromGeodetic(
3316  _shiftedGeodetic );
3317 
3318  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3319  coordinates->easting(), coordinates->northing() );
3320 
3321  delete coordinates;
3322 
3323  break;
3324  }
3326  {
3327  MapProjectionCoordinates* coordinates =
3329  target->coordinateSystem))->convertFromGeodetic(
3330  _shiftedGeodetic );
3331 
3332  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3333  coordinates->easting(), coordinates->northing() );
3334 
3335  delete coordinates;
3336 
3337  break;
3338  }
3340  {
3341  CartesianCoordinates* coordinates =
3342  ((LocalCartesian*)(target->coordinateSystem))->convertFromGeodetic(
3343  _shiftedGeodetic );
3344 
3345  ( dynamic_cast< CartesianCoordinates& >( targetCoordinates ) ).set(
3346  coordinates->x(), coordinates->y(), coordinates->z() );
3347 
3348  delete coordinates;
3349 
3350  break;
3351  }
3354  {
3355  MapProjectionCoordinates* coordinates =
3356  ((Mercator*)(target->coordinateSystem))->convertFromGeodetic(
3357  _shiftedGeodetic );
3358 
3359  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3360  coordinates->easting(), coordinates->northing() );
3361 
3362  delete coordinates;
3363 
3364  break;
3365  }
3367  {
3368  Precision::Enum temp_precision =
3369  ( dynamic_cast< MGRSorUSNGCoordinates& >(
3370  targetCoordinates ) ).precision();
3371 
3372  if (temp_precision < 0)
3373  temp_precision = Precision::degree;
3374  if (temp_precision > 5)
3375  temp_precision = Precision::tenthOfSecond;
3376  MGRSorUSNGCoordinates* coordinates =
3377  ((MGRS*)(target->coordinateSystem))->convertFromGeodetic(
3378  _shiftedGeodetic, temp_precision );
3379 
3380  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set(
3381  coordinates->MGRSString() );
3382 
3383  delete coordinates;
3384 
3385  break;
3386  }
3388  {
3389  MapProjectionCoordinates* coordinates =
3390  ((MillerCylindrical*)(
3391  target->coordinateSystem))->convertFromGeodetic(
3392  _shiftedGeodetic );
3393 
3394  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3395  coordinates->easting(), coordinates->northing() );
3396 
3397  delete coordinates;
3398 
3399  break;
3400  }
3402  {
3403  MapProjectionCoordinates* coordinates =
3404  ((Mollweide*)(target->coordinateSystem))->convertFromGeodetic(
3405  _shiftedGeodetic );
3406 
3407  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3408  coordinates->easting(), coordinates->northing() );
3409 
3410  delete coordinates;
3411 
3412  break;
3413  }
3414  case CoordinateType::neys:
3415  {
3416  MapProjectionCoordinates* coordinates =
3417  ((Neys*)(target->coordinateSystem))->convertFromGeodetic(
3418  _shiftedGeodetic );
3419 
3420  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3421  coordinates->easting(), coordinates->northing() );
3422 
3423  delete coordinates;
3424 
3425  break;
3426  }
3428  {
3429  MapProjectionCoordinates* coordinates =
3430  ((NZMG*)(target->coordinateSystem))->convertFromGeodetic(
3431  _shiftedGeodetic );
3432 
3433  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3434  coordinates->easting(), coordinates->northing() );
3435 
3436  delete coordinates;
3437 
3438  break;
3439  }
3441  {
3442  MapProjectionCoordinates* coordinates =
3443  ((ObliqueMercator*)(target->coordinateSystem))->convertFromGeodetic(
3444  _shiftedGeodetic );
3445 
3446  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3447  coordinates->easting(), coordinates->northing() );
3448 
3449  if( strlen( coordinates->warningMessage() ) > 0)
3450  {
3451  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3452  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3453  }
3454 
3455  delete coordinates;
3456 
3457  break;
3458  }
3460  {
3461  MapProjectionCoordinates* coordinates =
3462  ((Orthographic*)(target->coordinateSystem))->convertFromGeodetic(
3463  _shiftedGeodetic );
3464 
3465  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3466  coordinates->easting(), coordinates->northing() );
3467 
3468  delete coordinates;
3469 
3470  break;
3471  }
3474  {
3475  MapProjectionCoordinates* coordinates =
3476  ((PolarStereographic*)(
3477  target->coordinateSystem))->convertFromGeodetic(
3478  _shiftedGeodetic );
3479 
3480  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3481  coordinates->easting(), coordinates->northing() );
3482 
3483  delete coordinates;
3484 
3485  break;
3486  }
3488  {
3489  MapProjectionCoordinates* coordinates =
3490  ((Polyconic*)(target->coordinateSystem))->convertFromGeodetic(
3491  _shiftedGeodetic );
3492 
3493  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3494  coordinates->easting(), coordinates->northing() );
3495 
3496  if( strlen( coordinates->warningMessage() ) > 0)
3497  {
3498  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3499  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3500  }
3501 
3502  delete coordinates;
3503 
3504  break;
3505  }
3507  {
3508  MapProjectionCoordinates* coordinates =
3509  ((Sinusoidal*)(target->coordinateSystem))->convertFromGeodetic(
3510  _shiftedGeodetic );
3511 
3512  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3513  coordinates->easting(), coordinates->northing() );
3514 
3515  delete coordinates;
3516 
3517  break;
3518  }
3520  {
3521  MapProjectionCoordinates* coordinates =
3522  ((Stereographic*)(target->coordinateSystem))->convertFromGeodetic(
3523  _shiftedGeodetic );
3524 
3525  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3526  coordinates->easting(), coordinates->northing() );
3527 
3528  delete coordinates;
3529 
3530  break;
3531  }
3533  {
3534  MapProjectionCoordinates* coordinates =
3536  target->coordinateSystem))->convertFromGeodetic(
3537  _shiftedGeodetic );
3538 
3539  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3540  coordinates->easting(), coordinates->northing() );
3541 
3542  if( strlen( coordinates->warningMessage() ) > 0)
3543  {
3544  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3545  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3546  }
3547 
3548  delete coordinates;
3549 
3550  break;
3551  }
3553  {
3554  MapProjectionCoordinates* coordinates =
3555  ((TransverseMercator*)(
3556  target->coordinateSystem))->convertFromGeodetic(
3557  _shiftedGeodetic );
3558 
3559  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3560  coordinates->easting(), coordinates->northing() );
3561 
3562  if( strlen( coordinates->warningMessage() ) > 0)
3563  {
3564  targetCoordinates.setWarningMessage( coordinates->warningMessage() );
3565  strcat( targetWarningMessage, targetCoordinates.warningMessage() );
3566  }
3567 
3568  delete coordinates;
3569 
3570  break;
3571  }
3573  {
3574  UPSCoordinates* coordinates =
3575  ((UPS*)(target->coordinateSystem))->convertFromGeodetic(
3576  _shiftedGeodetic );
3577 
3578  ( dynamic_cast< UPSCoordinates& >( targetCoordinates ) ).set(
3579  coordinates->hemisphere(),
3580  coordinates->easting(),
3581  coordinates->northing() );
3582 
3583  delete coordinates;
3584 
3585  break;
3586  }
3588  {
3589  Precision::Enum temp_precision =
3590  ( dynamic_cast< MGRSorUSNGCoordinates& >(
3591  targetCoordinates ) ).precision();
3592  if (temp_precision < 0)
3593  temp_precision = Precision::degree;
3594  if (temp_precision > 5)
3595  temp_precision = Precision::tenthOfSecond;
3596 
3597  MGRSorUSNGCoordinates* coordinates =
3598  ((USNG*)(target->coordinateSystem))->convertFromGeodetic(
3599  _shiftedGeodetic, temp_precision );
3600 
3601  ( dynamic_cast< MGRSorUSNGCoordinates& >( targetCoordinates ) ).set(
3602  coordinates->MGRSString() );
3603 
3604  delete coordinates;
3605 
3606  break;
3607  }
3609  {
3610  UTMCoordinates* coordinates =
3611  ((UTM*)(target->coordinateSystem))->convertFromGeodetic(
3612  _shiftedGeodetic );
3613 
3614  ( dynamic_cast< UTMCoordinates& >( targetCoordinates ) ).set(
3615  coordinates->zone(), coordinates->hemisphere(),
3616  coordinates->easting(), coordinates->northing() );
3617 
3618  delete coordinates;
3619 
3620  break;
3621  }
3623  {
3624  MapProjectionCoordinates* coordinates =
3625  ((VanDerGrinten*)(target->coordinateSystem))->convertFromGeodetic(
3626  _shiftedGeodetic );
3627 
3628  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3629  coordinates->easting(), coordinates->northing() );
3630 
3631  delete coordinates;
3632 
3633  break;
3634  }
3636  {
3637  MapProjectionCoordinates* coordinates =
3638  ((WebMercator*)(target->coordinateSystem))->convertFromGeodetic(
3639  _shiftedGeodetic );
3640 
3641  ( dynamic_cast< MapProjectionCoordinates& >( targetCoordinates ) ).set(
3642  coordinates->easting(), coordinates->northing() );
3643 
3644  delete coordinates;
3645 
3646  break;
3647  }
3648  } /* switch (target->coordinateType) */
3649  }
3651  {
3653  "Output ", Coordinate_System_Table[target->coordinateType].Name,
3654  ": \n", e.getMessage() );
3655  }
3656 }
3657 
3658 
3659 void CoordinateConversionService::convertCollection(
3660  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinatesCollection,
3661  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection,
3662  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinatesCollection,
3663  std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection )
3664 {
3665 /*
3666  * The function convertCollection will convert a list of source coordinates
3667  * to a list of target coordinates in a single step.
3668  *
3669  * sourceCoordinatesCollection : Coordinates to be converted (input)
3670  * sourceAccuracyCollection : Source circular/linear/spherical errors (input)
3671  * targetCoordinatesCollection : Converted coordinates (output)
3672  * targetAccuracyCollection : Target circular/linear/spherical errors (output)
3673  */
3674 
3675  int num = sourceCoordinatesCollection.size();
3676  int numTargetCoordinates = targetCoordinatesCollection.size();
3677  int numTargetAccuracies = targetAccuracyCollection.size();
3678  CoordinateType::Enum targetCoordinateType =
3679  coordinateSystemState[SourceOrTarget::target].coordinateType;
3680 
3681  CoordinateTuple* _targetCoordinates = 0;
3682  Accuracy* _targetAccuracy;
3683 
3684  for( int i = 0; i < num; i++ )
3685  {
3686  CoordinateTuple* _sourceCoordinates = sourceCoordinatesCollection[i];
3687  Accuracy* _sourceAccuracy = sourceAccuracyCollection[i];
3688 
3689  bool targetCoordinateExists = true;
3690  bool targetAccuracyExists = true;
3691 
3692  if(i < numTargetAccuracies)
3693  _targetAccuracy = targetAccuracyCollection[i];
3694  else
3695  {
3696  _targetAccuracy = new Accuracy();
3697  targetAccuracyExists = false;
3698  }
3699 
3700  if( _sourceCoordinates && _sourceAccuracy )
3701  {
3702  switch(targetCoordinateType)
3703  {
3705  {
3706  if(i < numTargetCoordinates)
3707  _targetCoordinates = targetCoordinatesCollection[i];
3708  else
3709  {
3710  _targetCoordinates = new MapProjectionCoordinates(
3712  targetCoordinateExists = false;
3713  }
3714  try
3715  {
3716  convert(
3719  sourceCoordinatesCollection[i],
3720  sourceAccuracyCollection[i],
3721  *_targetCoordinates, *_targetAccuracy);
3722  }
3724  {
3725  _targetCoordinates->setErrorMessage(e.getMessage());
3726  }
3727 
3728  if(!targetCoordinateExists)
3729  targetCoordinatesCollection.push_back(_targetCoordinates);
3730  break;
3731  }
3733  {
3734  if(i < numTargetCoordinates)
3735  _targetCoordinates = targetCoordinatesCollection[i];
3736  else
3737  {
3738  _targetCoordinates = new MapProjectionCoordinates(
3740  targetCoordinateExists = false;
3741  }
3742  try
3743  {
3744  convert(
3747  sourceCoordinatesCollection[i],
3748  sourceAccuracyCollection[i],
3749  *_targetCoordinates, *_targetAccuracy);
3750  }
3752  {
3753  _targetCoordinates->setErrorMessage(e.getMessage());
3754  }
3755 
3756  if(!targetCoordinateExists)
3757  targetCoordinatesCollection.push_back(_targetCoordinates);
3758  break;
3759  }
3760  case CoordinateType::bonne:
3761  {
3762  if(i < numTargetCoordinates)
3763  _targetCoordinates = targetCoordinatesCollection[i];
3764  else
3765  {
3766  _targetCoordinates = new MapProjectionCoordinates(
3768  targetCoordinateExists = false;
3769  }
3770  try
3771  {
3772  convert(
3775  sourceCoordinatesCollection[i],
3776  sourceAccuracyCollection[i],
3777  *_targetCoordinates, *_targetAccuracy);
3778  }
3780  {
3781  _targetCoordinates->setErrorMessage(e.getMessage());
3782  }
3783 
3784  if(!targetCoordinateExists)
3785  targetCoordinatesCollection.push_back(_targetCoordinates);
3786  break;
3787  }
3789  {
3790  if(i < numTargetCoordinates)
3791  _targetCoordinates = targetCoordinatesCollection[i];
3792  else
3793  {
3794  _targetCoordinates = new BNGCoordinates(
3796  targetCoordinateExists = false;
3797  }
3798  try
3799  {
3800  convert(
3803  sourceCoordinatesCollection[i],
3804  sourceAccuracyCollection[i],
3805  *_targetCoordinates, *_targetAccuracy);
3806  }
3808  {
3809  _targetCoordinates->setErrorMessage(e.getMessage());
3810  }
3811 
3812  if(!targetCoordinateExists)
3813  targetCoordinatesCollection.push_back(_targetCoordinates);
3814  break;
3815  }
3817  {
3818  if(i < numTargetCoordinates)
3819  _targetCoordinates = targetCoordinatesCollection[i];
3820  else
3821  {
3822  _targetCoordinates = new MapProjectionCoordinates(
3824  targetCoordinateExists = false;
3825  }
3826  try
3827  {
3828  convert(
3831  sourceCoordinatesCollection[i],
3832  sourceAccuracyCollection[i],
3833  *_targetCoordinates, *_targetAccuracy);
3834  }
3836  {
3837  _targetCoordinates->setErrorMessage(e.getMessage());
3838  }
3839 
3840  if(!targetCoordinateExists)
3841  targetCoordinatesCollection.push_back(_targetCoordinates);
3842  break;
3843  }
3845  {
3846  if(i < numTargetCoordinates)
3847  _targetCoordinates = targetCoordinatesCollection[i];
3848  else
3849  {
3850  _targetCoordinates = new MapProjectionCoordinates(
3852  targetCoordinateExists = false;
3853  }
3854  try
3855  {
3856  convert(
3859  sourceCoordinatesCollection[i],
3860  sourceAccuracyCollection[i],
3861  *_targetCoordinates, *_targetAccuracy);
3862  }
3864  {
3865  _targetCoordinates->setErrorMessage(e.getMessage());
3866  }
3867 
3868  if(!targetCoordinateExists)
3869  targetCoordinatesCollection.push_back(_targetCoordinates);
3870  break;
3871  }
3873  {
3874  if(i < numTargetCoordinates)
3875  _targetCoordinates = targetCoordinatesCollection[i];
3876  else
3877  {
3878  _targetCoordinates = new MapProjectionCoordinates(
3880  targetCoordinateExists = false;
3881  }
3882  try
3883  {
3884  convert(
3887  sourceCoordinatesCollection[i],
3888  sourceAccuracyCollection[i],
3889  *_targetCoordinates, *_targetAccuracy);
3890  }
3892  {
3893  _targetCoordinates->setErrorMessage(e.getMessage());
3894  }
3895 
3896  if(!targetCoordinateExists)
3897  targetCoordinatesCollection.push_back(_targetCoordinates);
3898  break;
3899  }
3901  {
3902  if(i < numTargetCoordinates)
3903  _targetCoordinates = targetCoordinatesCollection[i];
3904  else
3905  {
3906  _targetCoordinates = new MapProjectionCoordinates(
3908  targetCoordinateExists = false;
3909  }
3910  try
3911  {
3912  convert(
3915  sourceCoordinatesCollection[i],
3916  sourceAccuracyCollection[i],
3917  *_targetCoordinates, *_targetAccuracy);
3918  }
3920  {
3921  _targetCoordinates->setErrorMessage(e.getMessage());
3922  }
3923 
3924  if(!targetCoordinateExists)
3925  targetCoordinatesCollection.push_back(_targetCoordinates);
3926  break;
3927  }
3929  {
3930  if(i < numTargetCoordinates)
3931  _targetCoordinates = targetCoordinatesCollection[i];
3932  else
3933  {
3934  _targetCoordinates = new MapProjectionCoordinates(
3936  targetCoordinateExists = false;
3937  }
3938  try
3939  {
3940  convert(
3943  sourceCoordinatesCollection[i],
3944  sourceAccuracyCollection[i],
3945  *_targetCoordinates, *_targetAccuracy);
3946  }
3948  {
3949  _targetCoordinates->setErrorMessage(e.getMessage());
3950  }
3951 
3952  if(!targetCoordinateExists)
3953  targetCoordinatesCollection.push_back(_targetCoordinates);
3954  break;
3955  }
3957  {
3958  if(i < numTargetCoordinates)
3959  _targetCoordinates = targetCoordinatesCollection[i];
3960  else
3961  {
3962  _targetCoordinates = new CartesianCoordinates(
3964  targetCoordinateExists = false;
3965  }
3966  try
3967  {
3968  convert(
3970  sourceCoordinatesCollection[i], sourceAccuracyCollection[i],
3971  *_targetCoordinates, *_targetAccuracy);
3972  }
3974  {
3975  _targetCoordinates->setErrorMessage(e.getMessage());
3976  }
3977 
3978  if(!targetCoordinateExists)
3979  targetCoordinatesCollection.push_back(_targetCoordinates);
3980  break;
3981  }
3983  {
3984  if(i < numTargetCoordinates)
3985  _targetCoordinates = targetCoordinatesCollection[i];
3986  else
3987  {
3988  _targetCoordinates = new GeodeticCoordinates(
3990  targetCoordinateExists = false;
3991  }
3992  try
3993  {
3994  convert(
3996  sourceCoordinatesCollection[i], sourceAccuracyCollection[i],
3997  *_targetCoordinates, *_targetAccuracy);
3998  }
4000  {
4001  _targetCoordinates->setErrorMessage(e.getMessage());
4002  }
4003 
4004  if(!targetCoordinateExists)
4005  targetCoordinatesCollection.push_back(_targetCoordinates);
4006  break;
4007  }
4009  {
4010  if(i < numTargetCoordinates)
4011  _targetCoordinates = targetCoordinatesCollection[i];
4012  else
4013  {
4014  _targetCoordinates = new GEOREFCoordinates(CoordinateType::georef);
4015  targetCoordinateExists = false;
4016  }
4017  try
4018  {
4019  convert(
4022  sourceCoordinatesCollection[i],
4023  sourceAccuracyCollection[i],
4024  *_targetCoordinates, *_targetAccuracy);
4025  }
4027  {
4028  _targetCoordinates->setErrorMessage(e.getMessage());
4029  }
4030 
4031  if(!targetCoordinateExists)
4032  targetCoordinatesCollection.push_back(_targetCoordinates);
4033  break;
4034  }
4036  {
4037  if(i < numTargetCoordinates)
4038  _targetCoordinates = targetCoordinatesCollection[i];
4039  else
4040  {
4041  _targetCoordinates = new GARSCoordinates(
4043  targetCoordinateExists = false;
4044  }
4045  try
4046  {
4047  convert(
4050  sourceCoordinatesCollection[i],
4051  sourceAccuracyCollection[i],
4052  *_targetCoordinates, *_targetAccuracy);
4053  }
4055  {
4056  _targetCoordinates->setErrorMessage(e.getMessage());
4057  }
4058 
4059  if(!targetCoordinateExists)
4060  targetCoordinatesCollection.push_back(_targetCoordinates);
4061  break;
4062  }
4064  {
4065  if(i < numTargetCoordinates)
4066  _targetCoordinates = targetCoordinatesCollection[i];
4067  else
4068  {
4069  _targetCoordinates = new MapProjectionCoordinates(
4071  targetCoordinateExists = false;
4072  }
4073  try
4074  {
4075  convert(
4078  sourceCoordinatesCollection[i],
4079  sourceAccuracyCollection[i],
4080  *_targetCoordinates, *_targetAccuracy);
4081  }
4083  {
4084  _targetCoordinates->setErrorMessage(e.getMessage());
4085  }
4086 
4087  if(!targetCoordinateExists)
4088  targetCoordinatesCollection.push_back(_targetCoordinates);
4089  break;
4090  }
4092  {
4093  if(i < numTargetCoordinates)
4094  _targetCoordinates = targetCoordinatesCollection[i];
4095  else
4096  {
4097  _targetCoordinates = new MapProjectionCoordinates(
4099  targetCoordinateExists = false;
4100  }
4101  try
4102  {
4103  convert(
4106  sourceCoordinatesCollection[i],
4107  sourceAccuracyCollection[i],
4108  *_targetCoordinates,
4109  *_targetAccuracy);
4110  }
4112  {
4113  _targetCoordinates->setErrorMessage(e.getMessage());
4114  }
4115 
4116  if(!targetCoordinateExists)
4117  targetCoordinatesCollection.push_back(_targetCoordinates);
4118  break;
4119  }
4121  {
4122  if(i < numTargetCoordinates)
4123  _targetCoordinates = targetCoordinatesCollection[i];
4124  else
4125  {
4126  _targetCoordinates = new MapProjectionCoordinates(
4128  targetCoordinateExists = false;
4129  }
4130  try
4131  {
4132  convert(
4135  sourceCoordinatesCollection[i],
4136  sourceAccuracyCollection[i],
4137  *_targetCoordinates, *_targetAccuracy);
4138  }
4140  {
4141  _targetCoordinates->setErrorMessage(e.getMessage());
4142  }
4143 
4144  if(!targetCoordinateExists)
4145  targetCoordinatesCollection.push_back(_targetCoordinates);
4146  break;
4147  }
4149  {
4150  if(i < numTargetCoordinates)
4151  _targetCoordinates = targetCoordinatesCollection[i];
4152  else
4153  {
4154  _targetCoordinates = new CartesianCoordinates(
4156  targetCoordinateExists = false;
4157  }
4158  try
4159  {
4160  convert(
4163  sourceCoordinatesCollection[i],
4164  sourceAccuracyCollection[i],
4165  *_targetCoordinates, *_targetAccuracy);
4166  }
4168  {
4169  _targetCoordinates->setErrorMessage(e.getMessage());
4170  }
4171 
4172  if(!targetCoordinateExists)
4173  targetCoordinatesCollection.push_back(_targetCoordinates);
4174  break;
4175  }
4177  {
4178  if(i < numTargetCoordinates)
4179  _targetCoordinates = targetCoordinatesCollection[i];
4180  else
4181  {
4182  _targetCoordinates = new MapProjectionCoordinates(
4184  targetCoordinateExists = false;
4185  }
4186  try
4187  {
4188  convert(
4191  sourceCoordinatesCollection[i],
4192  sourceAccuracyCollection[i],
4193  *_targetCoordinates, *_targetAccuracy);
4194  }
4196  {
4197  _targetCoordinates->setErrorMessage(e.getMessage());
4198  }
4199 
4200  if(!targetCoordinateExists)
4201  targetCoordinatesCollection.push_back(_targetCoordinates);
4202  break;
4203  }
4205  {
4206  if(i < numTargetCoordinates)
4207  _targetCoordinates = targetCoordinatesCollection[i];
4208  else
4209  {
4210  _targetCoordinates = new MapProjectionCoordinates(
4212  targetCoordinateExists = false;
4213  }
4214  try
4215  {
4216  convert(
4219  sourceCoordinatesCollection[i],
4220  sourceAccuracyCollection[i],
4221  *_targetCoordinates, *_targetAccuracy);
4222  }
4224  {
4225  _targetCoordinates->setErrorMessage(e.getMessage());
4226  }
4227 
4228  if(!targetCoordinateExists)
4229  targetCoordinatesCollection.push_back(_targetCoordinates);
4230  break;
4231  }
4233  {
4234  if(i < numTargetCoordinates)
4235  _targetCoordinates = targetCoordinatesCollection[i];
4236  else
4237  {
4238  _targetCoordinates = new MGRSorUSNGCoordinates(
4240  targetCoordinateExists = false;
4241  }
4242  try
4243  {
4244  convert(
4247  sourceCoordinatesCollection[i],
4248  sourceAccuracyCollection[i],
4249  *_targetCoordinates, *_targetAccuracy);
4250  }
4252  {
4253  _targetCoordinates->setErrorMessage(e.getMessage());
4254  }
4255 
4256  if(!targetCoordinateExists)
4257  targetCoordinatesCollection.push_back(_targetCoordinates);
4258  break;
4259  }
4261  {
4262  if(i < numTargetCoordinates)
4263  _targetCoordinates = targetCoordinatesCollection[i];
4264  else
4265  {
4266  _targetCoordinates = new MapProjectionCoordinates(
4268  targetCoordinateExists = false;
4269  }
4270  try
4271  {
4272  convert(
4275  sourceCoordinatesCollection[i],
4276  sourceAccuracyCollection[i],
4277  *_targetCoordinates, *_targetAccuracy);
4278  }
4280  {
4281  _targetCoordinates->setErrorMessage(e.getMessage());
4282  }
4283 
4284  if(!targetCoordinateExists)
4285  targetCoordinatesCollection.push_back(_targetCoordinates);
4286  break;
4287  }
4289  {
4290  if(i < numTargetCoordinates)
4291  _targetCoordinates = targetCoordinatesCollection[i];
4292  else
4293  {
4294  _targetCoordinates = new MapProjectionCoordinates(
4296  targetCoordinateExists = false;
4297  }
4298  try
4299  {
4300  convert(
4303  sourceCoordinatesCollection[i],
4304  sourceAccuracyCollection[i],
4305  *_targetCoordinates, *_targetAccuracy);
4306  }
4308  {
4309  _targetCoordinates->setErrorMessage(e.getMessage());
4310  }
4311 
4312  if(!targetCoordinateExists)
4313  targetCoordinatesCollection.push_back(_targetCoordinates);
4314  break;
4315  }
4317  {
4318  if(i < numTargetCoordinates)
4319  _targetCoordinates = targetCoordinatesCollection[i];
4320  else
4321  {
4322  _targetCoordinates = new MapProjectionCoordinates(
4324  targetCoordinateExists = false;
4325  }
4326  try
4327  {
4328  convert(
4331  sourceCoordinatesCollection[i],
4332  sourceAccuracyCollection[i],
4333  *_targetCoordinates, *_targetAccuracy);
4334  }
4336  {
4337  _targetCoordinates->setErrorMessage(e.getMessage());
4338  }
4339 
4340  if(!targetCoordinateExists)
4341  targetCoordinatesCollection.push_back(_targetCoordinates);
4342  break;
4343  }
4344  case CoordinateType::neys:
4345  {
4346  if(i < numTargetCoordinates)
4347  _targetCoordinates = targetCoordinatesCollection[i];
4348  else
4349  {
4350  _targetCoordinates = new MapProjectionCoordinates(
4352  targetCoordinateExists = false;
4353  }
4354  try
4355  {
4356  convert(
4359  sourceCoordinatesCollection[i],
4360  sourceAccuracyCollection[i],
4361  *_targetCoordinates, *_targetAccuracy);
4362  }
4364  {
4365  _targetCoordinates->setErrorMessage(e.getMessage());
4366  }
4367 
4368  if(!targetCoordinateExists)
4369  targetCoordinatesCollection.push_back(_targetCoordinates);
4370  break;
4371  }
4373  {
4374  if(i < numTargetCoordinates)
4375  _targetCoordinates = targetCoordinatesCollection[i];
4376  else
4377  {
4378  _targetCoordinates = new MapProjectionCoordinates(
4380  targetCoordinateExists = false;
4381  }
4382  try
4383  {
4384  convert(
4387  sourceCoordinatesCollection[i],
4388  sourceAccuracyCollection[i],
4389  *_targetCoordinates, *_targetAccuracy);
4390  }
4392  {
4393  _targetCoordinates->setErrorMessage(e.getMessage());
4394  }
4395 
4396  if(!targetCoordinateExists)
4397  targetCoordinatesCollection.push_back(_targetCoordinates);
4398  break;
4399  }
4401  {
4402  if(i < numTargetCoordinates)
4403  _targetCoordinates = targetCoordinatesCollection[i];
4404  else
4405  {
4406  _targetCoordinates = new MapProjectionCoordinates(
4408  targetCoordinateExists = false;
4409  }
4410  try
4411  {
4412  convert(
4415  sourceCoordinatesCollection[i],
4416  sourceAccuracyCollection[i],
4417  *_targetCoordinates, *_targetAccuracy);
4418  }
4420  {
4421  _targetCoordinates->setErrorMessage(e.getMessage());
4422  }
4423 
4424  if(!targetCoordinateExists)
4425  targetCoordinatesCollection.push_back(_targetCoordinates);
4426  break;
4427  }
4429  {
4430  if(i < numTargetCoordinates)
4431  _targetCoordinates = targetCoordinatesCollection[i];
4432  else
4433  {
4434  _targetCoordinates = new MapProjectionCoordinates(
4436  targetCoordinateExists = false;
4437  }
4438  try
4439  {
4440  convert(
4443  sourceCoordinatesCollection[i],
4444  sourceAccuracyCollection[i],
4445  *_targetCoordinates, *_targetAccuracy);
4446  }
4448  {
4449  _targetCoordinates->setErrorMessage(e.getMessage());
4450  }
4451 
4452  if(!targetCoordinateExists)
4453  targetCoordinatesCollection.push_back(_targetCoordinates);
4454  break;
4455  }
4457  {
4458  if(i < numTargetCoordinates)
4459  _targetCoordinates = targetCoordinatesCollection[i];
4460  else
4461  {
4462  _targetCoordinates = new MapProjectionCoordinates(
4464  targetCoordinateExists = false;
4465  }
4466  try
4467  {
4468  convert(
4471  sourceCoordinatesCollection[i],
4472  sourceAccuracyCollection[i],
4473  *_targetCoordinates, *_targetAccuracy);
4474  }
4476  {
4477  _targetCoordinates->setErrorMessage(e.getMessage());
4478  }
4479 
4480  if(!targetCoordinateExists)
4481  targetCoordinatesCollection.push_back(_targetCoordinates);
4482  break;
4483  }
4485  {
4486  if(i < numTargetCoordinates)
4487  _targetCoordinates = targetCoordinatesCollection[i];
4488  else
4489  {
4490  _targetCoordinates = new MapProjectionCoordinates(
4492  targetCoordinateExists = false;
4493  }
4494  try
4495  {
4496  convert(
4499  sourceCoordinatesCollection[i],
4500  sourceAccuracyCollection[i],
4501  *_targetCoordinates, *_targetAccuracy);
4502  }
4504  {
4505  _targetCoordinates->setErrorMessage(e.getMessage());
4506  }
4507 
4508  if(!targetCoordinateExists)
4509  targetCoordinatesCollection.push_back(_targetCoordinates);
4510  break;
4511  }
4513  {
4514  if(i < numTargetCoordinates)
4515  _targetCoordinates = targetCoordinatesCollection[i];
4516  else
4517  {
4518  _targetCoordinates = new MapProjectionCoordinates(
4520  targetCoordinateExists = false;
4521  }
4522  try
4523  {
4524  convert(
4527  sourceCoordinatesCollection[i],
4528  sourceAccuracyCollection[i],
4529  *_targetCoordinates, *_targetAccuracy);
4530  }
4532  {
4533  _targetCoordinates->setErrorMessage(e.getMessage());
4534  }
4535 
4536  if(!targetCoordinateExists)
4537  targetCoordinatesCollection.push_back(_targetCoordinates);
4538  break;
4539  }
4541  {
4542  if(i < numTargetCoordinates)
4543  _targetCoordinates = targetCoordinatesCollection[i];
4544  else
4545  {
4546  _targetCoordinates = new MapProjectionCoordinates(
4548  targetCoordinateExists = false;
4549  }
4550  try
4551  {
4552  convert(
4555  sourceCoordinatesCollection[i],
4556  sourceAccuracyCollection[i],
4557  *_targetCoordinates, *_targetAccuracy);
4558  }
4560  {
4561  _targetCoordinates->setErrorMessage(e.getMessage());
4562  }
4563 
4564  if(!targetCoordinateExists)
4565  targetCoordinatesCollection.push_back(_targetCoordinates);
4566  break;
4567  }
4569  {
4570  if(i < numTargetCoordinates)
4571  _targetCoordinates = targetCoordinatesCollection[i];
4572  else
4573  {
4574  _targetCoordinates = new MapProjectionCoordinates(
4576  targetCoordinateExists = false;
4577  }
4578  try
4579  {
4580  convert(
4583  sourceCoordinatesCollection[i],
4584  sourceAccuracyCollection[i],
4585  *_targetCoordinates, *_targetAccuracy);
4586  }
4588  {
4589  _targetCoordinates->setErrorMessage(e.getMessage());
4590  }
4591 
4592  if(!targetCoordinateExists)
4593  targetCoordinatesCollection.push_back(_targetCoordinates);
4594  break;
4595  }
4597  {
4598  if(i < numTargetCoordinates)
4599  _targetCoordinates = targetCoordinatesCollection[i];
4600  else
4601  {
4602  _targetCoordinates = new MapProjectionCoordinates(
4604  targetCoordinateExists = false;
4605  }
4606  try
4607  {
4608  convert(
4611  sourceCoordinatesCollection[i],
4612  sourceAccuracyCollection[i],
4613  *_targetCoordinates, *_targetAccuracy);
4614  }
4616  {
4617  _targetCoordinates->setErrorMessage(e.getMessage());
4618  }
4619 
4620  if(!targetCoordinateExists)
4621  targetCoordinatesCollection.push_back(_targetCoordinates);
4622  break;
4623  }
4625  {
4626  if(i < numTargetCoordinates)
4627  _targetCoordinates = targetCoordinatesCollection[i];
4628  else
4629  {
4630  _targetCoordinates = new UPSCoordinates(
4632  targetCoordinateExists = false;
4633  }
4634  try
4635  {
4636  convert(
4639  _sourceCoordinates,
4640  _sourceAccuracy,
4641  *_targetCoordinates, *_targetAccuracy);
4642  }
4644  {
4645  _targetCoordinates->setErrorMessage(e.getMessage());
4646  }
4647 
4648  if(!targetCoordinateExists)
4649  targetCoordinatesCollection.push_back(_targetCoordinates);
4650  break;
4651  }
4653  {
4654  if(i < numTargetCoordinates)
4655  _targetCoordinates = targetCoordinatesCollection[i];
4656  else
4657  {
4658  _targetCoordinates = new UTMCoordinates(
4660  targetCoordinateExists = false;
4661  }
4662  try
4663  {
4664  convert(
4667  sourceCoordinatesCollection[i],
4668  sourceAccuracyCollection[i],
4669  *_targetCoordinates, *_targetAccuracy);
4670  }
4672  {
4673  _targetCoordinates->setErrorMessage(e.getMessage());
4674  }
4675 
4676  if(!targetCoordinateExists)
4677  targetCoordinatesCollection.push_back(_targetCoordinates);
4678  break;
4679  }
4681  {
4682  if(i < numTargetCoordinates)
4683  _targetCoordinates = targetCoordinatesCollection[i];
4684  else
4685  {
4686  _targetCoordinates = new MGRSorUSNGCoordinates(
4688  targetCoordinateExists = false;
4689  }
4690  try
4691  {
4692  convert(
4695  sourceCoordinatesCollection[i],
4696  sourceAccuracyCollection[i],
4697  *_targetCoordinates, *_targetAccuracy);
4698  }
4700  {
4701  _targetCoordinates->setErrorMessage(e.getMessage());
4702  }
4703 
4704  if(!targetCoordinateExists)
4705  targetCoordinatesCollection.push_back(_targetCoordinates);
4706  break;
4707  }
4709  {
4710  if(i < numTargetCoordinates)
4711  _targetCoordinates = targetCoordinatesCollection[i];
4712  else
4713  {
4714  _targetCoordinates = new MapProjectionCoordinates(
4716  targetCoordinateExists = false;
4717  }
4718  try
4719  {
4720  convert(
4723  sourceCoordinatesCollection[i],
4724  sourceAccuracyCollection[i],
4725  *_targetCoordinates, *_targetAccuracy);
4726  }
4728  {
4729  _targetCoordinates->setErrorMessage(e.getMessage());
4730  }
4731 
4732  if(!targetCoordinateExists)
4733  targetCoordinatesCollection.push_back(_targetCoordinates);
4734  break;
4735  }
4737  {
4738  if(i < numTargetCoordinates)
4739  _targetCoordinates = targetCoordinatesCollection[i];
4740  else
4741  {
4742  _targetCoordinates =
4744  targetCoordinateExists = false;
4745  }
4746  try
4747  {
4748  convert(
4751  sourceCoordinatesCollection[i],
4752  sourceAccuracyCollection[i],
4753  *_targetCoordinates, *_targetAccuracy);
4754  }
4756  {
4757  _targetCoordinates->setErrorMessage(e.getMessage());
4758  }
4759 
4760  if(!targetCoordinateExists)
4761  targetCoordinatesCollection.push_back(_targetCoordinates);
4762  break;
4763  }
4764  default:
4766  }
4767 
4768  if(!targetAccuracyExists)
4769  targetAccuracyCollection.push_back( _targetAccuracy );
4770  }
4771  else
4772  {
4773  if(i >= numTargetCoordinates)
4774  targetCoordinateExists = false;
4775 
4776  if( _sourceCoordinates )
4777  {
4778  if(!targetCoordinateExists)
4779  targetCoordinatesCollection.push_back(
4780  new CoordinateTuple( *_sourceCoordinates ) );
4781  else
4782  {
4783  _targetCoordinates = targetCoordinatesCollection[i];
4784  _targetCoordinates->set(
4785  _sourceCoordinates->coordinateType(),
4786  _sourceCoordinates->warningMessage(),
4787  _sourceCoordinates->errorMessage());
4788  }
4789  }
4790  else
4791  {
4792  if(!targetCoordinateExists)
4793  targetCoordinatesCollection.push_back( new CoordinateTuple() );
4794  }
4795 
4796  if(!targetAccuracyExists)
4797  {
4798  if( _sourceAccuracy )
4799  targetAccuracyCollection.push_back( _sourceAccuracy );
4800  else
4801  {
4802  Accuracy* __sourceAccuracy = new Accuracy();
4803  targetAccuracyCollection.push_back( __sourceAccuracy );
4804  }
4805  }
4806  }
4807  }
4808 
4809  if(numTargetCoordinates > num)
4810  {
4811  for(int i = num; i < numTargetCoordinates; i++)
4812  {
4813  delete targetCoordinatesCollection[i];
4814  targetCoordinatesCollection.pop_back();
4815  }
4816  }
4817  if(numTargetAccuracies > num)
4818  {
4819  for(int i = num; i < numTargetAccuracies; i++)
4820  {
4821  targetAccuracyCollection.pop_back();
4822  }
4823  }
4824 }
4825 
4826 // CLASSIFICATION: UNCLASSIFIED