UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Functions Enumerations
CoordinateConversionService.h
1 // CLASSIFICATION: UNCLASSIFIED
2 #ifndef CoordinateConversionService_H
3 #define CoordinateConversionService_H
4 
5 /***************************************************************************/
6 /* RSC IDENTIFIER: Coordinate Conversion Service
7  *
8  * ABSTRACT
9  *
10  * This component is the coordinate conversion service for the MSPCCS
11  * application. It provides an external input interface that supports the
12  * MSPCCS GUI (Java) and the MSPCCS file processing
13  * component.
14  *
15  * This component depends on the DT&CC modules: DATUM, ELLIPSOID,
16  * GEOCENTRIC, GEOREF, MERCATOR, TRANSVERSE MERCATOR, UTM, MGRS, USNG, POLAR
17  * STEREOGRAPHIC, UPS, LAMBERT_1, LAMBERT_2, ALBERS, AZIMUTHAL EQUIDISTANT, BONNE,
18  * BRITISH NATIONAL GRID, CASSINI, CYLINDRICAL EQUAL AREA,ECKERT4, ECKERT6,
19  * EQUIDISTANT CYLINDRICAL, GARS, GNOMONIC, LOCAL CARTESIAN, MILLER, MOLLWEIDE,
20  * NEYS, NEW ZEALAND MAP GRID, OBLIQUE MERCATOR, ORTHOGRAPHIC, POLYCONIC,
21  * SINUSOIDAL, STEREOGRAPHIC, TRANSVERSE CYLINDRICAL EQUAL AREA, and VAN DER GRINTEN.
22  *
23  *
24  * ERROR HANDLING
25  *
26  * This component checks for error codes returned by the DT&CC modules.
27  * If an error code is returned, it is combined with the current
28  * error code using the bitwise or. This combining allows multiple error
29  * codes to be returned. The possible error codes are listed below.
30  *
31  *
32  * REUSE NOTES
33  *
34  * Coordinate Conversion Service is intended for reuse by other applications that require
35  * coordinate conversions between multiple coordinate systems and/or datum
36  * transformations between multiple datums.
37  *
38  *
39  * REFERENCES
40  *
41  * Further information on Coordinate Conversion Service can be found in the Coordinate
42  * Conversion Service Reuse Manual.
43  *
44  * Coordinate Conversion Service originated from : U.S. Army Topographic Engineering Center
45  * Digital Concepts & Analysis Center
46  * 7701 Telegraph Road
47  * Alexandria, VA 22310-3864
48  *
49  *
50  * LICENSES
51  *
52  * None apply to this component.
53  *
54  * RESTRICTIONS
55  *
56  * Coordinate Conversion Service has no restrictions.
57  *
58  * ENVIRONMENT
59  *
60  * Coordinate Conversion Service was tested and certified in the following environments:
61  *
62  * 1. Solaris 2.5 with GCC, version 2.8.1
63  * 2. Windows XP with MS Visual C++, version 6
64  *
65  * MODIFICATIONS
66  *
67  * Date Description
68  * ---- -----------
69  * 04-22-97 Original Code
70  * 09-30-99 Added support for 15 new projections
71  * 05-30-00 Added support for 2 new projections
72  * 06-30-00 Added support for 1 new projection
73  * 09-30-00 Added support for 4 new projections
74  * 03-24-05 Added support for Lambert Conformal Conic (1 Standard Parallel)
75  * 08-17-05 Changed Lambert_Conformal_Conic to Lambert_Conformal_Conic_2
76  * 06-06-06 Added support for USNG
77  * 07-17-06 Added support for GARS
78  * 03-17-07 Original C++ Code
79  * 07-20-10 NGL BAEts27152 Updated getServiceVersion to return an int
80  */
81 
82 
83 #include <vector>
84 #include "CoordinateType.h"
85 #include "Precision.h"
86 #include "SourceOrTarget.h"
87 #include "CoordinateTuple.h"
88 
89 
90 #ifdef WIN32
91 #ifdef MSP_CCS_EX
92 #define MSP_CCS __declspec(dllexport)
93 #else
94 #define MSP_CCS __declspec(dllimport)
95 #endif
96 #endif
97 
98 
99 namespace MSP
100 {
101  class CCSThreadMutex;
102  namespace CCS
103  {
104  class EllipsoidLibrary;
105  class EllipsoidLibraryImplementation;
106  class DatumLibrary;
107  class DatumLibraryImplementation;
108  class GeoidLibrary;
109  class Accuracy;
110  class CoordinateSystemParameters;
111  class CoordinateTuple;
112  class MapProjection3Parameters;
113  class MapProjection4Parameters;
114  class MapProjection5Parameters;
115  class MapProjection6Parameters;
116  class EquidistantCylindricalParameters;
117  class GeodeticParameters;
118  class LocalCartesianParameters;
119  class MercatorStandardParallelParameters;
120  class MercatorScaleFactorParameters;
121  class NeysParameters;
122  class ObliqueMercatorParameters;
123  class PolarStereographicStandardParallelParameters;
124  class PolarStereographicScaleFactorParameters;
125  class UTMParameters;
126  class MapProjectionCoordinates;
127  class BNGCoordinates;
128  class CartesianCoordinates;
129  class GeodeticCoordinates;
130  class GEOREFCoordinates;
131  class GARSCoordinates;
132  class MGRSorUSNGCoordinates;
133  class UPSCoordinates;
134  class UTMCoordinates;
135  class CoordinateSystem;
136 
137 
138  /***************************************************************************/
139  /*
140  * DEFINES
141  */
142 
143  /* Symbolic constants */
144  const int NUMBER_COORD_SYS = 37; /* Number of coordinate systems */
145  const int COORD_SYS_CODE_LENGTH = 3; /* Length of coordinate system codes (including null) */
146  const int COORD_SYS_NAME_LENGTH = 50; /* Max length of coordinate system names (including null) */
147  const int DATUM_CODE_LENGTH = 7; /* Length of datum codes (including null) */
148  const int DATUM_NAME_LENGTH = 33; /* Max length of datum names (including null) */
149  const int ELLIPSOID_CODE_LENGTH = 3; /* Length of ellipsoid codes (including null) */
150  const int ELLIPSOID_NAME_LENGTH = 30; /* Max length of ellipsoid names (including null) */
151  const int CONVERT_MSG_LENGTH = 2048; /* Max length of coordinate conversion status message */
152  const int RETURN_MSG_LENGTH = 256; /* Max length of return code status message */
153 
154 
158  struct Color
159  {
161  enum Enum
162  {
163  red,
164  yellow,
165  green
166  };
167  };
168 
173 #ifdef WIN32
174  class MSP_CCS CoordinateConversionService
175 #else
177 #endif
178  {
179  public:
180 
192  CoordinateConversionService( const char* sourceDatumCode, MSP::CCS::CoordinateSystemParameters* sourceParameters, const char* targetDatumCode, MSP::CCS::CoordinateSystemParameters* targetParameters );
193 
200 
205 
212 
213 
226  void convertSourceToTarget( CoordinateTuple* sourceCoordinates, Accuracy* sourceAccuracy, CoordinateTuple& targetCoordinates, Accuracy& targetAccuracy );
227 
228 
241  void convertTargetToSource( CoordinateTuple* targetCoordinates, Accuracy* targetAccuracy, CoordinateTuple& sourceCoordinates, Accuracy& sourceAccurac );
242 
243 
254  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 );
255 
256 
267  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 );
268 
269 
270  /*
271  * The function getEllipsoidLibrary returns the ellipsoid library
272  * which provides access to ellipsoidparameter information.
273  *
274  */
275 
276  EllipsoidLibrary* getEllipsoidLibrary();
277 
278 
279  /*
280  * The function getDatumLibrary returns the datum library
281  * which provides access to datum transformation and parameter information.
282  *
283  * @return Datum library
284  */
285  DatumLibrary* getDatumLibrary();
286 
287 
288  /*
289  * The function getServiceVersion returns current service version.
290  *
291  * @return Service version
292  */
293  int getServiceVersion();
294 
295 
296  /*
297  * The function getDatum returns the index of the current datum.
298  *
299  * @param[in] direction - indicates whether the datum is to be used for input or output
300  * @return Index identifying the index of the current datum
301  */
302 
303  const char* getDatum( const SourceOrTarget::Enum direction ) const;
304 
305 
306  /*
307  * The function getCoordinateSystem returns the current coordinate system
308  * type.
309  *
310  * @param[in] direction - Indicates whether the coordinate system is to
311  * be used for input or output
312  * @return Parameters identifies current coordinate system type
313  */
314 
315  MSP::CCS::CoordinateSystemParameters* getCoordinateSystem( const SourceOrTarget::Enum direction ) const;
316 
317 
318  private:
319 
320  static CCSThreadMutex mutex;
321 
322  /* Object used to keep track of the number of ccs objects */
323  struct CCSData
324  {
325  int refCount;
326 
327  EllipsoidLibrary* ellipsoidLibrary;
328  EllipsoidLibraryImplementation* ellipsoidLibraryImplementation;
329  DatumLibrary* datumLibrary;
330  DatumLibraryImplementation* datumLibraryImplementation;
331  GeoidLibrary* geoidLibrary;
332 
333  CCSData();
334  ~CCSData();
335  };
336 
337  CCSData* ccsData;
338 
339  EllipsoidLibraryImplementation* ellipsoidLibraryImplementation;
340  DatumLibraryImplementation* datumLibraryImplementation;
341  GeoidLibrary* geoidLibrary;
342 
343 //compiler bug on solaris 8. Parameters needs to be public
344 #ifdef SOLARIS
345  public:
346 #endif
347 
348  /* Coordinate System Definition with Multiple Variants */
349  union Parameters
350  {
351  CoordinateSystemParameters* coordinateSystemParameters;
352  MapProjection3Parameters* mapProjection3Parameters;
353  MapProjection4Parameters* mapProjection4Parameters;
354  MapProjection5Parameters* mapProjection5Parameters;
355  MapProjection6Parameters* mapProjection6Parameters;
356  EquidistantCylindricalParameters* equidistantCylindricalParameters;
357  GeodeticParameters* geodeticParameters;
358  LocalCartesianParameters* localCartesianParameters;
359  MercatorStandardParallelParameters* mercatorStandardParallelParameters;
360  MercatorScaleFactorParameters* mercatorScaleFactorParameters;
361  NeysParameters* neysParameters;
362  ObliqueMercatorParameters* obliqueMercatorParameters;
363  PolarStereographicStandardParallelParameters* polarStereographicStandardParallelParameters;
364  PolarStereographicScaleFactorParameters* polarStereographicScaleFactorParameters;
365  UTMParameters* utmParameters;
366  };
367 
368  /* Coordinate Tuple Definition with Multiple Variants */
369  union Coordinates
370  {
371  MapProjectionCoordinates* mapProjectionCoordinates;
372  BNGCoordinates* bngCoordinates;
373  CartesianCoordinates* cartesianCoordinates;
374  GeodeticCoordinates* geodeticCoordinates;
375  GEOREFCoordinates* georefCoordinates;
376  GARSCoordinates* garsCoordinates;
377  MGRSorUSNGCoordinates* mgrsOrUSNGCoordinates;
378  UPSCoordinates* upsCoordinates;
379  UTMCoordinates* utmCoordinates;
380  };
381 
382  struct Coordinate_System_Row
383  {
384  char Name[COORD_SYS_NAME_LENGTH];
385  char Code[COORD_SYS_CODE_LENGTH];
386  CoordinateType::Enum coordinateSystem;
387  };
388 
389 
390  /* Coordinate Conversion Service State Definition */
391  struct Coordinate_State_Row
392  {
393  char datumCode[DATUM_CODE_LENGTH]; /* currently specified datum code */
394  long datumIndex; /* currently specified datum index */
395  CoordinateType::Enum coordinateType; /* current coordinate system type */
396  Parameters parameters; /* current coordinate system parameters */
397  CoordinateSystem* coordinateSystem; /* current coordinate system */
398  };
399 
400  /* coordinateSystemState[x] is set up as follows:
401  c = Number of IO states (Source, Target, etc.) */
402  Coordinate_State_Row coordinateSystemState[2];
403 
404  /* Local State Variables */
405  Coordinate_System_Row Coordinate_System_Table[NUMBER_COORD_SYS];
406 
407  long WGS84_datum_index;
408 
409 
410  /*
411  * The function setDataLibraries sets the initial state of the engine in
412  * in preparation for coordinate conversion and/or datum transformation
413  * operations.
414  */
415 
416  void setDataLibraries();
417 
418 
419  /*
420  * The function initCoordinateSystemState initializes coordinateSystemState.
421  *
422  * direction : Indicates whether the coordinate system is to be used for
423  * source or target (input)
424  */
425 
426  void initCoordinateSystemState( const SourceOrTarget::Enum direction );
427 
428 
429  /*
430  * The function deleteCoordinateSystem frees memory of coordinateSystemState.
431  *
432  * direction : Indicates whether the coordinate system is to be used for
433  * source or target (input)
434  */
435 
436  void deleteCoordinateSystem( const SourceOrTarget::Enum direction );
437 
438 
439  /*
440  * The function copyParameters uses the input parameters to set the value of the
441  * current parameters.
442  *
443  * direction : Indicates whether the coordinate system is to be used for
444  * source or target (input)
445  * coordinateType : Coordinate system type (input)
446  * parameters : Coordinate system parameters to copy (input)
447  */
448 
449  void copyParameters( SourceOrTarget::Enum direction, CoordinateType::Enum coordinateType, Parameters parameters );
450 
451 
452  /*
453  * The function setDatum sets the datum to the
454  * datum corresponding to the specified index.
455  *
456  * direction : Indicates whether the datum is to be used for input or
457  * output (input)
458  * index : Identifies the index of the datum to be used (input)
459  */
460 
461  void setDatum( const SourceOrTarget::Enum direction, const char* index );
462 
463 
464  /*
465  * The function setCoordinateSystem sets the coordinate system
466  * to the specified coordinate system type.
467  *
468  * direction : Indicates whether the coordinate system is to be used for
469  * input or output (input)
470  * parameters : Coordinate system parameters to be used (input)
471  */
472 
473  void setCoordinateSystem( const SourceOrTarget::Enum direction, MSP::CCS::CoordinateSystemParameters* parameters );
474 
475 
476  /*
477  * The function setParameters calls the setParameters function of the source or target
478  * coordinate system.
479  *
480  * direction : Indicates whether the coordinate system is to be used for
481  * source or target (input)
482  */
483 
484  void setParameters( const SourceOrTarget::Enum direction );
485 
486 
487  /*
488  * The function convert converts the current input coordinates in the coordinate
489  * system defined by the current input coordinate system parameters and input datum,
490  * into output coordinates in the coordinate system defined by the output coordinate
491  * system parameters and output datum.
492  *
493  * sourceDirection: Indicates which set of coordinates and parameters to use as the source (input)
494  * targetDirection: Indicates which set of coordinates and parameters to use as the target (input)
495  */
496 
497  void convert( SourceOrTarget::Enum sourceDirection, SourceOrTarget::Enum targetDirection, CoordinateTuple* sourceCoordinates, Accuracy* sourceAccuracy, CoordinateTuple& targetCoordinates, Accuracy& targetAccuracy );
498 
499 
500  GeodeticCoordinates* convertSourceToGeodetic( SourceOrTarget::Enum sourceDirection, CoordinateTuple* sourceCoordinates, char* sourceWarningMessage );
501 
502 
503  void convertGeodeticToTarget( SourceOrTarget::Enum targetDirection, GeodeticCoordinates* _shiftedGeodetic, CoordinateTuple& targetCoordinates, char* targetWarningMessage );
504 
505 
506  /*
507  * The function convertCollection will convert a list of source coordinates to a list of target coordinates
508  * in a single step.
509  *
510  * sourceCoordinatesCollection : Coordinates of the source coordinate system to be converted (input)
511  * sourceAccuracyCollection : Source circular, linear and spherical errors (input)
512  * targetCoordinatesCollection : Converted coordinates of the target coordinate system (output)
513  * targetAccuracyCollection : Target circular, linear and spherical errors (output)
514  */
515 
516  void convertCollection( const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinatesCollection, const std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection, std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinatesCollection, std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection );
517  };
518  }
519 }
520 
521 #endif
522 
523 
524 // CLASSIFICATION: UNCLASSIFIED