UNCLASSIFIED

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