UNCLASSIFIED

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