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, LOCAL SPHERICAL,
20  * MILLER, MOLLWEIDE, NEYS, NEW ZEALAND MAP GRID, OBLIQUE MERCATOR,
21  * ORTHOGRAPHIC, POLYCONIC, SINUSOIDAL, SPHERICAL, 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 <string.h>
80 
81 #include "CoordinateType.h"
82 #include "Precision.h"
83 #include "SourceOrTarget.h"
84 #include "CoordinateTuple.h"
85 
86 
87 #ifdef WIN32
88 #ifdef MSP_CCS_EXPORTS
89 #define MSP_CCS __declspec(dllexport)
90 #elif defined (MSP_CCS_IMPORTS)
91 #define MSP_CCS __declspec(dllimport)
92 #else
93 #define MSP_CCS
94 #endif
95 #endif
96 
97 
98 namespace MSP
99 {
100  class CCSThreadMutex;
101  namespace CCS
102  {
103  class EllipsoidLibrary;
105  class DatumLibrary;
107  class GeoidLibrary;
108  class Accuracy;
110  class CoordinateTuple;
116  class GeodeticParameters;
120  class NeysParameters;
124  class UTMParameters;
125  class GeodeticCoordinates;
126  class CoordinateSystem;
127 
128  /*
129  * DEFINES
130  */
131 
132  /* Symbolic constants */
133  const int NUMBER_COORD_SYS = 40; // Number of coordinate systems
134  const int COORD_SYS_CODE_LENGTH = 3; // Length of coordinate system codes (including null)
135  const int COORD_SYS_NAME_LENGTH = 50; // Max length of coordinate system names (including null)
136  const int DATUM_CODE_LENGTH = 7; // Length of datum codes (including null)
137  const int DATUM_NAME_LENGTH = 33; // Max length of datum names (including null)
138  const int ELLIPSOID_CODE_LENGTH = 3; // Length of ellipsoid codes (including null)
139  const int ELLIPSOID_NAME_LENGTH = 30; // Max length of ellipsoid names (including null)
140  const int CONVERT_MSG_LENGTH = 2048; // Max length of coordinate conversion status message
141  const int RETURN_MSG_LENGTH = 256; // Max length of return code status message
142 
143 
144 
149 #ifdef WIN32
150  class MSP_CCS CoordinateConversionService
151 #else
153 #endif
154  {
155  public:
156 
169  const char* sourceDatumCode,
170  MSP::CCS::CoordinateSystemParameters* sourceParameters,
171  const char* targetDatumCode,
172  MSP::CCS::CoordinateSystemParameters* targetParameters );
173 
180 
185 
191  CoordinateConversionService &operator=(
192  const CoordinateConversionService &ccs );
193 
194 
208  void convertSourceToTarget(
209  CoordinateTuple* sourceCoordinates,
210  Accuracy* sourceAccuracy,
211  CoordinateTuple& targetCoordinates,
212  Accuracy& targetAccuracy );
213 
214 
228  void convertTargetToSource(
229  CoordinateTuple* targetCoordinates,
230  Accuracy* targetAccuracy,
231  CoordinateTuple& sourceCoordinates,
232  Accuracy& sourceAccurac );
233 
234 
245  void convertSourceToTargetCollection(
246  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
247  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracy,
248  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
249  std::vector<MSP::CCS::Accuracy*>& targetAccuracy );
250 
251 
263  void convertTargetToSourceCollection(
264  const std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinates,
265  const std::vector<MSP::CCS::Accuracy*>& targetAccuracy,
266  std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinates,
267  std::vector<MSP::CCS::Accuracy*>& sourceAccuracy );
268 
269 
270  /*
271  * The function getEllipsoidLibrary returns the ellipsoid library
272  * which provides access to ellipsoid parameter 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
282  * information.
283  *
284  * @return Datum library
285  */
286  DatumLibrary* getDatumLibrary();
287 
288 
289  /*
290  * The function getServiceVersion returns current service version.
291  *
292  * @return Service version
293  */
294  int getServiceVersion();
295 
296 
297  /*
298  * The function getDatum returns the index of the current datum.
299  *
300  * @param[in] direction - indicates whether the datum is to be used for input or output
301  * @return Index identifying the index of the current datum
302  */
303 
304  const char* getDatum( const SourceOrTarget::Enum direction ) const;
305 
306 
307  /*
308  * The function getCoordinateSystem returns the current
309  * coordinate system type.
310  *
311  * @param[in] direction - Indicates whether the coordinate system is to
312  * be used for input or output
313  * @return Parameters identifies current coordinate system type
314  */
315 
316  MSP::CCS::CoordinateSystemParameters* getCoordinateSystem(
317  const SourceOrTarget::Enum direction ) const;
318 
319 
320  private:
321 
322  static CCSThreadMutex mutex;
323 
324  /* Object used to keep track of the number of CCS objects */
325  struct CCSData
326  {
327  int refCount;
328 
329  EllipsoidLibrary* ellipsoidLibrary;
330  EllipsoidLibraryImplementation* ellipsoidLibraryImplementation;
331  DatumLibrary* datumLibrary;
332  DatumLibraryImplementation* datumLibraryImplementation;
333  GeoidLibrary* geoidLibrary;
334 
335  CCSData();
336  ~CCSData();
337  };
338 
339  CCSData* ccsData;
340 
341  EllipsoidLibraryImplementation* ellipsoidLibraryImplementation;
342  DatumLibraryImplementation* datumLibraryImplementation;
343  GeoidLibrary* geoidLibrary;
344 
345 //compiler bug on solaris 8. Parameters needs to be public
346 #ifdef SOLARIS
347  public:
348 #endif
349 
350  /* Coordinate System Definition with Multiple Variants */
351  union Parameters
352  {
353  CoordinateSystemParameters* coordinateSystemParameters;
354  MapProjection3Parameters* mapProjection3Parameters;
355  MapProjection4Parameters* mapProjection4Parameters;
356  MapProjection5Parameters* mapProjection5Parameters;
357  MapProjection6Parameters* mapProjection6Parameters;
358  EquidistantCylindricalParameters* equidistantCylindricalParameters;
359  GeodeticParameters* geodeticParameters;
360  LocalCartesianParameters* localCartesianParameters;
361  MercatorStandardParallelParameters* mercatorStandardParallelParameters;
362  MercatorScaleFactorParameters* mercatorScaleFactorParameters;
363  NeysParameters* neysParameters;
364  ObliqueMercatorParameters* obliqueMercatorParameters;
365  PolarStereographicStandardParallelParameters* polarStereographicStandardParallelParameters;
366  PolarStereographicScaleFactorParameters* polarStereographicScaleFactorParameters;
367  UTMParameters* utmParameters;
368  };
369 
370  struct Coordinate_System_Row
371  {
372  char Name[COORD_SYS_NAME_LENGTH];
373  char Code[COORD_SYS_CODE_LENGTH];
374 
375  void set( const char *name, const char *code)
376  {
377  strcpy( Name, name );
378  strcpy( Code, code );
379  }
380  };
381 
382  /* Coordinate Conversion Service State Definition */
383  struct Coordinate_State_Row
384  {
385  char datumCode[DATUM_CODE_LENGTH]; // currently specified datum code
386  long datumIndex; // currently specified datum index
387  CoordinateType::Enum coordinateType; // current CS type
388  Parameters parameters; // current CS parameters
389  CoordinateSystem* coordinateSystem; // current CS
390  };
391 
392  /* coordinateSystemState[x] is set up as follows:
393  c = Number of IO states (Source, Target, etc.) */
394  Coordinate_State_Row coordinateSystemState[2];
395 
396  /* Local State Variables */
397  Coordinate_System_Row Coordinate_System_Table[NUMBER_COORD_SYS];
398 
399  long WGS84_datum_index;
400 
401  /*
402  * The function setDataLibraries sets the initial state of the engine
403  * in preparation for coordinate conversion and/or datum transformation
404  * operations.
405  */
406  void setDataLibraries();
407 
408 
409  /*
410  * The function initCoordinateSystemState initializes
411  * coordinateSystemState.
412  *
413  * direction : Indicates whether the coordinate system is to be used
414  * for source or target (input)
415  */
416 
417  void initCoordinateSystemState( const SourceOrTarget::Enum direction );
418 
419 
420  /*
421  * The function deleteCoordinateSystem frees memory of
422  * coordinateSystemState.
423  *
424  * direction : Indicates whether the coordinate system is to be used
425  * for source or target (input)
426  */
427 
428  void deleteCoordinateSystem( const SourceOrTarget::Enum direction );
429 
430 
431  /*
432  * The function copyParameters uses the input parameters to set the
433  * value of the current parameters.
434  *
435  * direction : Indicates whether the coordinate system is to
436  * be used for source or target (input)
437  * coordinateType : Coordinate system type (input)
438  * parameters : Coordinate system parameters to copy (input)
439  */
440 
441  void copyParameters(
442  SourceOrTarget::Enum direction,
443  CoordinateType::Enum coordinateType,
444  Parameters parameters );
445 
446  /*
447  * The function setDatum sets the datum to the
448  * datum corresponding to the specified index.
449  *
450  * direction : Indicates whether the datum is to be used for input or
451  * output (input)
452  * index : Identifies the index of the datum to be used (input)
453  */
454 
455  void setDatum(
456  const SourceOrTarget::Enum direction,
457  const char* index );
458 
459 
460  /*
461  * The function setCoordinateSystem sets the coordinate system
462  * to the specified coordinate system type.
463  *
464  * direction : Indicates whether the coordinate system is to be
465  * used for input or output (input)
466  * parameters : Coordinate system parameters to be used (input)
467  */
468 
469  void setCoordinateSystem(
470  const SourceOrTarget::Enum direction,
472 
473  /*
474  * The function setParameters calls the setParameters function
475  * of the source or target coordinate system.
476  *
477  * direction : Indicates whether the coordinate system is to be
478  * used for source or target (input)
479  */
480 
481  void setParameters( const SourceOrTarget::Enum direction );
482 
483 
484  /*
485  * The function convert converts the current input coordinates
486  * in the coordinate system defined by the current input coordinate
487  * system parameters and input datum, into output coordinates in
488  * the coordinate system defined by the output coordinate
489  * system parameters and output datum.
490  *
491  * sourceDirection: Indicates which set of coordinates and parameters to use as the source (input)
492  * targetDirection: Indicates which set of coordinates and parameters to use as the target (input)
493  */
494 
495  void convert(
496  SourceOrTarget::Enum sourceDirection,
497  SourceOrTarget::Enum targetDirection,
498  CoordinateTuple* sourceCoordinates,
499  Accuracy* sourceAccuracy,
500  CoordinateTuple& targetCoordinates,
501  Accuracy& targetAccuracy );
502 
503 
504  GeodeticCoordinates* convertSourceToGeodetic(
505  SourceOrTarget::Enum sourceDirection,
506  CoordinateTuple* sourceCoordinates,
507  char* sourceWarningMessage );
508 
509 
510  void convertGeodeticToTarget(
511  SourceOrTarget::Enum targetDirection,
512  GeodeticCoordinates* _shiftedGeodetic,
513  CoordinateTuple& targetCoordinates,
514  char* targetWarningMessage );
515 
516 
517  /*
518  * The function convertCollection will convert a list of source
519  * coordinates to a list of target coordinates in a single step.
520  *
521  * sourceCoordinatesCollection : Coordinates of the source coordinate system to be converted (input)
522  * sourceAccuracyCollection : Source circular, linear and spherical errors (input)
523  * targetCoordinatesCollection : Converted coordinates of the target coordinate system (output)
524  * targetAccuracyCollection : Target circular, linear and spherical errors (output)
525  */
526 
527  void convertCollection(
528  const std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinatesCollection,
529  const std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection,
530  std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinatesCollection,
531  std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection );
532  };
533  }
534 }
535 
536 #endif
537 
538 
539 // CLASSIFICATION: UNCLASSIFIED
const int COORD_SYS_CODE_LENGTH
const int COORD_SYS_NAME_LENGTH
const int ELLIPSOID_NAME_LENGTH
const int ELLIPSOID_CODE_LENGTH