~ubuntu-branches/ubuntu/wily/geotranz/wily

« back to all changes in this revision

Viewing changes to .pc/002-gxx-4-changes.patch/GEOTRANS3/java_gui/geotrans3/jni/fiomeths.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Roberto Lumbreras
  • Date: 2011-03-06 21:06:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110306210609-tsvzx88vdmpgc7u4
Tags: 3.1-1
* New upstream version.
* Added debian/make-orig-tar-bz2 to repackage the upstream .tgz easily.
* Dropped 005-openjdk-forms.patch, it didn't work well in all systems.
* Renamed libgeotranz3 to libgeotranz3.1 because of ABI changes.
* Added symbols64 file for alpha, s390 and 64bit architectures.
  (Closes: #609504)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// CLASSIFICATION: UNCLASSIFIED
 
2
 
 
3
/***************************************************************************/
 
4
/* RSC IDENTIFIER: FIOMETHS
 
5
 *
 
6
 * ABSTRACT
 
7
 *
 
8
 *    This component provides file processing capability to MSPCCS.
 
9
 *
 
10
 *    This component depends on the following modules:  Coordinate Conversion Service,
 
11
 *    ERRHAND, COMPHACK, FTOVAL, STRTOVAL.
 
12
 *
 
13
 * ERROR HANDLING
 
14
 *
 
15
 *    This component checks for errors in the file input data and if
 
16
 *    an error is found it passes an error code back to the calling routine.
 
17
 *
 
18
 *
 
19
 * REUSE NOTES
 
20
 *
 
21
 *    FIOMETHS is not specifically intended for reuse, as it is designed
 
22
 *    to work with files of a very specific format.
 
23
 *
 
24
 *
 
25
 * REFERENCES
 
26
 *
 
27
 *    Further information on FIOMETHS can be found in the MSPCCS Programmer's
 
28
 *    Guide.
 
29
 *
 
30
 *    FIOMETHS originated from :  U.S. Army Topographic Engineering Center
 
31
 *                             Digital Concepts & Analysis Center
 
32
 *                             7701 Telegraph Road
 
33
 *                             Alexandria, VA  22310-3864
 
34
 *
 
35
 * LICENSES
 
36
 *
 
37
 *    None apply to this component.
 
38
 *
 
39
 * RESTRICTIONS
 
40
 *
 
41
 *    FIOMETHS has no restrictions.
 
42
 *
 
43
 * ENVIRONMENT
 
44
 *
 
45
 *    FIOMETHS was tested and certified in the following environments:
 
46
 *
 
47
 *    1. Solaris 2.5 with GCC, version 2.7.2.1
 
48
 *    2. Windows XP with MS Visual C++, version 6
 
49
 *
 
50
 * MODIFICATIONS
 
51
 *
 
52
 *    Date              Description
 
53
 *    ----              -----------
 
54
 *    04-22-97          Original Code
 
55
 *    06-28-99          Added new DT&CC Modules
 
56
 *    09-13-00          Added new DT&CC Modules
 
57
 *    03-29-01          Improved file formatting flexibility
 
58
 *    08-17-05          Changed Lambert_Conformal_Conic to CoordinateType::lambertConformalConic2Parallels
 
59
 *    01-18-06          Added changes for new height types
 
60
 *    04-18-07          Updated to use C++ MSPCCS
 
61
 *    05-12-10          S. Gillis, BAEts26542, MSP TS MSL-HAW conversion
 
62
 *                      should use CCS
 
63
 */
 
64
 
 
65
 
 
66
/***************************************************************************/
 
67
 
 
68
/*                              INCLUDES                                 */
 
69
#include <string.h>
 
70
#include <stdio.h>
 
71
#include <ctype.h>
 
72
#include <math.h>
 
73
#include <time.h>
 
74
#include "fiomeths.h"
 
75
#include "CoordinateConversionService.h"
 
76
#include "DatumLibrary.h"
 
77
#include "EllipsoidLibrary.h"
 
78
#include "CoordinateSystemParameters.h"
 
79
#include "EquidistantCylindricalParameters.h"
 
80
#include "GeodeticParameters.h"
 
81
#include "LocalCartesianParameters.h"
 
82
#include "MapProjection3Parameters.h"
 
83
#include "MapProjection4Parameters.h"
 
84
#include "MapProjection5Parameters.h"
 
85
#include "MapProjection6Parameters.h"
 
86
#include "MercatorStandardParallelParameters.h"
 
87
#include "MercatorScaleFactorParameters.h"
 
88
#include "NeysParameters.h"
 
89
#include "ObliqueMercatorParameters.h"
 
90
#include "PolarStereographicStandardParallelParameters.h"
 
91
#include "PolarStereographicScaleFactorParameters.h"
 
92
#include "UTMParameters.h"
 
93
#include "BNGCoordinates.h"
 
94
#include "CartesianCoordinates.h"
 
95
#include "GARSCoordinates.h"
 
96
#include "GeodeticCoordinates.h"
 
97
#include "GEOREFCoordinates.h"
 
98
#include "MapProjectionCoordinates.h"
 
99
#include "MGRSorUSNGCoordinates.h"
 
100
#include "UPSCoordinates.h"
 
101
#include "UTMCoordinates.h"
 
102
#include "HeightType.h"
 
103
#include "strtoval.h"
 
104
#include "Accuracy.h"
 
105
#include "CoordinateConversionException.h"
 
106
 
 
107
 
 
108
#define PI    3.14159265358979323e0  /* PI        */
 
109
#define PI_Over_180  PI / 180.0  /* PI        */
 
110
 
 
111
 
 
112
using namespace MSP::CCS;
 
113
 
 
114
 
 
115
class FileErrorMessages
 
116
{
 
117
 
 
118
public:
 
119
 
 
120
  static char* fileOpenError;
 
121
  static char* fileCreateError;
 
122
  static char* fileHeaderWriteError;
 
123
  static char* errorParsingFile;
 
124
  static char* invalidSourceCoordinateSystem;
 
125
  static char* invalidTargetCoordinateSystem;
 
126
  static char* invalidTargetParameters;
 
127
  static char* invalidTargetCoordinates;
 
128
};
 
129
 
 
130
char* FileErrorMessages::fileOpenError = "Input file: error opening file\n";
 
131
char* FileErrorMessages::fileCreateError = "Output file: error creating file\n";
 
132
char* FileErrorMessages::fileHeaderWriteError = "Output file: error writing header to file\n";
 
133
char* FileErrorMessages::errorParsingFile = "Error reading input file coordinates\n";
 
134
char* FileErrorMessages::invalidSourceCoordinateSystem = "Input file: Invalid source coordinate system\n";
 
135
char* FileErrorMessages::invalidTargetCoordinateSystem = "Output file: Invalid target coordinate system\n";
 
136
char* FileErrorMessages::invalidTargetParameters = "Output file: Target parameters invalid for target coordinate system type\n";
 
137
char* FileErrorMessages::invalidTargetCoordinates = "Output file: Target coordinates invalid for target coordinate system type\n";
 
138
 
 
139
 
 
140
/* Local variable definitions */
 
141
 
 
142
typedef enum File_Header_Declarations
 
143
{
 
144
  FHD_End_of_Header = 0,        /* End of header */
 
145
  FHD_Header,                   /* Header */
 
146
  FHD_Comment,                  /* Separator/Comment */
 
147
  FHD_Projection,               /* Coordinate System, Grid, or Projection */
 
148
  FHD_Datum,                    /* Datum */
 
149
  FHD_No_Height,                /* No Height */
 
150
  FHD_Ellipsoid_Height,         /* Ellipsoid Height */
 
151
  FHD_MSL_EGM96_15M_BL_Height,  /* MSL EGM96 15M BL Height */
 
152
  FHD_MSL_EGM96_VG_NS_Height,   /* MSL EGM96 VG NS Height */
 
153
  FHD_MSL_EGM84_10D_BL_Height,  /* MSL EGM84 10D BL Height */
 
154
  FHD_MSL_EGM84_10D_NS_Height,  /* MSL EGM84 10D NS Height */
 
155
  FHD_MSL_EGM84_30M_BL_Height,  /* MSL EGM84 30M BL Height */
 
156
  FHD_Central_Meridian,         /* Central Meridian */
 
157
  FHD_Origin_Latitude,          /* Origin Latitude */
 
158
  FHD_Origin_Longitude,         /* Origin Longitude */
 
159
  FHD_Latitude_of_True_Scale,   /* Latitude of True Scale */
 
160
  FHD_Longitude_Down_from_Pole, /* Longitude Down from Pole */
 
161
  FHD_Latitude_One,             /* Latitude One */
 
162
  FHD_Longitude_One,            /* Longitude One */
 
163
  FHD_Latitude_Two,             /* Latitude Two */
 
164
  FHD_Longitude_Two,            /* Longitude Two */
 
165
  FHD_Origin_Height,            /* Origin Height */
 
166
  FHD_Orientation,              /* Orientation */
 
167
  FHD_Standard_Parallel,        /* Standard Parallel  */
 
168
  FHD_Standard_Parallel_One,    /* Standard Parallel One */
 
169
  FHD_Standard_Parallel_Two,    /* Standard Parallel Two */
 
170
  FHD_Hemisphere,               /* Hemisphere: 'N' or 'S'  */
 
171
  FHD_False_Easting,            /* False Easting */
 
172
  FHD_False_Northing,           /* False Northing */
 
173
  FHD_Scale_Factor,             /* Scale Factor */
 
174
  FHD_Coordinate_Order,         /* Order of Geodetic coordinates: LATITUDE-LONGITUDE or LONGITUDE-LATITUDE */
 
175
  FHD_Invalid_Header
 
176
} FHD_Value;
 
177
 
 
178
 
 
179
/* File processing error conditions */
 
180
typedef enum File_Input_and_Output_Conversion_Status
 
181
{
 
182
  /* Success */
 
183
  FIO_Success = 0,
 
184
  FIO_Error_Reading_File = -11,
 
185
  FIO_Error_Writing_File = -12,
 
186
  FIO_Error_Parsing_Header = -13,
 
187
  FIO_Error_Parsing_String = -14,
 
188
  FIO_Error_Parsing_File = -15,
 
189
  FIO_Error_Writing_Header = -16,
 
190
  FIO_EOFile = -17,
 
191
  FIO_Error_Latitude_of_True_Scale = -18,
 
192
  FIO_Error_Longitude_Down_from_Pole = -19,
 
193
  FIO_Error_Projection = -20,
 
194
  FIO_Error_Datum = -21,
 
195
  FIO_Error_Central_Meridian = -22,
 
196
  FIO_Error_Origin_Latitude = -23,
 
197
  FIO_Error_Origin_Longitude = -24,
 
198
  FIO_Error_Origin_Height = -25,
 
199
  FIO_Error_Orientation = -26,
 
200
  FIO_Error_Latitude_One = -27,
 
201
  FIO_Error_Longitude_One = -28,
 
202
  FIO_Error_Latitude_Two = -29,
 
203
  FIO_Error_Longitude_Two = -30,
 
204
  FIO_Error_Standard_Parallel = -31,
 
205
  FIO_Error_Standard_Parallel_One = -32,
 
206
  FIO_Error_Standard_Parallel_Two = -33,
 
207
  FIO_Error_False_Easting = -34,
 
208
  FIO_Error_False_Northing = -35,
 
209
  FIO_Error_Scale_Factor = -36,
 
210
  FIO_Error_Label = -37,
 
211
  FIO_Error_Hemisphere = -38,
 
212
  FIO_Error_Coordinate_Order = -39,
 
213
  /* General error */
 
214
  FIO_Error = -1000
 
215
} FIO_Status;
 
216
 
 
217
typedef enum File_to_Value_Conversion_Status
 
218
{
 
219
  /* Success */
 
220
  FVC_Success = 0,
 
221
  /* File_to_Longitude errors */
 
222
  FVC_Degrees_out_of_Bounds = -11,
 
223
  FVC_Minutes_out_of_Bounds = -12,
 
224
  FVC_Seconds_out_of_Bounds = -13,
 
225
  FVC_Minutes_or_Seconds_Overflow = -14,
 
226
  FVC_Inappropriate_Hemisphere = -15,
 
227
  FVC_Sign_and_Hemisphere = -16,
 
228
  FVC_Misplaced_Hemisphere = -17,
 
229
  FVC_File_Read_Longitude = -18,
 
230
  FVC_File_Read_Latitude = -19,
 
231
  FVC_File_Read_Hemisphere = -20,
 
232
  /* <Degrees>_to_File errors */
 
233
  FVC_DMS_to_File = -21,
 
234
  FVC_DM_to_File = -22,
 
235
  FVC_D_to_File = -23,
 
236
  FVC_File_Write_Longitude = -24,
 
237
  FVC_File_Write_Latitude = -25,
 
238
  /* <Parameter>_to_File errors */
 
239
  /* Parameter Specific errors */
 
240
  FVC_Zone_out_of_Bounds = -71,
 
241
  FVC_Scale_Factor_out_of_Bounds = -72,
 
242
  /* File errors */
 
243
  FVC_Error_Opening_File = -501,
 
244
  FVC_Error_Closing_File = -502,
 
245
  FVC_Error_Writing_String = -503,
 
246
  FVC_Error_Reading_Noise = -504,
 
247
  FVC_Error_Parsing_Header = -505,
 
248
  FVC_Invalid_Header = -506,
 
249
  FVC_Error_Parsing_File = -507,
 
250
  FVC_EOF = -508,
 
251
  /* General error */
 
252
  FVC_Error = -1000
 
253
} FVC_Status;
 
254
 
 
255
const char* LATITUDE_LONGITUDE = "LATITUDE-LONGITUDE";
 
256
const char* LONGITUDE_LATITUDE = "LONGITUDE-LATITUDE";
 
257
 
 
258
const char* coordinates_Header_String = "COORDINATES";
 
259
const char* projection_Header_String = "PROJECTION";
 
260
const char* datum_Header_String = "DATUM";
 
261
const char* no_Height_Header_String = "NO HEIGHT";
 
262
const char* ellipsoid_Height_Header_String = "ELLIPSOID HEIGHT";
 
263
const char* geoid_Height_Header_String = "GEOID/MSL HEIGHT";
 
264
const char* msl_EGM96_15M_BL_Height_Header_String = "MSL-EGM96-15M-BL HEIGHT";
 
265
const char* msl_EGM96_VG_NS_Height_Header_String = "MSL-EGM96-VG-NS HEIGHT";
 
266
const char* msl_EGM84_10D_BL_Height_Header_String = "MSL-EGM84-10D-BL HEIGHT";
 
267
const char* msl_EGM84_10D_NS_Height_Header_String = "MSL-EGM84-10D-NS HEIGHT";
 
268
const char* msl_EGM84_30M_BL_Height_Header_String = "MSL-EGM84-30M-BL HEIGHT";
 
269
const char* central_Meridian_Header_String = "CENTRAL MERIDIAN";
 
270
const char* origin_Latitude_Header_String = "ORIGIN LATITUDE";
 
271
const char* origin_Longitude_Header_String = "ORIGIN LONGITUDE";
 
272
const char* lat_Of_True_Scale_Header_String = "LATITUDE OF TRUE SCALE";
 
273
const char* polarst_Longitude_Header_String = "LONGITUDE DOWN FROM POLE";
 
274
const char* latitude_One_Header_String = "LATITUDE ONE";
 
275
const char* longitude_One_Header_String = "LONGITUDE ONE";
 
276
const char* latitude_Two_Header_String = "LATITUDE TWO";
 
277
const char* longitude_Two_Header_String = "LONGITUDE TWO";
 
278
const char* origin_Height_Header_String = "ORIGIN HEIGHT";
 
279
const char* orientation_Header_String = "ORIENTATION";
 
280
const char* standard_Parallel_Header_String = "STANDARD PARALLEL";
 
281
const char* standard_Parallel_One_Header_String = "STANDARD PARALLEL ONE";
 
282
const char* standard_Parallel_Two_Header_String = "STANDARD PARALLEL TWO";
 
283
const char* scale_Factor_Header_String = "SCALE FACTOR";
 
284
const char* hemisphere_Header_String = "HEMISPHERE";
 
285
const char* false_Easting_Header_String = "FALSE EASTING";
 
286
const char* false_Northing_Header_String = "FALSE NORTHING";
 
287
const char* coordinate_Order_Header_String = "COORDINATE ORDER";
 
288
const char* header_String = "HEADER";
 
289
const char* end_Of_Header_String = "END OF HEADER";
 
290
const char* ce90_String = "CE90";
 
291
const char* le90_String = "LE90";
 
292
const char* se90_String = "SE90";
 
293
 
 
294
 
 
295
 
 
296
/************************************************************************/
 
297
/*                              LOCAL FUNCTIONS     
 
298
 *
 
299
 */
 
300
 
 
301
FVC_Status Open_File(SourceOrTarget::Enum IOValue, const char *filename, FILE **file)
 
302
{ /* Open_File */
 
303
  FVC_Status error_Code = FVC_Success;
 
304
  char *control_String = "r";
 
305
  FILE *local_File = NULL;
 
306
  if (IOValue == SourceOrTarget::source)
 
307
    control_String = "r";
 
308
  else if (IOValue == SourceOrTarget::target)
 
309
    control_String = "w";
 
310
  local_File = fopen(filename, control_String);
 
311
  if (local_File)
 
312
    *file = local_File;
 
313
  else
 
314
  {
 
315
    error_Code = FVC_Error_Opening_File;
 
316
    *file = NULL;
 
317
  }
 
318
  return error_Code;
 
319
} /* Open_File */
 
320
 
 
321
 
 
322
FVC_Status Close_File(FILE **file)
 
323
{ /* Close_File  */
 
324
  FVC_Status error_Code = FVC_Success;
 
325
  if (*file != NULL)
 
326
  {
 
327
    fclose(*file);
 
328
    *file = NULL;
 
329
  }
 
330
  return error_Code;
 
331
} /* Close_File */
 
332
 
 
333
 
 
334
FVC_Status Eat_Noise(FILE *file)
 
335
{ /* Eat_Noise */
 
336
  char noise[256] = "";
 
337
  if ((fscanf(file, "%255[:, \n\r\t]", noise) == 0) && feof(file))
 
338
    return FVC_EOF;
 
339
  return FVC_Success;
 
340
} /* Eat_Noise */
 
341
 
 
342
 
 
343
FVC_Status Next_Header_Line(FILE *file, FHD_Value *header)
 
344
{
 
345
  FVC_Status error_Code = FVC_Success;
 
346
  FHD_Value header_Line = FHD_Comment;
 
347
  int next_Character = '\0';
 
348
  char garbage_Array[512];
 
349
  while (header_Line == FHD_Comment && !error_Code)
 
350
  {
 
351
    /* eat all whitespace */
 
352
    fscanf(file, " ");
 
353
    next_Character = fgetc(file);
 
354
    if (next_Character == '#')
 
355
      fgets(garbage_Array, 511, file);
 
356
    else
 
357
    {
 
358
      if (ungetc(next_Character, file) != next_Character)
 
359
        error_Code = FVC_Error_Parsing_Header;
 
360
      else
 
361
      {
 
362
        int i, length;
 
363
        char header_Value[32] = "";
 
364
        long ftell_Location = ftell(file);
 
365
        fscanf(file, "%31[^:\n]", header_Value);
 
366
        length = strlen(header_Value);
 
367
        for (i = 0; i < length; i++)
 
368
          header_Value[i] = (char)toupper(header_Value[i]);
 
369
 
 
370
        if (strstr(header_Value, projection_Header_String) ||
 
371
            strstr(header_Value, coordinates_Header_String))
 
372
          header_Line = FHD_Projection;
 
373
        else if (strstr(header_Value, datum_Header_String))
 
374
          header_Line = FHD_Datum;
 
375
        else if (strstr(header_Value, no_Height_Header_String))
 
376
          header_Line = FHD_No_Height;
 
377
        else if (strstr(header_Value, ellipsoid_Height_Header_String))
 
378
          header_Line = FHD_Ellipsoid_Height;
 
379
        else if (strstr(header_Value, geoid_Height_Header_String))
 
380
          header_Line = FHD_MSL_EGM96_15M_BL_Height;
 
381
        else if (strstr(header_Value, msl_EGM96_15M_BL_Height_Header_String))
 
382
          header_Line = FHD_MSL_EGM96_15M_BL_Height;
 
383
        else if (strstr(header_Value, msl_EGM96_VG_NS_Height_Header_String))
 
384
          header_Line = FHD_MSL_EGM96_VG_NS_Height;
 
385
        else if (strstr(header_Value, msl_EGM84_10D_BL_Height_Header_String))
 
386
          header_Line = FHD_MSL_EGM84_10D_BL_Height;
 
387
        else if (strstr(header_Value, msl_EGM84_10D_NS_Height_Header_String))
 
388
          header_Line = FHD_MSL_EGM84_10D_NS_Height;
 
389
        else if (strstr(header_Value, msl_EGM84_30M_BL_Height_Header_String))
 
390
          header_Line = FHD_MSL_EGM84_30M_BL_Height;
 
391
        else if (strstr(header_Value, central_Meridian_Header_String))
 
392
          header_Line = FHD_Central_Meridian;
 
393
        else if (strstr(header_Value, lat_Of_True_Scale_Header_String))
 
394
          header_Line = FHD_Latitude_of_True_Scale;
 
395
        else if (strstr(header_Value, polarst_Longitude_Header_String))
 
396
          header_Line = FHD_Longitude_Down_from_Pole;
 
397
        else if (strstr(header_Value, origin_Latitude_Header_String))
 
398
          header_Line = FHD_Origin_Latitude;
 
399
        else if (strstr(header_Value, origin_Longitude_Header_String))
 
400
          header_Line = FHD_Origin_Longitude;
 
401
        else if (strstr(header_Value, origin_Height_Header_String))
 
402
          header_Line = FHD_Origin_Height;
 
403
        else if (strstr(header_Value, orientation_Header_String))
 
404
          header_Line = FHD_Orientation;
 
405
        else if (strstr(header_Value, latitude_One_Header_String))
 
406
          header_Line = FHD_Latitude_One;
 
407
        else if (strstr(header_Value, longitude_One_Header_String))
 
408
          header_Line = FHD_Longitude_One;
 
409
        else if (strstr(header_Value, latitude_Two_Header_String))
 
410
          header_Line = FHD_Latitude_Two;
 
411
        else if (strstr(header_Value, longitude_Two_Header_String))
 
412
          header_Line = FHD_Longitude_Two;
 
413
        else if (strstr(header_Value, standard_Parallel_One_Header_String))
 
414
          header_Line = FHD_Standard_Parallel_One;
 
415
        else if (strstr(header_Value, standard_Parallel_Two_Header_String))
 
416
          header_Line = FHD_Standard_Parallel_Two;
 
417
        else if (strstr(header_Value, standard_Parallel_Header_String))
 
418
          header_Line = FHD_Standard_Parallel;
 
419
        else if (strstr(header_Value, scale_Factor_Header_String))
 
420
          header_Line = FHD_Scale_Factor;
 
421
        else if (strstr(header_Value, hemisphere_Header_String))
 
422
          header_Line = FHD_Hemisphere;
 
423
        else if (strstr(header_Value, false_Easting_Header_String))
 
424
          header_Line = FHD_False_Easting;
 
425
        else if (strstr(header_Value, false_Northing_Header_String))
 
426
          header_Line = FHD_False_Northing;
 
427
        else if (strstr(header_Value, coordinate_Order_Header_String))
 
428
          header_Line = FHD_Coordinate_Order;
 
429
        else if (strstr(header_Value, end_Of_Header_String))
 
430
          header_Line = FHD_End_of_Header;
 
431
        else if (strstr(header_Value, header_String))
 
432
          header_Line = FHD_Header;
 
433
        else
 
434
        {
 
435
          error_Code = FVC_Invalid_Header;
 
436
          header_Line = FHD_Invalid_Header;
 
437
          fseek(file, ftell_Location, SEEK_SET);
 
438
        }
 
439
        Eat_Noise(file);
 
440
      }
 
441
    }
 
442
  }
 
443
  *header = header_Line;
 
444
  return error_Code;
 
445
}
 
446
 
 
447
 
 
448
FVC_Status Output_String(FILE *file, const char *sequence)
 
449
{/* BEGIN Output_String */
 
450
  FVC_Status error_Code = FVC_Success;
 
451
  if (fprintf(file, "%s", sequence) <= 0)
 
452
    error_Code = FVC_Error_Writing_String;
 
453
  return error_Code;
 
454
}/* END Output_String */
 
455
 
 
456
 
 
457
FVC_Status Output_Newline(FILE *file)
 
458
{
 
459
  static const char *newline_Sequence = "\n";
 
460
  return Output_String(file, newline_Sequence);
 
461
}
 
462
 
 
463
 
 
464
char* remove_trailing_spaces( char* str )
 
465
{
 
466
  int length = strlen( str );
 
467
  int index = length - 1;
 
468
 
 
469
  while( str[index] == ' ' )
 
470
    index --;
 
471
 
 
472
  str[index + 1] = '\0';
 
473
 
 
474
  return str;
 
475
}
 
476
 
 
477
 
 
478
 
 
479
/************************************************************************/
 
480
/*                             PUBLIC FUNCTIONS     
 
481
 *
 
482
 */
 
483
 
 
484
Fiomeths::Fiomeths() :
 
485
  coordinateConversionService( 0 ),
 
486
  inputFile( 0 ),
 
487
  outputFile( 0 ),
 
488
  sourceProjectionType( CoordinateType::geodetic ),
 
489
  targetProjectionType( CoordinateType::geodetic ),
 
490
  sourceDatumCode( 0 ),
 
491
  targetDatumCode( 0 ),
 
492
  coordinateSystemParameters( 0 ),
 
493
  equidistantCylindricalParameters( 0 ),
 
494
  geodeticParameters( 0 ),
 
495
  localCartesianParameters( 0 ),
 
496
  mapProjection3Parameters( 0 ),
 
497
  mapProjection4Parameters( 0 ),
 
498
  mapProjection5Parameters( 0 ),
 
499
  mapProjection6Parameters( 0 ),
 
500
  mercatorStandardParallelParameters( 0 ),
 
501
  mercatorScaleFactorParameters( 0 ),
 
502
  neysParameters( 0 ),
 
503
  obliqueMercatorParameters( 0 ),
 
504
  polarStereographicStandardParallelParameters( 0 ),
 
505
  polarStereographicScaleFactorParameters( 0 ),
 
506
  utmParameters( 0 ),
 
507
  targetParameters( 0 ),
 
508
  _numErrors( 0 ),
 
509
  _numProcessed( 0 ),
 
510
  _numWarnings( 0 ),
 
511
  _elapsedTime( 0 ),
 
512
  invalid( -1 ),
 
513
  inputLatitudeLongitudeOrder( true ),
 
514
  outputLatitudeLongitudeOrder( true )
 
515
{
 
516
  sourceDatumCode = new char[4];
 
517
  strcpy( sourceDatumCode, "WGE" );
 
518
 
 
519
  geodeticParameters = new GeodeticParameters();
 
520
}
 
521
 
 
522
 
 
523
Fiomeths::Fiomeths( const char* fileName ) :
 
524
  coordinateConversionService( 0 ),
 
525
  inputFile( 0 ),
 
526
  outputFile( 0 ),
 
527
  sourceProjectionType( CoordinateType::geodetic ),
 
528
  targetProjectionType( CoordinateType::geodetic ),
 
529
  sourceDatumCode( 0 ),
 
530
  targetDatumCode( 0 ),
 
531
  coordinateSystemParameters( 0 ),
 
532
  equidistantCylindricalParameters( 0 ),
 
533
  geodeticParameters( 0 ),
 
534
  localCartesianParameters( 0 ),
 
535
  mapProjection3Parameters( 0 ),
 
536
  mapProjection4Parameters( 0 ),
 
537
  mapProjection5Parameters( 0 ),
 
538
  mapProjection6Parameters( 0 ),
 
539
  mercatorStandardParallelParameters( 0 ),
 
540
  mercatorScaleFactorParameters( 0 ),
 
541
  neysParameters( 0 ),
 
542
  obliqueMercatorParameters( 0 ),
 
543
  polarStereographicStandardParallelParameters( 0 ),
 
544
  polarStereographicScaleFactorParameters( 0 ),
 
545
  utmParameters( 0 ),
 
546
  targetParameters( 0 ),
 
547
  _numErrors( 0 ),
 
548
  _numProcessed( 0 ),
 
549
  _numWarnings( 0 ),
 
550
  _elapsedTime( 0 ),
 
551
  invalid( -1 ),
 
552
  inputLatitudeLongitudeOrder( true ),
 
553
  outputLatitudeLongitudeOrder( true )
 
554
{
 
555
  try
 
556
  {
 
557
    setInputFilename( fileName );
 
558
  }
 
559
  catch( CoordinateConversionException e )
 
560
  {
 
561
    throw CoordinateConversionException( e.getMessage() );
 
562
  }
 
563
}
 
564
 
 
565
 
 
566
Fiomeths::~Fiomeths()
 
567
{
 
568
  delete coordinateConversionService;
 
569
  coordinateConversionService = 0;
 
570
 
 
571
  if( sourceDatumCode )
 
572
  {
 
573
    delete [] sourceDatumCode;
 
574
    sourceDatumCode = 0;
 
575
  }
 
576
 
 
577
  if( targetDatumCode )
 
578
  {
 
579
    delete [] targetDatumCode;
 
580
    targetDatumCode = 0;
 
581
  }
 
582
 
 
583
  if( coordinateSystemParameters )
 
584
  {
 
585
    delete coordinateSystemParameters;
 
586
    coordinateSystemParameters = 0;
 
587
  }
 
588
 
 
589
  if( equidistantCylindricalParameters )
 
590
  {
 
591
    delete equidistantCylindricalParameters;
 
592
    equidistantCylindricalParameters = 0;
 
593
  }
 
594
 
 
595
  if( geodeticParameters )
 
596
  {
 
597
    delete geodeticParameters;
 
598
    geodeticParameters = 0;
 
599
  }
 
600
 
 
601
  if( localCartesianParameters )
 
602
  {
 
603
    delete localCartesianParameters;
 
604
    localCartesianParameters = 0;
 
605
  }
 
606
 
 
607
  if( mapProjection3Parameters )
 
608
  {
 
609
    delete mapProjection3Parameters;
 
610
    mapProjection3Parameters = 0;
 
611
  }
 
612
 
 
613
  if( mapProjection4Parameters )
 
614
  {
 
615
    delete mapProjection4Parameters;
 
616
    mapProjection4Parameters = 0;
 
617
  }
 
618
 
 
619
  if( mapProjection5Parameters )
 
620
  {
 
621
    delete mapProjection5Parameters;
 
622
    mapProjection5Parameters = 0;
 
623
  }
 
624
 
 
625
  if( mapProjection6Parameters )
 
626
  {
 
627
    delete mapProjection6Parameters;
 
628
    mapProjection6Parameters = 0;
 
629
  }
 
630
 
 
631
  if( mercatorStandardParallelParameters )
 
632
  {
 
633
    delete mercatorStandardParallelParameters;
 
634
    mercatorStandardParallelParameters = 0;
 
635
  }
 
636
 
 
637
  if( mercatorScaleFactorParameters )
 
638
  {
 
639
    delete mercatorScaleFactorParameters;
 
640
    mercatorScaleFactorParameters = 0;
 
641
  }
 
642
 
 
643
  if( neysParameters )
 
644
  {
 
645
    delete neysParameters;
 
646
    neysParameters = 0;
 
647
  }
 
648
 
 
649
  if( obliqueMercatorParameters )
 
650
  {
 
651
    delete obliqueMercatorParameters;
 
652
    obliqueMercatorParameters = 0;
 
653
  }
 
654
 
 
655
  if( polarStereographicStandardParallelParameters )
 
656
  {
 
657
    delete polarStereographicStandardParallelParameters;
 
658
    polarStereographicStandardParallelParameters = 0;
 
659
  }
 
660
 
 
661
  if( polarStereographicScaleFactorParameters )
 
662
  {
 
663
    delete polarStereographicScaleFactorParameters;
 
664
    polarStereographicScaleFactorParameters = 0;
 
665
  }
 
666
 
 
667
  if( utmParameters )
 
668
  {
 
669
    delete utmParameters;
 
670
    utmParameters = 0;
 
671
  }
 
672
 
 
673
 
 
674
  delete targetParameters;
 
675
  targetParameters = 0;
 
676
}
 
677
 
 
678
 
 
679
void Fiomeths::setOutputFilename( const char *filename, const char* _targetDatumCode, CoordinateSystemParameters* _targetParameters )
 
680
{
 
681
  targetDatumCode = new char[ strlen( _targetDatumCode ) + 1 ];
 
682
  strcpy( targetDatumCode, _targetDatumCode );
 
683
 
 
684
  setCoordinateSystemParameters( _targetParameters );
 
685
 
 
686
  FIO_Status error_Code = FIO_Success;
 
687
  FVC_Status error_Code_File = FVC_Success;
 
688
 
 
689
  if (outputFile != NULL)
 
690
    closeOutputFile();
 
691
 
 
692
  error_Code_File = Open_File( SourceOrTarget::target, filename, &outputFile );
 
693
 
 
694
  if (!error_Code_File)
 
695
  {
 
696
    coordinateConversionService = new CoordinateConversionService( sourceDatumCode, getCoordinateSystemParameters(), _targetDatumCode, _targetParameters );
 
697
 
 
698
    writeOutputFileHeader( _targetDatumCode, _targetParameters );
 
699
  }
 
700
  else
 
701
    throw CoordinateConversionException( FileErrorMessages::fileCreateError );
 
702
 
 
703
}
 
704
 
 
705
 
 
706
void Fiomeths::convertFile()
 
707
{
 
708
  std::vector<MSP::CCS::CoordinateTuple*> sourceCoordinateCollection;
 
709
  std::vector<MSP::CCS::Accuracy*> sourceAccuracyCollection;
 
710
  std::vector<TrailingHeight> trailingHeightCollection;
 
711
  std::vector<CoordinateTuple*> targetCoordinateCollection;
 
712
  std::vector<Accuracy*> targetAccuracyCollection;
 
713
 
 
714
  FIO_Status error_Code = FIO_Success;
 
715
  long tempErrorCode = 0;
 
716
  char next_Character;
 
717
  char Comment[256] = "";
 
718
 
 
719
  char next_Letters[7];
 
720
  long position;
 
721
  long coordinate = 1;
 
722
 
 
723
  while (!feof(inputFile))
 
724
  {
 
725
    CoordinateTuple* sourceCoordinate = 0;
 
726
    Accuracy* sourceAccuracy = 0;
 
727
    TrailingHeight trailingHeight;
 
728
    trailingHeight.heightPresent = false;
 
729
    Accuracy* targetAccuracy = new Accuracy();
 
730
 
 
731
    next_Character = (char)fgetc(inputFile);
 
732
    ungetc(next_Character, inputFile);
 
733
    if (next_Character == '#')
 
734
    {
 
735
      fgets(Comment, 255, inputFile);
 
736
      sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
737
      sourceCoordinate->setErrorMessage( Comment );
 
738
      coordinate = 0;
 
739
    }
 
740
    else if (next_Character == '\n')
 
741
    {
 
742
      fgetc(inputFile);
 
743
      sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
744
      sourceCoordinate->setErrorMessage( "\n" );
 
745
      coordinate = 0;
 
746
    }
 
747
    else if (next_Character == '\r')
 
748
    {
 
749
      fgetc(inputFile);
 
750
      sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
751
      sourceCoordinate->setErrorMessage( "\r" );
 
752
      coordinate = 0;
 
753
    }
 
754
    else if (next_Character == 'H')
 
755
    {
 
756
      position = ftell(inputFile);
 
757
      fgets(next_Letters, 7, inputFile);
 
758
      if (strcmp(next_Letters, "HEADER") == 0)
 
759
      {
 
760
        convert( sourceCoordinateCollection, sourceAccuracyCollection, trailingHeightCollection, targetCoordinateCollection, targetAccuracyCollection );
 
761
        long errorCode = parseInputFileHeader(inputFile);
 
762
        if( errorCode )
 
763
        {
 
764
          char errorStr[256];
 
765
          getFileErrorString( errorCode, errorStr ); 
 
766
          closeInputFile();
 
767
          throw CoordinateConversionException( errorStr );
 
768
        }
 
769
        CoordinateConversionService* tempCoordinateConversionService = new CoordinateConversionService( sourceDatumCode, getCoordinateSystemParameters(), targetDatumCode, targetParameters );
 
770
        if( coordinateConversionService )
 
771
          delete coordinateConversionService;
 
772
        coordinateConversionService = tempCoordinateConversionService;
 
773
        sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
774
        coordinate = 0;
 
775
      }
 
776
      else
 
777
      {
 
778
        fseek(inputFile, position, 0);
 
779
        fputs(next_Letters, inputFile);
 
780
        coordinate = 1;
 
781
      }
 
782
    }
 
783
    else if (feof(inputFile))
 
784
    {
 
785
      sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
786
      coordinate = 0;
 
787
    }
 
788
    else
 
789
      coordinate = 1;
 
790
 
 
791
    if( coordinate )
 
792
    {
 
793
      // Read source coordinate values
 
794
      try
 
795
      {
 
796
        sourceCoordinate = readCoordinate();
 
797
 
 
798
        if( readHeight( trailingHeight.height ) == 0 )
 
799
          trailingHeight.heightPresent = true;
 
800
 
 
801
        // Read source accuracy values if given
 
802
        char buf[256] = "";
 
803
        fscanf(inputFile, "%[^\n#]", buf);
 
804
        if(strstr(buf, ce90_String) && strstr(buf, le90_String) && strstr(buf, se90_String))
 
805
        {
 
806
          Accuracy* tempSourceAccuracy = readConversionErrors(buf);
 
807
          sourceAccuracy = new Accuracy( tempSourceAccuracy->circularError90(), tempSourceAccuracy->linearError90(), tempSourceAccuracy->sphericalError90() );
 
808
          delete tempSourceAccuracy;
 
809
          tempSourceAccuracy = 0;
 
810
        }
 
811
        else
 
812
          sourceAccuracy = new Accuracy();
 
813
 
 
814
        // Store any trailing comments on the coordinate line
 
815
        fgets(Comment, 255, inputFile);
 
816
        if(Comment[0] != '\n')
 
817
          sourceCoordinate->setErrorMessage( Comment );
 
818
      }
 
819
      catch(CoordinateConversionException e)
 
820
      {
 
821
        fgets(Comment, 255, inputFile);
 
822
        sourceCoordinate = new CoordinateTuple( ( CoordinateType::Enum )invalid );
 
823
        sourceCoordinate->setErrorMessage( "# Error reading coordinates from input file\n");
 
824
        _numErrors ++;
 
825
 
 
826
      }
 
827
 
 
828
      _numProcessed++;
 
829
 
 
830
    }
 
831
 
 
832
    CoordinateTuple* targetCoordinate = initTargetCoordinate();
 
833
 
 
834
    sourceCoordinateCollection.push_back( sourceCoordinate );
 
835
    sourceAccuracyCollection.push_back( sourceAccuracy );
 
836
    trailingHeightCollection.push_back( trailingHeight );
 
837
    targetCoordinateCollection.push_back( targetCoordinate );
 
838
    targetAccuracyCollection.push_back( targetAccuracy );
 
839
  }
 
840
 
 
841
  convert( sourceCoordinateCollection, sourceAccuracyCollection, trailingHeightCollection, targetCoordinateCollection, targetAccuracyCollection );
 
842
 
 
843
  closeInputFile();
 
844
  closeOutputFile();
 
845
}
 
846
 
 
847
 
 
848
void Fiomeths::closeInputFile()
 
849
{
 
850
  if (inputFile != NULL)
 
851
    Close_File(&inputFile);
 
852
}
 
853
 
 
854
 
 
855
void Fiomeths::closeOutputFile()
 
856
{
 
857
  if (outputFile != NULL)
 
858
    Close_File(&outputFile);
 
859
}
 
860
 
 
861
 
 
862
const char* Fiomeths::getDatumCode() const
 
863
{
 
864
/*
 
865
 *  The function getDatumCode returns the code of the current datum
 
866
 */
 
867
 
 
868
  return sourceDatumCode;
 
869
}
 
870
 
 
871
 
 
872
/**
 
873
 * Returns the input coordinate system parameters. 
 
874
 *
 
875
 * @return    coordinate system parameters contained in the header of the input file
 
876
 * @throws   CoordinateConversionException    invalid coordinate system
 
877
 */
 
878
CoordinateSystemParameters* Fiomeths::getCoordinateSystemParameters() const
 
879
{
 
880
  switch(sourceProjectionType)
 
881
  {
 
882
    case CoordinateType::albersEqualAreaConic:
 
883
    case CoordinateType::lambertConformalConic2Parallels:
 
884
      return mapProjection6Parameters;
 
885
    case CoordinateType::azimuthalEquidistant:
 
886
    case CoordinateType::bonne:
 
887
    case CoordinateType::cassini:
 
888
    case CoordinateType::cylindricalEqualArea:
 
889
    case CoordinateType::gnomonic:
 
890
    case CoordinateType::orthographic:
 
891
    case CoordinateType::polyconic:
 
892
    case CoordinateType::stereographic:
 
893
      return mapProjection4Parameters;
 
894
    case CoordinateType::britishNationalGrid:
 
895
    case CoordinateType::globalAreaReferenceSystem:
 
896
    case CoordinateType::geocentric:
 
897
    case CoordinateType::georef:
 
898
    case CoordinateType::militaryGridReferenceSystem:
 
899
    case CoordinateType::newZealandMapGrid:
 
900
    case CoordinateType::universalPolarStereographic:
 
901
    case CoordinateType::usNationalGrid:
 
902
     return coordinateSystemParameters;
 
903
    case CoordinateType::eckert4:
 
904
    case CoordinateType::eckert6:
 
905
    case CoordinateType::millerCylindrical:
 
906
    case CoordinateType::mollweide:
 
907
    case CoordinateType::sinusoidal:
 
908
    case CoordinateType::vanDerGrinten:
 
909
      return mapProjection3Parameters;
 
910
    case CoordinateType::equidistantCylindrical:
 
911
      return equidistantCylindricalParameters;
 
912
    case CoordinateType::geodetic:
 
913
      return geodeticParameters;
 
914
    case CoordinateType::localCartesian:
 
915
      return localCartesianParameters;
 
916
    case CoordinateType::mercatorStandardParallel:
 
917
      return mercatorStandardParallelParameters;
 
918
    case CoordinateType::mercatorScaleFactor:
 
919
      return mercatorScaleFactorParameters;
 
920
    case CoordinateType::lambertConformalConic1Parallel:
 
921
    case CoordinateType::transverseCylindricalEqualArea:
 
922
    case CoordinateType::transverseMercator:
 
923
      return mapProjection5Parameters;
 
924
    case CoordinateType::neys:
 
925
      return neysParameters;
 
926
    case CoordinateType::obliqueMercator:
 
927
      return obliqueMercatorParameters;
 
928
    case CoordinateType::polarStereographicStandardParallel:
 
929
      return polarStereographicStandardParallelParameters;
 
930
    case CoordinateType::polarStereographicScaleFactor:
 
931
      return polarStereographicScaleFactorParameters;
 
932
    case CoordinateType::universalTransverseMercator:
 
933
      return utmParameters;
 
934
    default:
 
935
      throw CoordinateConversionException( FileErrorMessages::invalidSourceCoordinateSystem );
 
936
  }
 
937
}
 
938
 
 
939
 
 
940
long Fiomeths::getNumErrors() const
 
941
{
 
942
  return _numErrors;
 
943
}
 
944
 
 
945
 
 
946
long Fiomeths::getNumProcessed() const
 
947
{
 
948
  return _numProcessed;
 
949
}
 
950
 
 
951
 
 
952
long Fiomeths::getNumWarnings() const
 
953
{
 
954
  return _numWarnings;
 
955
}
 
956
 
 
957
 
 
958
double Fiomeths::getElapsedTime() const
 
959
{
 
960
  return _elapsedTime;
 
961
}
 
962
 
 
963
 
 
964
void Fiomeths::setUseNSEW(bool value)
 
965
{
 
966
  _useNSEW = value;
 
967
}
 
968
 
 
969
 
 
970
/*boole Get_Use_NSEW()
 
971
{
 
972
  return (_useNSEW);
 
973
}*/
 
974
 
 
975
void Fiomeths::setUseMinutes(bool value)
 
976
{
 
977
  _useMinutes = value;
 
978
}
 
979
 
 
980
 
 
981
/*boole Get_Use_Minutes()
 
982
{
 
983
  return (_useMinutes);
 
984
}*/
 
985
 
 
986
 
 
987
void Fiomeths::setUseSeconds(bool value)
 
988
{
 
989
  _useSeconds = value;
 
990
}
 
991
 
 
992
 
 
993
/*boole Get_Use_Seconds()
 
994
{
 
995
  return (_useSeconds);
 
996
}*/
 
997
 
 
998
 
 
999
void Fiomeths::setLatLongPrecision(int _precision)
 
1000
{
 
1001
  Set_Lat_Long_Precision((Precision::Enum)_precision);
 
1002
}
 
1003
 
 
1004
 
 
1005
void Fiomeths::setGeodeticCoordinateOrder(bool _outputLatitudeLongitudeOrder)
 
1006
{
 
1007
  outputLatitudeLongitudeOrder = _outputLatitudeLongitudeOrder;
 
1008
}
 
1009
 
 
1010
 
 
1011
/************************************************************************/
 
1012
/*                              PRIVATE FUNCTIONS     
 
1013
 *
 
1014
 */
 
1015
 
 
1016
void Fiomeths::setInputFilename( const char *filename )
 
1017
{
 
1018
  FVC_Status error_Code_File = Open_File( SourceOrTarget::source, filename, &inputFile);
 
1019
  if (error_Code_File)
 
1020
    throw CoordinateConversionException( FileErrorMessages::fileOpenError );
 
1021
  else
 
1022
  {
 
1023
    long error_Code = parseInputFileHeader(inputFile);
 
1024
    if( error_Code )
 
1025
    {
 
1026
      char errorStr[256];
 
1027
      getFileErrorString( error_Code, errorStr ); 
 
1028
      throw CoordinateConversionException( errorStr );
 
1029
    }
 
1030
  }
 
1031
 
 
1032
  Eat_Noise(inputFile);
 
1033
}
 
1034
 
 
1035
 
 
1036
void Fiomeths::getFileErrorString(long error, char *str)
 
1037
{
 
1038
  switch (error)
 
1039
  {
 
1040
  case FIO_Error_Reading_File:
 
1041
    {
 
1042
      strcpy(str,"Input file error opening file\n");
 
1043
      break;
 
1044
    }
 
1045
  case FIO_Error_Projection:
 
1046
    {
 
1047
      strcpy(str,"Input file error in coordinate type\n");
 
1048
      break;
 
1049
    }
 
1050
  case FIO_Error_Datum:
 
1051
    {
 
1052
      strcpy(str,"Input file error in datum\n");
 
1053
      break;
 
1054
    }
 
1055
  case FIO_Error_Central_Meridian:
 
1056
    {
 
1057
      strcpy(str,"Input file error in Central Meridian\n");
 
1058
      break;
 
1059
    }
 
1060
  case FIO_Error_Origin_Latitude:
 
1061
    {
 
1062
      strcpy(str,"Input file error in Origin Latitude\n");
 
1063
      break;
 
1064
    }
 
1065
  case FIO_Error_Origin_Longitude:
 
1066
    {
 
1067
      strcpy(str,"Input file error in Origin Longitude\n");
 
1068
      break;
 
1069
    }
 
1070
  case FIO_Error_Origin_Height:
 
1071
    {
 
1072
      strcpy(str,"Input file error in Origin Height\n");
 
1073
      break;
 
1074
    }
 
1075
  case FIO_Error_Orientation:
 
1076
    {
 
1077
      strcpy(str,"Input file error in Orientation\n");
 
1078
      break;
 
1079
    }
 
1080
  case FIO_Error_Latitude_One:
 
1081
    {
 
1082
      strcpy(str,"Input file error in Latitude 1\n");
 
1083
      break;
 
1084
    }
 
1085
  case FIO_Error_Longitude_One:
 
1086
    {
 
1087
      strcpy(str,"Input file error in Longitude 1\n");
 
1088
      break;
 
1089
    }
 
1090
  case FIO_Error_Latitude_Two:
 
1091
    {
 
1092
      strcpy(str,"Input file error in Latitude 2\n");
 
1093
      break;
 
1094
    }
 
1095
  case FIO_Error_Longitude_Two:
 
1096
    {
 
1097
      strcpy(str,"Input file error in Longitude 2\n");
 
1098
      break;
 
1099
    }
 
1100
  case FIO_Error_Standard_Parallel:
 
1101
    {
 
1102
      strcpy(str,"Input file error in Standard Parallel ");
 
1103
      break;
 
1104
    }
 
1105
  case FIO_Error_Standard_Parallel_One:
 
1106
    {
 
1107
      strcpy(str,"Input file error in Standard Parallel 1\n");
 
1108
      break;
 
1109
    }
 
1110
  case FIO_Error_Standard_Parallel_Two:
 
1111
    {
 
1112
      strcpy(str,"Input file error in Standard Parallel 2\n");
 
1113
      break;
 
1114
    }
 
1115
  case FIO_Error_False_Easting:
 
1116
    {
 
1117
      strcpy(str,"Input file error in False Easting\n");
 
1118
      break;
 
1119
    }
 
1120
  case FIO_Error_False_Northing:
 
1121
    {
 
1122
      strcpy(str,"Input file error in False Northing\n");
 
1123
      break;
 
1124
    }
 
1125
  case FIO_Error_Scale_Factor:
 
1126
    {
 
1127
      strcpy(str,"Input file error in Scale Factor\n");
 
1128
      break;
 
1129
    }
 
1130
  case FIO_Error_Hemisphere:
 
1131
    {
 
1132
      strcpy(str,"Input file error in Hemisphere\n");
 
1133
      break;
 
1134
    }
 
1135
  case FIO_Error_Coordinate_Order:
 
1136
    {
 
1137
      strcpy(str,"Input file error in Coordinate Order\n");
 
1138
      break;
 
1139
    }
 
1140
  case FIO_Error_Parsing_Header:
 
1141
    {
 
1142
      strcpy(str,"Input file header contains unknown keyword\n");
 
1143
      break;
 
1144
    }
 
1145
  default:
 
1146
    {
 
1147
      strcpy(str,"Input file unknown error\n");
 
1148
      break;
 
1149
    }
 
1150
  }
 
1151
}
 
1152
 
 
1153
 
 
1154
long Fiomeths::parseInputFileHeader(FILE *file)
 
1155
{
 
1156
  HeightType::Enum heightType = HeightType::ellipsoidHeight;
 
1157
  double centralMeridian = 0.0;
 
1158
  double latitudeOfTrueScale = 0.0;
 
1159
  double longitudeDownFromPole = 0.0;
 
1160
  double originLatitude = 0.0;
 
1161
  double originLongitude = 0.0;
 
1162
  double originHeight = 0.0;
 
1163
  double orientation = 0.0;
 
1164
  double latitude1 = 0.0;
 
1165
  double longitude1 = 0.0;
 
1166
  double latitude2 = 0.0;
 
1167
  double longitude2 = 0.0;
 
1168
  double standardParallel = 0.0;
 
1169
  double standardParallel1 = 0.0;
 
1170
  double standardParallel2 = 0.0;
 
1171
  double falseEasting = 0.0;
 
1172
  double falseNorthing = 0.0;
 
1173
  double scaleFactor = 1.0;
 
1174
  char hemisphere = 'N';
 
1175
  FHD_Value latitude_header_type = FHD_Origin_Latitude;
 
1176
  FHD_Value longitude_header_type = FHD_Origin_Longitude;
 
1177
 
 
1178
  FIO_Status error_Code = FIO_Success;
 
1179
  SVC_Status error_Code_String = SVC_Success;
 
1180
  FVC_Status error_Code_File = FVC_Success;
 
1181
  FHD_Value header_Line = FHD_Comment;
 
1182
  long errorCodeCCS = 0;
 
1183
  char buf[256];
 
1184
  long length;
 
1185
 
 
1186
  inputLatitudeLongitudeOrder = true;
 
1187
 
 
1188
  /* Process each header line until end-of-header sequence reached */
 
1189
  error_Code_File = Next_Header_Line(file, &header_Line);
 
1190
  if (error_Code_File)
 
1191
    return FIO_Error_Parsing_Header;
 
1192
  while (header_Line != FHD_End_of_Header)
 
1193
  {
 
1194
    switch (header_Line)
 
1195
    {
 
1196
      case FHD_Projection:
 
1197
      {
 
1198
        char coord_Type[256] = "";
 
1199
        if (fgets(coord_Type,256,file) == NULL)
 
1200
          return FIO_Error_Projection;
 
1201
        else
 
1202
        {
 
1203
          int i = 0;
 
1204
          while(isalpha(coord_Type[i]) || (coord_Type[i] == ' ') || (coord_Type[i] == '\'')
 
1205
                || (coord_Type[i] == '(') || (coord_Type[i] == ')')
 
1206
                || (coord_Type[i] == '1') || (coord_Type[i] == '2'))
 
1207
          {
 
1208
            if (isalpha(coord_Type[i]))
 
1209
              coord_Type[i] = (char)toupper(coord_Type[i]);
 
1210
            i++;
 
1211
          }
 
1212
          coord_Type[i] = '\0';
 
1213
          strcpy( coord_Type, remove_trailing_spaces( coord_Type ) );
 
1214
          error_Code_String = String_to_Projection(coord_Type, &sourceProjectionType);
 
1215
          if(error_Code_String)
 
1216
            return FIO_Error_Projection;
 
1217
        }
 
1218
        break;
 
1219
      }
 
1220
      case FHD_Datum:
 
1221
      {
 
1222
        char datumCode[7];
 
1223
        if (fscanf(file, "%s", datumCode) <=0)
 
1224
          return FIO_Error_Datum;
 
1225
        else
 
1226
        {
 
1227
          int length = strlen( datumCode );
 
1228
          if ( length > ( DATUM_CODE_LENGTH-1 ) )
 
1229
            return FIO_Error_Datum;
 
1230
          else
 
1231
          {
 
1232
            if( sourceDatumCode )
 
1233
              delete [] sourceDatumCode;
 
1234
            sourceDatumCode = new char[ strlen( datumCode ) + 1 ];
 
1235
            strcpy( sourceDatumCode, datumCode );
 
1236
          }
 
1237
        }
 
1238
        break;
 
1239
      }
 
1240
      case FHD_No_Height:
 
1241
      {
 
1242
        heightType = HeightType::noHeight;
 
1243
        break;
 
1244
      }
 
1245
      case FHD_Ellipsoid_Height:
 
1246
      {
 
1247
        heightType = HeightType::ellipsoidHeight;
 
1248
        break;
 
1249
      }
 
1250
      case FHD_MSL_EGM96_15M_BL_Height:
 
1251
      {
 
1252
        heightType = HeightType::EGM96FifteenMinBilinear;
 
1253
        break;
 
1254
      }
 
1255
      case FHD_MSL_EGM96_VG_NS_Height:
 
1256
      {
 
1257
        heightType = HeightType::EGM96VariableNaturalSpline;
 
1258
        break;
 
1259
      }
 
1260
      case FHD_MSL_EGM84_10D_BL_Height:
 
1261
      {
 
1262
        heightType = HeightType::EGM84TenDegBilinear;
 
1263
        break;
 
1264
      }
 
1265
      case FHD_MSL_EGM84_10D_NS_Height:
 
1266
      {
 
1267
        heightType = HeightType::EGM84TenDegNaturalSpline;
 
1268
        break;
 
1269
      }
 
1270
      case FHD_MSL_EGM84_30M_BL_Height:
 
1271
      {
 
1272
        heightType = HeightType::EGM84ThirtyMinBiLinear;
 
1273
        break;
 
1274
      }
 
1275
      case FHD_Central_Meridian:
 
1276
      {
 
1277
        double value = 0.0;
 
1278
        long error_code = 0;
 
1279
        longitude_header_type = FHD_Central_Meridian;
 
1280
        Eat_Noise(file);
 
1281
        error_code = fscanf(file, "%14[ 0123456789NSEW:/+.-]", buf);
 
1282
        if (error_code)
 
1283
        {
 
1284
          error_code = String_to_Longitude(buf,&value);
 
1285
          if (!error_code)
 
1286
          {
 
1287
            centralMeridian = value * PI / 180.0;
 
1288
          }
 
1289
          else
 
1290
            return FIO_Error_Central_Meridian;
 
1291
        }
 
1292
        else
 
1293
          return FIO_Error_Central_Meridian;
 
1294
        break;
 
1295
      }
 
1296
    case FHD_Latitude_of_True_Scale:
 
1297
      {
 
1298
        double value = 0.0;
 
1299
        long error_code = 0;
 
1300
        latitude_header_type = FHD_Latitude_of_True_Scale;
 
1301
        Eat_Noise(file);
 
1302
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1303
        if (error_code)
 
1304
        {
 
1305
          error_code = String_to_Latitude(buf,&value);
 
1306
          if (!error_code)
 
1307
          {
 
1308
            latitudeOfTrueScale = value * PI / 180.0;
 
1309
          }
 
1310
          else
 
1311
            return FIO_Error_Latitude_of_True_Scale;
 
1312
        }
 
1313
        else
 
1314
          return FIO_Error_Latitude_of_True_Scale;
 
1315
        break;
 
1316
      }
 
1317
    case FHD_Longitude_Down_from_Pole:
 
1318
      {
 
1319
        double value = 0.0;
 
1320
        long error_code = 0;
 
1321
        longitude_header_type = FHD_Longitude_Down_from_Pole;
 
1322
        Eat_Noise(file);
 
1323
        error_code = fscanf(file, "%14[ 0123456789NSEW:/+.-]", buf);
 
1324
        if (error_code)
 
1325
        {
 
1326
          error_code = String_to_Longitude(buf,&value);
 
1327
          if (!error_code)
 
1328
          {
 
1329
            longitudeDownFromPole = value * PI / 180.0;
 
1330
          }
 
1331
          else
 
1332
            return FIO_Error_Longitude_Down_from_Pole;
 
1333
        }
 
1334
        else
 
1335
          return FIO_Error_Longitude_Down_from_Pole;
 
1336
        break;
 
1337
      }
 
1338
    case FHD_Origin_Latitude:
 
1339
      {
 
1340
        double value = 0.0;
 
1341
        long error_code = 0;
 
1342
        latitude_header_type = FHD_Origin_Latitude;
 
1343
        Eat_Noise(file);
 
1344
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1345
        if (error_code)
 
1346
        {
 
1347
          error_code = String_to_Latitude(buf,&value);
 
1348
          if (!error_code)
 
1349
          {
 
1350
            originLatitude = value * PI / 180.0;
 
1351
          }
 
1352
          else
 
1353
            return FIO_Error_Origin_Latitude;
 
1354
        }
 
1355
        else
 
1356
          return FIO_Error_Origin_Latitude;
 
1357
        break;
 
1358
      }
 
1359
    case FHD_Origin_Longitude:
 
1360
      {
 
1361
        double value = 0.0;
 
1362
        long error_code = 0;
 
1363
        longitude_header_type = FHD_Origin_Longitude;
 
1364
        Eat_Noise(file);
 
1365
        error_code = fscanf(file, "%14[ 0123456789NSEW:/+.-]", buf);
 
1366
        if (error_code)
 
1367
        {
 
1368
          error_code = String_to_Longitude(buf,&value);
 
1369
          if (!error_code)
 
1370
          {
 
1371
            originLongitude = value * PI / 180.0;
 
1372
          }
 
1373
          else
 
1374
            return FIO_Error_Origin_Longitude;
 
1375
        }
 
1376
        else
 
1377
          return FIO_Error_Origin_Longitude;
 
1378
        break;
 
1379
      }
 
1380
    case FHD_Origin_Height:
 
1381
      {
 
1382
        double value = 0.0;
 
1383
        long error_code = fscanf(file, "%s", buf);
 
1384
        if (error_code)
 
1385
        {
 
1386
          length = strlen(buf)-1;
 
1387
          if (!isdigit(buf[length]))
 
1388
            buf[length] = 0;
 
1389
          error_code = String_to_Double(buf,&value);
 
1390
          if (!error_code)
 
1391
            originHeight = value;
 
1392
          else
 
1393
            return FIO_Error_Origin_Height;
 
1394
        }
 
1395
        else
 
1396
          return FIO_Error_Origin_Height;
 
1397
        break;
 
1398
      }
 
1399
    case FHD_Orientation:
 
1400
      {
 
1401
        double value = 0.0;
 
1402
        long error_code = 0;
 
1403
        Eat_Noise(file);
 
1404
        error_code = fscanf(file, "%14[ 0123456789NSEW:/+.-]", buf);
 
1405
        if (error_code)
 
1406
        {
 
1407
          error_code = String_to_Longitude(buf,&value);
 
1408
          if (!error_code)
 
1409
          {
 
1410
            orientation = value * PI / 180.0;
 
1411
          }
 
1412
          else
 
1413
            return FIO_Error_Orientation;
 
1414
        }
 
1415
        else
 
1416
          return FIO_Error_Orientation;
 
1417
        break;
 
1418
      }
 
1419
    case FHD_Latitude_One:
 
1420
      {
 
1421
        double value = 0.0;
 
1422
        long error_code = 0;
 
1423
        Eat_Noise(file);
 
1424
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1425
        if (error_code)
 
1426
        {
 
1427
          error_code = String_to_Latitude(buf,&value);
 
1428
          if (!error_code)
 
1429
          {
 
1430
            latitude1 = value * PI / 180.0;
 
1431
          }
 
1432
          else
 
1433
            return FIO_Error_Latitude_One;
 
1434
        }
 
1435
        else
 
1436
          return FIO_Error_Latitude_One;
 
1437
        break;
 
1438
      }
 
1439
    case FHD_Longitude_One:
 
1440
      {
 
1441
        double value = 0.0;
 
1442
        long error_code = 0;
 
1443
        Eat_Noise(file);
 
1444
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1445
        if (error_code)
 
1446
        {
 
1447
          error_code = String_to_Longitude(buf,&value);
 
1448
          if (!error_code)
 
1449
          {
 
1450
            longitude1 = value * PI / 180.0;
 
1451
          }
 
1452
          else
 
1453
            return FIO_Error_Longitude_One;
 
1454
        }
 
1455
        else
 
1456
          return FIO_Error_Longitude_One;
 
1457
        break;
 
1458
      }
 
1459
    case FHD_Latitude_Two:
 
1460
      {
 
1461
        double value = 0.0;
 
1462
        long error_code = 0;
 
1463
        Eat_Noise(file);
 
1464
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1465
        if (error_code)
 
1466
        {
 
1467
          error_code = String_to_Latitude(buf,&value);
 
1468
          if (!error_code)
 
1469
          {
 
1470
            latitude2 = value * PI / 180.0;
 
1471
          }
 
1472
          else
 
1473
            return FIO_Error_Latitude_Two;
 
1474
        }
 
1475
        else
 
1476
          return FIO_Error_Latitude_Two;
 
1477
        break;
 
1478
      }
 
1479
    case FHD_Longitude_Two:
 
1480
      {
 
1481
        double value = 0.0;
 
1482
        long error_code = 0;
 
1483
        Eat_Noise(file);
 
1484
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1485
        if (error_code)
 
1486
        {
 
1487
          error_code = String_to_Longitude(buf,&value);
 
1488
          if (!error_code)
 
1489
          {
 
1490
            longitude2 = value * PI / 180.0;
 
1491
          }
 
1492
          else
 
1493
            return FIO_Error_Longitude_Two;
 
1494
        }
 
1495
        else
 
1496
          return FIO_Error_Longitude_Two;
 
1497
        break;
 
1498
      }
 
1499
    case FHD_Standard_Parallel:
 
1500
      {
 
1501
        double value = 0.0;
 
1502
        long error_code = 0;
 
1503
        latitude_header_type = FHD_Standard_Parallel;
 
1504
        Eat_Noise(file);
 
1505
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1506
        if (error_code)
 
1507
        {
 
1508
          error_code = String_to_Latitude(buf,&value);
 
1509
          if (!error_code)
 
1510
          {
 
1511
            standardParallel = value * PI / 180.0;
 
1512
          }
 
1513
          else
 
1514
            return FIO_Error_Standard_Parallel;
 
1515
        }
 
1516
        else
 
1517
          return FIO_Error_Standard_Parallel;
 
1518
        break;
 
1519
      }
 
1520
    case FHD_Standard_Parallel_One:
 
1521
      {
 
1522
        double value = 0.0;
 
1523
        long error_code = 0;
 
1524
        Eat_Noise(file);
 
1525
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1526
        if (error_code)
 
1527
        {
 
1528
          error_code = String_to_Latitude(buf,&value);
 
1529
          if (!error_code)
 
1530
          {
 
1531
            standardParallel1 = value * PI / 180.0;
 
1532
          }
 
1533
          else
 
1534
            return FIO_Error_Standard_Parallel_One;
 
1535
        }
 
1536
        else
 
1537
          return FIO_Error_Standard_Parallel_One;
 
1538
        break;
 
1539
      }
 
1540
    case FHD_Standard_Parallel_Two:
 
1541
      {
 
1542
        double value = 0.0;
 
1543
        long error_code = 0;
 
1544
        Eat_Noise(file);
 
1545
        error_code = fscanf(file, "%13[ 0123456789NSEW:/.+-]", buf);
 
1546
        if (error_code)
 
1547
        {
 
1548
          error_code = String_to_Latitude(buf,&value);
 
1549
          if (!error_code)
 
1550
          {
 
1551
            standardParallel2 = value * PI / 180.0;
 
1552
          }
 
1553
          else
 
1554
            return FIO_Error_Standard_Parallel_Two;
 
1555
        }
 
1556
        else
 
1557
          return FIO_Error_Standard_Parallel_Two;
 
1558
        break;
 
1559
      }
 
1560
    case FHD_False_Easting:
 
1561
      {
 
1562
        double value = 0.0;
 
1563
        long error_code = fscanf(file, "%s", buf);
 
1564
        if (error_code)
 
1565
        {
 
1566
          length = strlen(buf)-1;
 
1567
          if (!isdigit(buf[length]))
 
1568
            buf[length] = 0;
 
1569
          error_code = String_to_Double(buf,&value);
 
1570
          if (!error_code)
 
1571
            falseEasting = value;
 
1572
          else
 
1573
            return FIO_Error_False_Easting;
 
1574
        }
 
1575
        else
 
1576
          return FIO_Error_False_Easting;
 
1577
        break;
 
1578
      }
 
1579
      case FHD_False_Northing:
 
1580
      {
 
1581
        double value = 0.0;
 
1582
        long error_code = fscanf(file, "%s", buf);
 
1583
        if (error_code)
 
1584
        {
 
1585
          length = strlen(buf)-1;
 
1586
          if (!isdigit(buf[length]))
 
1587
            buf[length] = 0;
 
1588
          error_code = String_to_Double(buf,&value);
 
1589
          if (!error_code)
 
1590
            falseNorthing = value;
 
1591
          else
 
1592
            return FIO_Error_False_Northing;
 
1593
        }
 
1594
        else
 
1595
          return FIO_Error_False_Northing;
 
1596
        break;
 
1597
      }
 
1598
      case FHD_Scale_Factor:
 
1599
      {
 
1600
        double value = 0.0;
 
1601
        long error_code = fscanf(file, "%s", buf);
 
1602
        if (error_code)
 
1603
        {
 
1604
          length = strlen(buf)-1;
 
1605
          if (!isdigit(buf[length]))
 
1606
            buf[length] = 0;
 
1607
          error_code = String_to_Double(buf,&value);
 
1608
          if (!error_code)
 
1609
          {
 
1610
            if ((0.3 <= value) &&(value <= 3.0))
 
1611
              scaleFactor = value;
 
1612
            else
 
1613
              return FIO_Error_Scale_Factor;
 
1614
          }
 
1615
          else
 
1616
            return FIO_Error_Scale_Factor;
 
1617
        }
 
1618
        else
 
1619
          return FIO_Error_Scale_Factor;
 
1620
        break;
 
1621
      }
 
1622
      case FHD_Coordinate_Order:
 
1623
      {
 
1624
        int i = 0;
 
1625
        long error_code = fscanf(file, "%s", buf);
 
1626
        if (error_code)
 
1627
        {
 
1628
          int length = strlen(buf);
 
1629
          for(i = 0; i < length; i++)
 
1630
            buf[i] = (char)toupper(buf[i]);
 
1631
 
 
1632
          if(strstr(LONGITUDE_LATITUDE, buf))
 
1633
            inputLatitudeLongitudeOrder = false;
 
1634
          else if(strstr(LATITUDE_LONGITUDE, buf))
 
1635
            inputLatitudeLongitudeOrder = true;
 
1636
          else
 
1637
            return FIO_Error_Coordinate_Order;
 
1638
        }
 
1639
        else
 
1640
          return FIO_Error_Coordinate_Order;
 
1641
        break;
 
1642
      }
 
1643
      case FHD_Hemisphere:
 
1644
      {
 
1645
        int i = 0;
 
1646
        long error_code = fscanf(file, "%s", buf);
 
1647
        if (error_code)
 
1648
        {
 
1649
          int length = strlen(buf);
 
1650
          for(i = 0; i < length; i++)
 
1651
            buf[i] = (char)toupper(buf[i]);
 
1652
          if(strstr("N", buf))
 
1653
            hemisphere = 'N';
 
1654
          else if(strstr("S", buf))
 
1655
            hemisphere = 'S';
 
1656
          else
 
1657
            return FIO_Error_Hemisphere;
 
1658
        }
 
1659
        else
 
1660
          return FIO_Error_Hemisphere;
 
1661
        break;
 
1662
      }
 
1663
    case FHD_Header:
 
1664
      break;
 
1665
    case FHD_Invalid_Header:
 
1666
    default:
 
1667
      return FIO_Error_Parsing_Header;
 
1668
    } /* switch */
 
1669
    error_Code_File = Next_Header_Line(file, &header_Line);
 
1670
    if (error_Code_File)
 
1671
      return FIO_Error_Parsing_Header;
 
1672
  } /* while */
 
1673
 
 
1674
  /* Set parameters */
 
1675
  switch( sourceProjectionType )
 
1676
  {
 
1677
    case CoordinateType::albersEqualAreaConic:
 
1678
      if( mapProjection6Parameters )
 
1679
        delete mapProjection6Parameters;
 
1680
      mapProjection6Parameters = new MapProjection6Parameters(CoordinateType::albersEqualAreaConic, centralMeridian, originLatitude, standardParallel1, standardParallel2, falseEasting, falseNorthing);
 
1681
      break;
 
1682
    case CoordinateType::azimuthalEquidistant:
 
1683
      if( mapProjection4Parameters )
 
1684
        delete mapProjection4Parameters;
 
1685
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::azimuthalEquidistant, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1686
      break;
 
1687
    case CoordinateType::bonne:
 
1688
      if( mapProjection4Parameters )
 
1689
        delete mapProjection4Parameters;
 
1690
        mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::bonne, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1691
        break;
 
1692
    case CoordinateType::britishNationalGrid:
 
1693
      if( coordinateSystemParameters )
 
1694
        delete coordinateSystemParameters;
 
1695
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::britishNationalGrid);
 
1696
      break;
 
1697
    case CoordinateType::cassini:
 
1698
      if( mapProjection4Parameters )
 
1699
        delete mapProjection4Parameters;
 
1700
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::cassini, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1701
      break;
 
1702
    case CoordinateType::cylindricalEqualArea:
 
1703
      if( mapProjection4Parameters )
 
1704
        delete mapProjection4Parameters;
 
1705
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::cylindricalEqualArea, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1706
      break;
 
1707
    case CoordinateType::eckert4:
 
1708
      if( mapProjection3Parameters )
 
1709
        delete mapProjection3Parameters;
 
1710
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::eckert4, centralMeridian, falseEasting, falseNorthing);
 
1711
      break;
 
1712
    case CoordinateType::eckert6:
 
1713
      if( mapProjection3Parameters )
 
1714
        delete mapProjection3Parameters;
 
1715
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::eckert6, centralMeridian, falseEasting, falseNorthing);
 
1716
      break;
 
1717
    case CoordinateType::equidistantCylindrical:
 
1718
      if( equidistantCylindricalParameters )
 
1719
        delete equidistantCylindricalParameters;
 
1720
      equidistantCylindricalParameters = new EquidistantCylindricalParameters(CoordinateType::equidistantCylindrical, centralMeridian, standardParallel, falseEasting, falseNorthing);
 
1721
      break;
 
1722
    case CoordinateType::geocentric:
 
1723
      if( coordinateSystemParameters )
 
1724
        delete coordinateSystemParameters;
 
1725
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::geocentric);
 
1726
      break;
 
1727
    case CoordinateType::geodetic:
 
1728
      if( geodeticParameters )
 
1729
        delete geodeticParameters;
 
1730
      geodeticParameters = new GeodeticParameters(CoordinateType::geodetic, heightType);
 
1731
      break;
 
1732
    case CoordinateType::georef:
 
1733
      if( coordinateSystemParameters )
 
1734
        delete coordinateSystemParameters;
 
1735
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::georef);
 
1736
      break;
 
1737
    case CoordinateType::globalAreaReferenceSystem:
 
1738
      if( coordinateSystemParameters )
 
1739
        delete coordinateSystemParameters;
 
1740
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::globalAreaReferenceSystem);
 
1741
      break;
 
1742
    case CoordinateType::gnomonic:
 
1743
      if( mapProjection4Parameters )
 
1744
        delete mapProjection4Parameters;
 
1745
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::gnomonic, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1746
      break;
 
1747
    case CoordinateType::lambertConformalConic1Parallel:
 
1748
      if( mapProjection5Parameters )
 
1749
        delete mapProjection5Parameters;
 
1750
      mapProjection5Parameters = new MapProjection5Parameters(CoordinateType::lambertConformalConic1Parallel, centralMeridian, originLatitude, scaleFactor, falseEasting, falseNorthing);
 
1751
      break;
 
1752
    case CoordinateType::lambertConformalConic2Parallels:
 
1753
      if( mapProjection6Parameters )
 
1754
        delete mapProjection6Parameters;
 
1755
      mapProjection6Parameters = new MapProjection6Parameters(CoordinateType::lambertConformalConic2Parallels, centralMeridian, originLatitude, standardParallel1, standardParallel2, falseEasting, falseNorthing);
 
1756
      break;
 
1757
    case CoordinateType::localCartesian:
 
1758
      if( localCartesianParameters )
 
1759
        delete localCartesianParameters;
 
1760
      localCartesianParameters = new LocalCartesianParameters(CoordinateType::localCartesian, originLongitude, originLatitude, originHeight, orientation);
 
1761
      break;
 
1762
    case CoordinateType::mercatorStandardParallel:
 
1763
    {
 
1764
      if( mercatorStandardParallelParameters )
 
1765
        delete mercatorStandardParallelParameters;
 
1766
      if( latitude_header_type == FHD_Standard_Parallel )
 
1767
        mercatorStandardParallelParameters = new MercatorStandardParallelParameters(CoordinateType::mercatorStandardParallel, centralMeridian, standardParallel, scaleFactor, falseEasting, falseNorthing);
 
1768
      else if( latitude_header_type == FHD_Origin_Latitude )
 
1769
        mercatorStandardParallelParameters = new MercatorStandardParallelParameters(CoordinateType::mercatorStandardParallel, centralMeridian, originLatitude, scaleFactor, falseEasting, falseNorthing);
 
1770
      else
 
1771
        mercatorStandardParallelParameters = new MercatorStandardParallelParameters(CoordinateType::mercatorStandardParallel, centralMeridian, latitudeOfTrueScale, scaleFactor, falseEasting, falseNorthing);
 
1772
     
 
1773
      GeodeticParameters geodeticParameters( CoordinateType::geodetic, HeightType::noHeight );  
 
1774
      CoordinateConversionService tempCoordinateConversionService( sourceDatumCode, mercatorStandardParallelParameters, "WGE", &geodeticParameters );
 
1775
      MercatorStandardParallelParameters tempMercatorStandardParallelParameters = *dynamic_cast< MercatorStandardParallelParameters* >( tempCoordinateConversionService.getCoordinateSystem( SourceOrTarget::source ) );
 
1776
      
 
1777
      mercatorStandardParallelParameters->setScaleFactor( tempMercatorStandardParallelParameters.scaleFactor() );
 
1778
      break;
 
1779
    }
 
1780
    case CoordinateType::mercatorScaleFactor:
 
1781
      if( mercatorScaleFactorParameters )
 
1782
        delete mercatorScaleFactorParameters;
 
1783
      mercatorScaleFactorParameters = new MercatorScaleFactorParameters(CoordinateType::mercatorScaleFactor, centralMeridian, scaleFactor, falseEasting, falseNorthing);
 
1784
      break;
 
1785
    case CoordinateType::militaryGridReferenceSystem:
 
1786
      if( coordinateSystemParameters )
 
1787
        delete coordinateSystemParameters;
 
1788
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::militaryGridReferenceSystem);
 
1789
      break;
 
1790
    case CoordinateType::millerCylindrical:
 
1791
      if( mapProjection3Parameters )
 
1792
        delete mapProjection3Parameters;
 
1793
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::millerCylindrical, centralMeridian, falseEasting, falseNorthing);
 
1794
      break;
 
1795
    case CoordinateType::mollweide:
 
1796
      if( mapProjection3Parameters )
 
1797
        delete mapProjection3Parameters;
 
1798
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::mollweide, centralMeridian, falseEasting, falseNorthing);
 
1799
      break;
 
1800
    case CoordinateType::neys:
 
1801
      if( neysParameters )
 
1802
        delete neysParameters;
 
1803
      neysParameters = new NeysParameters(CoordinateType::neys, centralMeridian, originLatitude, standardParallel1, falseEasting, falseNorthing);
 
1804
      break;
 
1805
    case CoordinateType::newZealandMapGrid:
 
1806
      if( coordinateSystemParameters )
 
1807
        delete coordinateSystemParameters;
 
1808
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::newZealandMapGrid);
 
1809
      break;
 
1810
    case CoordinateType::obliqueMercator:
 
1811
      if( obliqueMercatorParameters )
 
1812
        delete obliqueMercatorParameters;
 
1813
      obliqueMercatorParameters = new ObliqueMercatorParameters(CoordinateType::obliqueMercator, originLatitude, longitude1, latitude1, longitude2, latitude2, falseEasting, falseNorthing, scaleFactor);
 
1814
      break;
 
1815
    case CoordinateType::orthographic:
 
1816
      if( mapProjection4Parameters )
 
1817
        delete mapProjection4Parameters;
 
1818
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::orthographic, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1819
      break;
 
1820
    case CoordinateType::polarStereographicStandardParallel:
 
1821
      if( polarStereographicStandardParallelParameters )
 
1822
        delete polarStereographicStandardParallelParameters;
 
1823
      if( latitude_header_type == FHD_Standard_Parallel )
 
1824
      {
 
1825
        if( longitude_header_type == FHD_Central_Meridian )
 
1826
          polarStereographicStandardParallelParameters = new PolarStereographicStandardParallelParameters(CoordinateType::polarStereographicStandardParallel, centralMeridian, standardParallel, falseEasting, falseNorthing);
 
1827
        else
 
1828
          polarStereographicStandardParallelParameters = new PolarStereographicStandardParallelParameters(CoordinateType::polarStereographicStandardParallel, longitudeDownFromPole, standardParallel, falseEasting, falseNorthing);
 
1829
      }
 
1830
      else
 
1831
      {
 
1832
        if( longitude_header_type == FHD_Central_Meridian )
 
1833
          polarStereographicStandardParallelParameters = new PolarStereographicStandardParallelParameters(CoordinateType::polarStereographicStandardParallel, centralMeridian, latitudeOfTrueScale, falseEasting, falseNorthing);
 
1834
        else
 
1835
          polarStereographicStandardParallelParameters = new PolarStereographicStandardParallelParameters(CoordinateType::polarStereographicStandardParallel, longitudeDownFromPole, latitudeOfTrueScale, falseEasting, falseNorthing);
 
1836
      }
 
1837
      break;
 
1838
    case CoordinateType::polarStereographicScaleFactor:
 
1839
      if( polarStereographicScaleFactorParameters )
 
1840
        delete polarStereographicScaleFactorParameters;
 
1841
      if( longitude_header_type == FHD_Central_Meridian )
 
1842
        polarStereographicScaleFactorParameters = new PolarStereographicScaleFactorParameters(CoordinateType::polarStereographicScaleFactor, centralMeridian, scaleFactor, hemisphere, falseEasting, falseNorthing);
 
1843
      else
 
1844
        polarStereographicScaleFactorParameters = new PolarStereographicScaleFactorParameters(CoordinateType::polarStereographicScaleFactor, longitudeDownFromPole, scaleFactor, hemisphere, falseEasting, falseNorthing);
 
1845
      break;
 
1846
    case CoordinateType::polyconic:
 
1847
      if( mapProjection4Parameters )
 
1848
        delete mapProjection4Parameters;
 
1849
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::polyconic, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1850
      break;
 
1851
    case CoordinateType::sinusoidal:
 
1852
      if( mapProjection3Parameters )
 
1853
        delete mapProjection3Parameters;
 
1854
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::sinusoidal, centralMeridian, falseEasting, falseNorthing);
 
1855
      break;
 
1856
    case CoordinateType::stereographic:
 
1857
      if( mapProjection4Parameters )
 
1858
        delete mapProjection4Parameters;
 
1859
      mapProjection4Parameters = new MapProjection4Parameters(CoordinateType::stereographic, centralMeridian, originLatitude, falseEasting, falseNorthing);
 
1860
      break;
 
1861
    case CoordinateType::transverseCylindricalEqualArea:
 
1862
      if( mapProjection5Parameters )
 
1863
        delete mapProjection5Parameters;
 
1864
      mapProjection5Parameters = new MapProjection5Parameters(CoordinateType::transverseCylindricalEqualArea, centralMeridian, originLatitude, scaleFactor, falseEasting, falseNorthing);
 
1865
      break;
 
1866
    case CoordinateType::transverseMercator:
 
1867
      if( mapProjection5Parameters )
 
1868
        delete mapProjection5Parameters;
 
1869
      mapProjection5Parameters = new MapProjection5Parameters(CoordinateType::transverseMercator, centralMeridian, originLatitude, scaleFactor, falseEasting, falseNorthing);
 
1870
      break;
 
1871
    case CoordinateType::universalPolarStereographic:
 
1872
      if( coordinateSystemParameters )
 
1873
        delete coordinateSystemParameters;
 
1874
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::universalPolarStereographic);
 
1875
      break;
 
1876
    case CoordinateType::universalTransverseMercator:
 
1877
      if( utmParameters )
 
1878
        delete utmParameters;
 
1879
      utmParameters = new UTMParameters(CoordinateType::universalTransverseMercator, 0);
 
1880
      break;
 
1881
    case CoordinateType::usNationalGrid:
 
1882
      if( coordinateSystemParameters )
 
1883
        delete coordinateSystemParameters;
 
1884
      coordinateSystemParameters = new CoordinateSystemParameters(CoordinateType::usNationalGrid);
 
1885
      break;
 
1886
    case CoordinateType::vanDerGrinten:
 
1887
      if( mapProjection3Parameters )
 
1888
        delete mapProjection3Parameters;
 
1889
      mapProjection3Parameters = new MapProjection3Parameters(CoordinateType::vanDerGrinten, centralMeridian, falseEasting, falseNorthing);
 
1890
      break;
 
1891
    default:
 
1892
      throw CoordinateConversionException( FileErrorMessages::invalidSourceCoordinateSystem );
 
1893
  }
 
1894
 
 
1895
  return error_Code;
 
1896
}
 
1897
 
 
1898
 
 
1899
void Fiomeths::writeOutputFileHeader( const char* targetDatumCode, CoordinateSystemParameters* _targetParameters )
 
1900
{
 
1901
  char projectionName[COORD_SYS_NAME_LENGTH] = "";
 
1902
  char tempCode[DATUM_CODE_LENGTH] = "";
 
1903
  char tempName[DATUM_NAME_LENGTH] = "";
 
1904
  char ellipsoidCode[ELLIPSOID_CODE_LENGTH] = "";
 
1905
  char latitude_str[15] = "";
 
1906
  char longitude_str[15] = "";
 
1907
  char meter_str[15] = "";
 
1908
 
 
1909
  CoordinateSystemParameters parameters;
 
1910
  long datum_Index = 0;
 
1911
 
 
1912
  targetProjectionType = _targetParameters->coordinateType();
 
1913
 
 
1914
  if (Projection_to_String(targetProjectionType, projectionName))
 
1915
    throw CoordinateConversionException( FileErrorMessages::invalidTargetCoordinateSystem );
 
1916
 
 
1917
  if ((targetProjectionType == CoordinateType::britishNationalGrid) ||
 
1918
      (targetProjectionType == CoordinateType::globalAreaReferenceSystem) ||
 
1919
      (targetProjectionType == CoordinateType::geodetic) ||
 
1920
      (targetProjectionType == CoordinateType::georef) ||
 
1921
      (targetProjectionType == CoordinateType::geocentric) ||
 
1922
      (targetProjectionType == CoordinateType::localCartesian) ||
 
1923
      (targetProjectionType == CoordinateType::militaryGridReferenceSystem) ||
 
1924
      (targetProjectionType == CoordinateType::usNationalGrid) ||
 
1925
      (targetProjectionType == CoordinateType::universalTransverseMercator) ||
 
1926
      (targetProjectionType == CoordinateType::universalPolarStereographic))
 
1927
    fprintf(outputFile, "%s: ", coordinates_Header_String);
 
1928
  else
 
1929
    fprintf(outputFile, "%s: ", projection_Header_String);
 
1930
 
 
1931
  fprintf(outputFile, "%s\n", projectionName);
 
1932
 
 
1933
  fprintf(outputFile, "%s: ", datum_Header_String);
 
1934
  fprintf(outputFile, "%s\n", targetDatumCode);
 
1935
 
 
1936
  DatumLibrary* datumLibrary = coordinateConversionService->getDatumLibrary();
 
1937
  long datumIndex;// = datumLibrary->datumIndex(targetDatumCode);
 
1938
  datumLibrary->getDatumIndex( targetDatumCode, &datumIndex );
 
1939
  datumLibrary->getDatumInfo( datumIndex, tempCode, tempName, ellipsoidCode );
 
1940
 
 
1941
  fprintf(outputFile, "# ELLIPSOID: %s\n", ellipsoidCode);
 
1942
 
 
1943
  switch (targetProjectionType)
 
1944
  {
 
1945
    case CoordinateType::geodetic:
 
1946
    {
 
1947
      if( dynamic_cast< GeodeticParameters* >( _targetParameters ) )
 
1948
      {
 
1949
        GeodeticParameters params = *dynamic_cast< GeodeticParameters* >( _targetParameters );
 
1950
 
 
1951
        if (params.heightType() == HeightType::noHeight)
 
1952
          fprintf(outputFile, "%s", no_Height_Header_String);
 
1953
        else if (params.heightType() == HeightType::ellipsoidHeight)
 
1954
          fprintf(outputFile, "%s", ellipsoid_Height_Header_String);
 
1955
        else if (params.heightType() == HeightType::EGM96FifteenMinBilinear)
 
1956
          fprintf(outputFile, "%s", msl_EGM96_15M_BL_Height_Header_String);
 
1957
        else if (params.heightType() == HeightType::EGM96VariableNaturalSpline)
 
1958
          fprintf(outputFile, "%s", msl_EGM96_VG_NS_Height_Header_String);
 
1959
        else if (params.heightType() == HeightType::EGM84TenDegBilinear)
 
1960
          fprintf(outputFile, "%s", msl_EGM84_10D_BL_Height_Header_String);
 
1961
        else if (params.heightType() == HeightType::EGM84TenDegNaturalSpline)
 
1962
          fprintf(outputFile, "%s", msl_EGM84_10D_NS_Height_Header_String);
 
1963
        else if (params.heightType() == HeightType::EGM84ThirtyMinBiLinear)
 
1964
          fprintf(outputFile, "%s", msl_EGM84_30M_BL_Height_Header_String);
 
1965
        fprintf(outputFile,"\n");
 
1966
 
 
1967
        if(outputLatitudeLongitudeOrder)
 
1968
          fprintf(outputFile, "%s: %s\n", coordinate_Order_Header_String, LATITUDE_LONGITUDE);
 
1969
        else
 
1970
          fprintf(outputFile, "%s: %s\n", coordinate_Order_Header_String, LONGITUDE_LATITUDE);
 
1971
      }
 
1972
      else
 
1973
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
1974
 
 
1975
      break;
 
1976
    }
 
1977
    case CoordinateType::britishNationalGrid:
 
1978
    case CoordinateType::globalAreaReferenceSystem:
 
1979
    case CoordinateType::georef:
 
1980
    case CoordinateType::geocentric:
 
1981
    case CoordinateType::militaryGridReferenceSystem:
 
1982
    case CoordinateType::newZealandMapGrid:
 
1983
    case CoordinateType::universalPolarStereographic:
 
1984
    case CoordinateType::usNationalGrid:
 
1985
    case CoordinateType::universalTransverseMercator:
 
1986
    break;
 
1987
    case CoordinateType::localCartesian:
 
1988
    {
 
1989
      if( dynamic_cast< LocalCartesianParameters* >( _targetParameters ) )
 
1990
      {
 
1991
        LocalCartesianParameters params = *dynamic_cast< LocalCartesianParameters* >( _targetParameters );
 
1992
 
 
1993
        fprintf(outputFile, "%s: ", origin_Latitude_Header_String);
 
1994
        Latitude_to_String((params.latitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
1995
        fprintf(outputFile, "%s", latitude_str);
 
1996
 
 
1997
        fprintf(outputFile, "\n%s: ", origin_Longitude_Header_String);
 
1998
        Longitude_to_String((params.longitude()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
1999
        fprintf(outputFile, "%s", longitude_str);
 
2000
 
 
2001
        fprintf(outputFile, "\n%s: ", origin_Height_Header_String);
 
2002
        Meter_to_String(params.height(), meter_str);
 
2003
        fprintf(outputFile, "%s", meter_str);
 
2004
 
 
2005
        fprintf(outputFile, "\n%s: ", orientation_Header_String);
 
2006
        Longitude_to_String((params.orientation()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2007
        fprintf(outputFile, "%s", longitude_str);
 
2008
        fprintf(outputFile, "\n");
 
2009
      }
 
2010
      else
 
2011
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2012
 
 
2013
      break;
 
2014
    }
 
2015
    case CoordinateType::albersEqualAreaConic:
 
2016
    case CoordinateType::lambertConformalConic2Parallels:
 
2017
    {
 
2018
      if( dynamic_cast< MapProjection6Parameters* >( _targetParameters ) )
 
2019
      {
 
2020
        MapProjection6Parameters params = *dynamic_cast< MapProjection6Parameters* >( _targetParameters );
 
2021
 
 
2022
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2023
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2024
        fprintf(outputFile, "%s", longitude_str);
 
2025
 
 
2026
        fprintf(outputFile, "\n%s: ", origin_Latitude_Header_String);
 
2027
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2028
        fprintf(outputFile, "%s", latitude_str);
 
2029
 
 
2030
        fprintf(outputFile, "\n%s: ", standard_Parallel_One_Header_String);
 
2031
        Latitude_to_String((params.standardParallel1()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2032
        fprintf(outputFile, "%s", latitude_str);
 
2033
 
 
2034
        fprintf(outputFile, "\n%s: ", standard_Parallel_Two_Header_String);
 
2035
        Latitude_to_String((params.standardParallel2()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2036
        fprintf(outputFile, "%s", latitude_str);
 
2037
 
 
2038
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2039
        Meter_to_String(params.falseEasting(),meter_str);
 
2040
        fprintf(outputFile, "%s", meter_str);
 
2041
 
 
2042
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2043
        Meter_to_String(params.falseNorthing(),meter_str);
 
2044
        fprintf(outputFile, "%s", meter_str);
 
2045
        fprintf(outputFile, "\n");
 
2046
      }
 
2047
      else
 
2048
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2049
 
 
2050
      break;
 
2051
    }
 
2052
  /*  {
 
2053
      if( dynamic_cast< MapProjection5Parameters* >( _targetParameters ) )
 
2054
      {
 
2055
        MapProjection5Parameters params = *dynamic_cast< MapProjection5Parameters* >( _targetParameters );
 
2056
 
 
2057
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2058
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2059
        fprintf(outputFile, "%s", longitude_str);
 
2060
 
 
2061
        fprintf(outputFile, "\n%s: ", origin_Latitude_Header_String);
 
2062
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2063
        fprintf(outputFile, "%s", latitude_str);
 
2064
 
 
2065
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2066
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2067
 
 
2068
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2069
        Meter_to_String(params.falseEasting(),meter_str);
 
2070
        fprintf(outputFile, "%s", meter_str);
 
2071
 
 
2072
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2073
        Meter_to_String(params.falseNorthing(),meter_str);
 
2074
        fprintf(outputFile, "%s", meter_str);
 
2075
        fprintf(outputFile, "\n");
 
2076
      }
 
2077
      else
 
2078
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2079
 
 
2080
      break;
 
2081
    }*/
 
2082
    case CoordinateType::lambertConformalConic1Parallel:
 
2083
    case CoordinateType::transverseCylindricalEqualArea:
 
2084
    case CoordinateType::transverseMercator:
 
2085
    {
 
2086
      if( dynamic_cast< MapProjection5Parameters* >( _targetParameters ) )
 
2087
      {
 
2088
        MapProjection5Parameters params = *dynamic_cast< MapProjection5Parameters* >( _targetParameters );
 
2089
 
 
2090
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2091
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2092
        fprintf(outputFile, "%s", longitude_str);
 
2093
 
 
2094
        fprintf(outputFile, "\n%s: ", origin_Latitude_Header_String);
 
2095
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2096
        fprintf(outputFile, "%s", latitude_str);
 
2097
 
 
2098
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2099
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2100
 
 
2101
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2102
        Meter_to_String(params.falseEasting(),meter_str);
 
2103
        fprintf(outputFile, "%s", meter_str);
 
2104
 
 
2105
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2106
        Meter_to_String(params.falseNorthing(),meter_str);
 
2107
        fprintf(outputFile, "%s", meter_str);
 
2108
        fprintf(outputFile, "\n");
 
2109
      }
 
2110
      else
 
2111
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2112
 
 
2113
      break;
 
2114
    }
 
2115
    case CoordinateType::mercatorStandardParallel:
 
2116
    {
 
2117
      if( dynamic_cast< MercatorStandardParallelParameters* >( _targetParameters ) )
 
2118
      {
 
2119
        MercatorStandardParallelParameters params = *dynamic_cast< MercatorStandardParallelParameters* >( coordinateConversionService->getCoordinateSystem( SourceOrTarget::target ) );
 
2120
 
 
2121
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2122
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2123
        fprintf(outputFile, "%s", longitude_str);
 
2124
 
 
2125
        fprintf(outputFile, "\n%s: ", standard_Parallel_Header_String);
 
2126
        Latitude_to_String((params.standardParallel()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2127
        fprintf(outputFile, "%s", latitude_str);
 
2128
 
 
2129
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2130
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2131
 
 
2132
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2133
        Meter_to_String(params.falseEasting(),meter_str);
 
2134
        fprintf(outputFile, "%s", meter_str);
 
2135
 
 
2136
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2137
        Meter_to_String(params.falseNorthing(),meter_str);
 
2138
        fprintf(outputFile, "%s", meter_str);
 
2139
        fprintf(outputFile, "\n");
 
2140
      }
 
2141
      else
 
2142
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2143
 
 
2144
      break;
 
2145
    }
 
2146
    case CoordinateType::mercatorScaleFactor:
 
2147
    {
 
2148
      if( dynamic_cast< MercatorScaleFactorParameters* >( _targetParameters ) )
 
2149
      {
 
2150
        MercatorScaleFactorParameters params = *dynamic_cast< MercatorScaleFactorParameters* >( coordinateConversionService->getCoordinateSystem( SourceOrTarget::target ) );
 
2151
 
 
2152
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2153
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2154
        fprintf(outputFile, "%s", longitude_str);
 
2155
 
 
2156
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2157
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2158
 
 
2159
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2160
        Meter_to_String(params.falseEasting(),meter_str);
 
2161
        fprintf(outputFile, "%s", meter_str);
 
2162
 
 
2163
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2164
        Meter_to_String(params.falseNorthing(),meter_str);
 
2165
        fprintf(outputFile, "%s", meter_str);
 
2166
        fprintf(outputFile, "\n");
 
2167
      }
 
2168
      else
 
2169
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2170
 
 
2171
      break;
 
2172
    }
 
2173
    case CoordinateType::polarStereographicStandardParallel:
 
2174
    {
 
2175
      if( dynamic_cast< PolarStereographicStandardParallelParameters* >( _targetParameters ) )
 
2176
      {
 
2177
        PolarStereographicStandardParallelParameters params = *dynamic_cast< PolarStereographicStandardParallelParameters* >( _targetParameters );
 
2178
 
 
2179
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2180
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2181
        fprintf(outputFile, "%s", longitude_str);
 
2182
 
 
2183
        fprintf(outputFile, "\n%s: ", standard_Parallel_Header_String);
 
2184
        Latitude_to_String((params.standardParallel()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2185
        fprintf(outputFile, "%s", latitude_str);
 
2186
 
 
2187
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2188
        Meter_to_String(params.falseEasting(),meter_str);
 
2189
        fprintf(outputFile, "%s", meter_str);
 
2190
 
 
2191
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2192
        Meter_to_String(params.falseNorthing(),meter_str);
 
2193
        fprintf(outputFile, "%s", meter_str);
 
2194
        fprintf(outputFile, "\n");
 
2195
      }
 
2196
      else
 
2197
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2198
 
 
2199
      break;
 
2200
    }
 
2201
    case CoordinateType::polarStereographicScaleFactor:
 
2202
    {
 
2203
      if( dynamic_cast< PolarStereographicScaleFactorParameters* >( _targetParameters ) )
 
2204
      {
 
2205
        PolarStereographicScaleFactorParameters params = *dynamic_cast< PolarStereographicScaleFactorParameters* >( _targetParameters );
 
2206
 
 
2207
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2208
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2209
        fprintf(outputFile, "%s", longitude_str);
 
2210
 
 
2211
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2212
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2213
 
 
2214
        fprintf(outputFile, "\n%s: ", hemisphere_Header_String);
 
2215
        fprintf(outputFile, "%c", params.hemisphere());
 
2216
 
 
2217
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2218
        Meter_to_String(params.falseEasting(),meter_str);
 
2219
        fprintf(outputFile, "%s", meter_str);
 
2220
 
 
2221
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2222
        Meter_to_String(params.falseNorthing(),meter_str);
 
2223
        fprintf(outputFile, "%s", meter_str);
 
2224
        fprintf(outputFile, "\n");
 
2225
      }
 
2226
      else
 
2227
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2228
 
 
2229
      break;
 
2230
    }
 
2231
    case CoordinateType::azimuthalEquidistant:
 
2232
    case CoordinateType::bonne:
 
2233
    case CoordinateType::cassini:
 
2234
    case CoordinateType::cylindricalEqualArea:
 
2235
    case CoordinateType::gnomonic:
 
2236
    case CoordinateType::orthographic:
 
2237
    case CoordinateType::polyconic:
 
2238
    case CoordinateType::stereographic:
 
2239
    {
 
2240
      if( dynamic_cast< MapProjection4Parameters* >( _targetParameters ) )
 
2241
      {
 
2242
        MapProjection4Parameters params = *dynamic_cast< MapProjection4Parameters* >( _targetParameters );
 
2243
 
 
2244
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2245
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2246
        fprintf(outputFile, "%s", longitude_str);
 
2247
 
 
2248
        fprintf(outputFile, "\n%s: ", origin_Latitude_Header_String);
 
2249
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2250
        fprintf(outputFile, "%s", latitude_str);
 
2251
 
 
2252
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2253
        Meter_to_String(params.falseEasting(),meter_str);
 
2254
        fprintf(outputFile, "%s", meter_str);
 
2255
 
 
2256
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2257
        Meter_to_String(params.falseNorthing(),meter_str);
 
2258
        fprintf(outputFile, "%s", meter_str);
 
2259
        fprintf(outputFile, "\n");
 
2260
      }
 
2261
      else
 
2262
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2263
 
 
2264
      break;
 
2265
    }
 
2266
    case CoordinateType::eckert4:
 
2267
    case CoordinateType::eckert6:
 
2268
    case CoordinateType::millerCylindrical:
 
2269
    case CoordinateType::mollweide:
 
2270
    case CoordinateType::sinusoidal:
 
2271
    case CoordinateType::vanDerGrinten:
 
2272
    {
 
2273
      if( dynamic_cast< MapProjection3Parameters* >( _targetParameters ) )
 
2274
      {
 
2275
        MapProjection3Parameters params = *dynamic_cast< MapProjection3Parameters* >( _targetParameters );
 
2276
 
 
2277
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2278
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2279
        fprintf(outputFile, "%s", longitude_str);
 
2280
 
 
2281
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2282
        Meter_to_String(params.falseEasting(),meter_str);
 
2283
        fprintf(outputFile, "%s", meter_str);
 
2284
 
 
2285
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2286
        Meter_to_String(params.falseNorthing(),meter_str);
 
2287
        fprintf(outputFile, "%s", meter_str);
 
2288
        fprintf(outputFile, "\n");
 
2289
      }
 
2290
      else
 
2291
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2292
 
 
2293
      break;
 
2294
    }
 
2295
    case CoordinateType::equidistantCylindrical:
 
2296
    {
 
2297
      if( dynamic_cast< EquidistantCylindricalParameters* >( _targetParameters ) )
 
2298
      {
 
2299
        EquidistantCylindricalParameters params = *dynamic_cast< EquidistantCylindricalParameters* >( _targetParameters );
 
2300
 
 
2301
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2302
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2303
        fprintf(outputFile, "%s", longitude_str);
 
2304
 
 
2305
        fprintf(outputFile, "\n%s: ", standard_Parallel_Header_String);
 
2306
        Latitude_to_String((params.standardParallel()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2307
        fprintf(outputFile, "%s", latitude_str);
 
2308
 
 
2309
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2310
        Meter_to_String(params.falseEasting(),meter_str);
 
2311
        fprintf(outputFile, "%s", meter_str);
 
2312
 
 
2313
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2314
        Meter_to_String(params.falseNorthing(),meter_str);
 
2315
        fprintf(outputFile, "%s", meter_str);
 
2316
        fprintf(outputFile, "\n");
 
2317
      }
 
2318
      else
 
2319
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2320
 
 
2321
      break;
 
2322
    }
 
2323
    case CoordinateType::neys:
 
2324
    {
 
2325
      if( dynamic_cast< NeysParameters* >( _targetParameters ) )
 
2326
      {
 
2327
        NeysParameters params = *dynamic_cast< NeysParameters* >( _targetParameters );
 
2328
 
 
2329
        fprintf(outputFile, "%s: ", central_Meridian_Header_String);
 
2330
        Longitude_to_String((params.centralMeridian()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2331
        fprintf(outputFile, "%s", longitude_str);
 
2332
 
 
2333
        fprintf(outputFile, "\n%s: ", origin_Latitude_Header_String);
 
2334
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2335
        fprintf(outputFile, "%s", latitude_str);
 
2336
 
 
2337
        fprintf(outputFile, "\n%s: ", standard_Parallel_One_Header_String);
 
2338
        Latitude_to_String((params.standardParallel1()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2339
        fprintf(outputFile, "%s", latitude_str);
 
2340
 
 
2341
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2342
        Meter_to_String(params.falseEasting(),meter_str);
 
2343
        fprintf(outputFile, "%s", meter_str);
 
2344
 
 
2345
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2346
        Meter_to_String(params.falseNorthing(),meter_str);
 
2347
        fprintf(outputFile, "%s", meter_str);
 
2348
        fprintf(outputFile, "\n");
 
2349
      }
 
2350
      else
 
2351
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2352
 
 
2353
      break;
 
2354
    }
 
2355
    case CoordinateType::obliqueMercator:
 
2356
    {
 
2357
      if( dynamic_cast< ObliqueMercatorParameters* >( _targetParameters ) )
 
2358
      {
 
2359
        ObliqueMercatorParameters params = *dynamic_cast< ObliqueMercatorParameters* >( _targetParameters );
 
2360
 
 
2361
        fprintf(outputFile, "%s: ", origin_Latitude_Header_String);
 
2362
        Latitude_to_String((params.originLatitude()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2363
        fprintf(outputFile, "%s", latitude_str);
 
2364
 
 
2365
        fprintf(outputFile, "\n%s: ", latitude_One_Header_String);
 
2366
        Latitude_to_String((params.latitude1()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2367
        fprintf(outputFile, "%s", latitude_str);
 
2368
 
 
2369
        fprintf(outputFile, "\n%s: ", longitude_One_Header_String);
 
2370
        Longitude_to_String((params.longitude1()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2371
        fprintf(outputFile, "%s", longitude_str);
 
2372
 
 
2373
        fprintf(outputFile, "\n%s: ", latitude_Two_Header_String);
 
2374
        Latitude_to_String((params.latitude2()*180)/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2375
        fprintf(outputFile, "%s", latitude_str);
 
2376
 
 
2377
        fprintf(outputFile, "\n%s: ", longitude_Two_Header_String);
 
2378
        Longitude_to_String((params.longitude2()*180)/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
2379
        fprintf(outputFile, "%s", longitude_str);
 
2380
 
 
2381
        fprintf(outputFile, "\n%s: ", scale_Factor_Header_String);
 
2382
        fprintf(outputFile, "%.5f", params.scaleFactor());
 
2383
 
 
2384
        fprintf(outputFile, "\n%s: ", false_Easting_Header_String);
 
2385
        Meter_to_String(params.falseEasting(),meter_str);
 
2386
        fprintf(outputFile, "%s", meter_str);
 
2387
 
 
2388
        fprintf(outputFile, "\n%s: ", false_Northing_Header_String);
 
2389
        Meter_to_String(params.falseNorthing(),meter_str);
 
2390
        fprintf(outputFile, "%s", meter_str);
 
2391
        fprintf(outputFile, "\n");
 
2392
      }
 
2393
      else
 
2394
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2395
 
 
2396
      break;
 
2397
    }
 
2398
  }
 
2399
 
 
2400
  fprintf(outputFile, "%s\n\n", end_Of_Header_String);
 
2401
}
 
2402
 
 
2403
 
 
2404
void Fiomeths::setCoordinateSystemParameters( MSP::CCS::CoordinateSystemParameters* parameters )
 
2405
{
 
2406
/*
 
2407
 *  The function setCoordinateSystem sets the coordinate system.
 
2408
 *
 
2409
 *  parameters : Coordinate system parameters to be used               (input)
 
2410
 */
 
2411
 
 
2412
  switch( parameters->coordinateType() )
 
2413
  {
 
2414
    case CoordinateType::albersEqualAreaConic:
 
2415
      if( dynamic_cast< MapProjection6Parameters* >( parameters ) )
 
2416
        targetParameters = new MapProjection6Parameters( *dynamic_cast< MapProjection6Parameters* >( parameters ) );
 
2417
      else
 
2418
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2419
     break;
 
2420
    case CoordinateType::azimuthalEquidistant:
 
2421
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2422
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2423
      else
 
2424
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2425
      break;
 
2426
    case CoordinateType::bonne:
 
2427
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2428
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2429
      else
 
2430
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2431
      break;
 
2432
    case CoordinateType::britishNationalGrid:
 
2433
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2434
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2435
      else
 
2436
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2437
      break;
 
2438
    case CoordinateType::cassini:
 
2439
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2440
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2441
      else
 
2442
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2443
      break;
 
2444
    case CoordinateType::cylindricalEqualArea:
 
2445
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2446
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2447
      else
 
2448
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2449
      break;
 
2450
    case CoordinateType::eckert4:
 
2451
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2452
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2453
      else
 
2454
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2455
      break;
 
2456
    case CoordinateType::eckert6:
 
2457
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2458
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2459
      else
 
2460
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2461
      break;
 
2462
    case CoordinateType::equidistantCylindrical:
 
2463
      if( dynamic_cast< EquidistantCylindricalParameters* >( parameters ) )
 
2464
        targetParameters = new EquidistantCylindricalParameters( *dynamic_cast< EquidistantCylindricalParameters* >( parameters ) );
 
2465
      else
 
2466
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2467
      break;
 
2468
    case CoordinateType::geocentric:
 
2469
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2470
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2471
      else
 
2472
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2473
      break;
 
2474
    case CoordinateType::geodetic:
 
2475
      if( dynamic_cast< GeodeticParameters* >( parameters ) )
 
2476
        targetParameters = new GeodeticParameters( *dynamic_cast< GeodeticParameters* >( parameters ) );
 
2477
      else
 
2478
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2479
      break;
 
2480
    case CoordinateType::georef:
 
2481
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2482
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2483
      else
 
2484
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2485
      break;
 
2486
    case CoordinateType::globalAreaReferenceSystem:
 
2487
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2488
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2489
      else
 
2490
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2491
      break;
 
2492
    case CoordinateType::gnomonic:
 
2493
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2494
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2495
      else
 
2496
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2497
      break;
 
2498
    case CoordinateType::lambertConformalConic1Parallel:
 
2499
      if( dynamic_cast< MapProjection5Parameters* >( parameters ) )
 
2500
        targetParameters = new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
 
2501
      else
 
2502
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2503
      break;
 
2504
    case CoordinateType::lambertConformalConic2Parallels:
 
2505
      if( dynamic_cast< MapProjection6Parameters* >( parameters ) )
 
2506
        targetParameters = new MapProjection6Parameters( *dynamic_cast< MapProjection6Parameters* >( parameters ) );
 
2507
      else
 
2508
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2509
      break;
 
2510
    case CoordinateType::localCartesian:
 
2511
      if( dynamic_cast< LocalCartesianParameters* >( parameters ) )
 
2512
        targetParameters = new LocalCartesianParameters( *dynamic_cast< LocalCartesianParameters* >( parameters ) );
 
2513
      else
 
2514
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2515
      break;
 
2516
    case CoordinateType::mercatorStandardParallel:
 
2517
      if( dynamic_cast< MercatorStandardParallelParameters* >( parameters ) )
 
2518
        targetParameters = new MercatorStandardParallelParameters( *dynamic_cast< MercatorStandardParallelParameters* >( parameters ) );
 
2519
      else
 
2520
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2521
      break;
 
2522
    case CoordinateType::mercatorScaleFactor:
 
2523
      if( dynamic_cast< MercatorScaleFactorParameters* >( parameters ) )
 
2524
        targetParameters = new MercatorScaleFactorParameters( *dynamic_cast< MercatorScaleFactorParameters* >( parameters ) );
 
2525
      else
 
2526
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2527
      break;
 
2528
    case CoordinateType::militaryGridReferenceSystem:
 
2529
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2530
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2531
      else
 
2532
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2533
      break;
 
2534
    case CoordinateType::millerCylindrical:
 
2535
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2536
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2537
      else
 
2538
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2539
      break;
 
2540
    case CoordinateType::mollweide:
 
2541
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2542
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2543
      else
 
2544
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2545
      break;
 
2546
    case CoordinateType::newZealandMapGrid:
 
2547
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2548
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2549
      else
 
2550
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2551
      break;
 
2552
    case CoordinateType::neys:
 
2553
      if( dynamic_cast< NeysParameters* >( parameters ) )
 
2554
        targetParameters = new NeysParameters( *dynamic_cast< NeysParameters* >( parameters ) );
 
2555
      else
 
2556
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2557
      break;
 
2558
    case CoordinateType::obliqueMercator:
 
2559
      if( dynamic_cast< ObliqueMercatorParameters* >( parameters ) )
 
2560
        targetParameters = new ObliqueMercatorParameters( *dynamic_cast< ObliqueMercatorParameters* >( parameters ) );
 
2561
      else
 
2562
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2563
      break;
 
2564
    case CoordinateType::orthographic:
 
2565
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2566
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2567
      else
 
2568
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2569
      break;
 
2570
    case CoordinateType::polarStereographicStandardParallel:
 
2571
      if( dynamic_cast< PolarStereographicStandardParallelParameters* >( parameters ) )
 
2572
        targetParameters = new PolarStereographicStandardParallelParameters( *dynamic_cast< PolarStereographicStandardParallelParameters* >( parameters ) );
 
2573
      else
 
2574
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2575
      break;
 
2576
    case CoordinateType::polarStereographicScaleFactor:
 
2577
      if( dynamic_cast< PolarStereographicScaleFactorParameters* >( parameters ) )
 
2578
        targetParameters = new PolarStereographicScaleFactorParameters( *dynamic_cast< PolarStereographicScaleFactorParameters* >( parameters ) );
 
2579
      else
 
2580
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2581
      break;
 
2582
    case CoordinateType::polyconic:
 
2583
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2584
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2585
      else
 
2586
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2587
      break;
 
2588
    case CoordinateType::sinusoidal:
 
2589
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2590
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2591
      else
 
2592
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2593
      break;
 
2594
    case CoordinateType::stereographic:
 
2595
      if( dynamic_cast< MapProjection4Parameters* >( parameters ) )
 
2596
        targetParameters = new MapProjection4Parameters( *dynamic_cast< MapProjection4Parameters* >( parameters ) );
 
2597
      else
 
2598
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2599
      break;
 
2600
    case CoordinateType::transverseCylindricalEqualArea:
 
2601
      if( dynamic_cast< MapProjection5Parameters* >( parameters ) )
 
2602
        targetParameters = new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
 
2603
      else
 
2604
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2605
      break;
 
2606
    case CoordinateType::transverseMercator:
 
2607
      if( dynamic_cast< MapProjection5Parameters* >( parameters ) )
 
2608
        targetParameters = new MapProjection5Parameters( *dynamic_cast< MapProjection5Parameters* >( parameters ) );
 
2609
      else
 
2610
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2611
      break;
 
2612
    case CoordinateType::universalPolarStereographic:
 
2613
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2614
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2615
      else
 
2616
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2617
      break;
 
2618
    case CoordinateType::universalTransverseMercator:
 
2619
      if( dynamic_cast< UTMParameters* >( parameters ) )
 
2620
        targetParameters = new UTMParameters( *dynamic_cast< UTMParameters* >( parameters ) );
 
2621
      else
 
2622
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2623
      break;
 
2624
    case CoordinateType::usNationalGrid:
 
2625
      if( dynamic_cast< CoordinateSystemParameters* >( parameters ) )
 
2626
        targetParameters = new CoordinateSystemParameters( *dynamic_cast< CoordinateSystemParameters* >( parameters ) );
 
2627
      else
 
2628
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2629
      break;
 
2630
    case CoordinateType::vanDerGrinten:
 
2631
      if( dynamic_cast< MapProjection3Parameters* >( parameters ) )
 
2632
        targetParameters = new MapProjection3Parameters( *dynamic_cast< MapProjection3Parameters* >( parameters ) );
 
2633
      else
 
2634
        throw CoordinateConversionException( FileErrorMessages::invalidTargetParameters );
 
2635
      break;
 
2636
    default:
 
2637
      throw CoordinateConversionException( FileErrorMessages::invalidTargetCoordinateSystem );
 
2638
  }
 
2639
}
 
2640
 
 
2641
 
 
2642
CoordinateTuple* Fiomeths::readCoordinate()
 
2643
{
 
2644
  long tempErrorCode = 0;
 
2645
 
 
2646
  switch(sourceProjectionType)
 
2647
  {
 
2648
    case CoordinateType::geodetic:
 
2649
    {
 
2650
      char buf[256] = "";
 
2651
      long length;
 
2652
      double temp_val = 0;
 
2653
      double longitude = 0;
 
2654
      double latitude = 0;
 
2655
      double height = 0;
 
2656
 
 
2657
      Eat_Noise(inputFile);
 
2658
      if (!feof(inputFile) && (fscanf(inputFile, "%255[^,\t\n]", buf)))
 
2659
      {
 
2660
        if( inputLatitudeLongitudeOrder )  // first value is latitude
 
2661
          tempErrorCode = String_to_Latitude(buf, &temp_val);
 
2662
        else                      // first value is longitude
 
2663
          tempErrorCode = String_to_Longitude(buf, &temp_val);
 
2664
 
 
2665
        if(!tempErrorCode)
 
2666
        {
 
2667
          if( inputLatitudeLongitudeOrder )  // first value is latitude
 
2668
            latitude = temp_val*PI/180;
 
2669
          else                      // first value is longitude
 
2670
            longitude =(temp_val*PI)/180;
 
2671
 
 
2672
          fscanf(inputFile, "%[, \t]", buf);
 
2673
          if (!feof(inputFile) && (fscanf(inputFile, "%255[^,\t\n#;]", buf)))
 
2674
          {
 
2675
            length = strlen(buf)-1;
 
2676
            if (!isdigit(buf[length]) && !isalpha(buf[length]))
 
2677
              buf[length] = 0;
 
2678
 
 
2679
            if( inputLatitudeLongitudeOrder )  // second value is longitude
 
2680
              tempErrorCode = String_to_Longitude(buf, &temp_val);
 
2681
            else                      // second value is latitude
 
2682
              tempErrorCode = String_to_Latitude(buf, &temp_val);
 
2683
 
 
2684
            if(!tempErrorCode)
 
2685
            {
 
2686
              if( inputLatitudeLongitudeOrder )  // second value is longitude
 
2687
                longitude = temp_val*PI/180;
 
2688
              else                     // second value is latitude
 
2689
                latitude =(temp_val*PI)/180;
 
2690
 
 
2691
              /*only read height if not No Height*/
 
2692
              if(geodeticParameters && geodeticParameters->heightType() != HeightType::noHeight)
 
2693
              {
 
2694
                fscanf(inputFile, "%[, \t]", buf);
 
2695
                if (!feof(inputFile) && (fscanf(inputFile, "%[^, \t\n#;]", buf)))
 
2696
                {
 
2697
                  length = strlen(buf)-1;
 
2698
                  if (!isdigit(buf[length]))
 
2699
                    buf[length] = 0;
 
2700
                  double tempHeight;
 
2701
                  tempErrorCode = String_to_Double(buf,&tempHeight);
 
2702
                  height = tempHeight;
 
2703
                }
 
2704
                return new GeodeticCoordinates(CoordinateType::geodetic, longitude, latitude, height);
 
2705
              }
 
2706
              else
 
2707
                return new GeodeticCoordinates(CoordinateType::geodetic, longitude, latitude, 0.0);
 
2708
 
 
2709
            }
 
2710
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2711
          }
 
2712
          else
 
2713
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2714
        }
 
2715
        else
 
2716
          throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2717
      }
 
2718
      else
 
2719
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2720
      break;
 
2721
    }
 
2722
    case CoordinateType::georef:
 
2723
    {
 
2724
      char return_Parameter[32];
 
2725
      int i = 0;
 
2726
 
 
2727
      Eat_Noise(inputFile);
 
2728
      if (!feof(inputFile) && (fscanf(inputFile, "%255[1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]", return_Parameter)))
 
2729
      {
 
2730
        for (i = 0;(unsigned int)i < strlen(return_Parameter); i++)
 
2731
          return_Parameter[i] = (char)toupper(return_Parameter[i]);
 
2732
 
 
2733
        return new GEOREFCoordinates(CoordinateType::georef, return_Parameter);
 
2734
      }
 
2735
      else
 
2736
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2737
 
 
2738
      break;
 
2739
    }
 
2740
    case CoordinateType::localCartesian:
 
2741
    {
 
2742
      char buf[256];
 
2743
      double x, y, z;
 
2744
 
 
2745
      Eat_Noise(inputFile);
 
2746
      tempErrorCode = readCoord( &x, &y );
 
2747
      if(!tempErrorCode)
 
2748
      {
 
2749
        fscanf(inputFile, "%[, \t]", buf);
 
2750
        if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n;]", buf)))
 
2751
        {
 
2752
          tempErrorCode = String_to_Double( buf, &z );
 
2753
          if(!tempErrorCode)
 
2754
          {
 
2755
            return new CartesianCoordinates(CoordinateType::localCartesian, x, y, z);
 
2756
          }
 
2757
          if( tempErrorCode )
 
2758
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2759
        }
 
2760
        else
 
2761
          throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2762
      }
 
2763
    }
 
2764
    case CoordinateType::geocentric:
 
2765
    {
 
2766
      char buf[256];
 
2767
      double x, y, z;
 
2768
 
 
2769
      Eat_Noise(inputFile);
 
2770
      tempErrorCode = readCoord( &x, &y );
 
2771
      if(!tempErrorCode)
 
2772
      {
 
2773
        fscanf(inputFile, "%[, \t]", buf);
 
2774
        if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n;]", buf)))
 
2775
        {
 
2776
          tempErrorCode = String_to_Double( buf, &z );
 
2777
          if(!tempErrorCode)
 
2778
          {
 
2779
            return new CartesianCoordinates(CoordinateType::geocentric, x, y, z);
 
2780
          }
 
2781
          if( tempErrorCode )
 
2782
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2783
        }
 
2784
        else
 
2785
          throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2786
      }
 
2787
    }
 
2788
    case CoordinateType::militaryGridReferenceSystem:
 
2789
    {
 
2790
      char return_Parameter[32];
 
2791
      int i = 0;
 
2792
 
 
2793
      Eat_Noise(inputFile);
 
2794
      if (!feof(inputFile) && (fscanf(inputFile, "%255[1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]", return_Parameter)))
 
2795
      {
 
2796
        for (i = 0;(unsigned int)i < strlen(return_Parameter); i++)
 
2797
          return_Parameter[i] = (char)toupper(return_Parameter[i]);
 
2798
        return new MGRSorUSNGCoordinates(CoordinateType::militaryGridReferenceSystem, return_Parameter, Precision::tenthOfSecond);
 
2799
      }
 
2800
      else
 
2801
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2802
 
 
2803
      break;
 
2804
    }
 
2805
    case CoordinateType::usNationalGrid:
 
2806
    {
 
2807
      char return_Parameter[32];
 
2808
      int i = 0;
 
2809
 
 
2810
      Eat_Noise(inputFile);
 
2811
      if (!feof(inputFile) && (fscanf(inputFile, "%255[1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]", return_Parameter)))
 
2812
      {
 
2813
        for (i = 0;(unsigned int)i < strlen(return_Parameter); i++)
 
2814
          return_Parameter[i] = (char)toupper(return_Parameter[i]);
 
2815
        return new MGRSorUSNGCoordinates(CoordinateType::usNationalGrid, return_Parameter, Precision::tenthOfSecond);
 
2816
      }
 
2817
      else
 
2818
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2819
 
 
2820
      break;
 
2821
    }
 
2822
    case CoordinateType::universalTransverseMercator:
 
2823
    {
 
2824
      char buf[256];
 
2825
      long zone;
 
2826
      char hemisphere;
 
2827
      double easting, northing;
 
2828
      double temp = 0;
 
2829
 
 
2830
      Eat_Noise(inputFile);
 
2831
      if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n]", buf)))
 
2832
      {
 
2833
        tempErrorCode = String_to_Double(buf,&temp);
 
2834
        if(!tempErrorCode)
 
2835
        {
 
2836
          zone = (long)temp;
 
2837
          fscanf(inputFile, "%[, \t]", buf);
 
2838
          if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n]", &hemisphere)))
 
2839
          {
 
2840
            hemisphere = (char)toupper(hemisphere);
 
2841
            if ((hemisphere != 'N') && (hemisphere != 'S'))
 
2842
              throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2843
            else
 
2844
            {
 
2845
              fscanf(inputFile, "%[, \t]", buf);
 
2846
              tempErrorCode = readCoord( &easting, &northing );
 
2847
              if(!tempErrorCode)
 
2848
              {
 
2849
                return new UTMCoordinates(CoordinateType::universalTransverseMercator, zone, hemisphere, easting, northing);
 
2850
              }
 
2851
              else
 
2852
                throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2853
            }
 
2854
          }
 
2855
          else
 
2856
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2857
        }
 
2858
      }
 
2859
      else
 
2860
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2861
      break;
 
2862
    }
 
2863
    case CoordinateType::universalPolarStereographic:
 
2864
    {
 
2865
      char buf[256];
 
2866
      char hemisphere;
 
2867
      double easting, northing;
 
2868
 
 
2869
      Eat_Noise(inputFile);
 
2870
      if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n]", &hemisphere)))
 
2871
      {
 
2872
        hemisphere = (char)toupper(hemisphere);
 
2873
        if ((hemisphere != 'N') && (hemisphere != 'S'))
 
2874
          throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2875
        else
 
2876
        {
 
2877
          fscanf(inputFile, "%[, \t]", buf);
 
2878
          tempErrorCode = readCoord(&easting, &northing);
 
2879
          if(!tempErrorCode)
 
2880
          {
 
2881
            return new UPSCoordinates(CoordinateType::universalPolarStereographic, hemisphere, easting, northing);
 
2882
          }
 
2883
          if( tempErrorCode )
 
2884
            throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2885
        }
 
2886
      }
 
2887
      else
 
2888
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2889
      break;
 
2890
    }
 
2891
    case CoordinateType::albersEqualAreaConic:
 
2892
    {
 
2893
      double easting, northing;
 
2894
 
 
2895
      Eat_Noise(inputFile);
 
2896
      tempErrorCode = readCoord( &easting, &northing );
 
2897
      if(!tempErrorCode)
 
2898
      {
 
2899
        return new MapProjectionCoordinates(CoordinateType::albersEqualAreaConic, easting, northing);
 
2900
      }
 
2901
      else
 
2902
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2903
      break;
 
2904
    }
 
2905
    case CoordinateType::azimuthalEquidistant:
 
2906
    {
 
2907
      double easting, northing;
 
2908
 
 
2909
      Eat_Noise(inputFile);
 
2910
      tempErrorCode = readCoord( &easting, &northing );
 
2911
      if(!tempErrorCode)
 
2912
      {
 
2913
        return new MapProjectionCoordinates(CoordinateType::azimuthalEquidistant, easting, northing);
 
2914
      }
 
2915
      else
 
2916
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2917
      break;
 
2918
    }
 
2919
    case CoordinateType::bonne:
 
2920
    {
 
2921
      double easting, northing;
 
2922
 
 
2923
      Eat_Noise(inputFile);
 
2924
      tempErrorCode = readCoord( &easting, &northing );
 
2925
      if(!tempErrorCode)
 
2926
      {
 
2927
        return new MapProjectionCoordinates(CoordinateType::bonne, easting, northing);
 
2928
      }
 
2929
      else
 
2930
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2931
      break;
 
2932
    }
 
2933
    case CoordinateType::cassini:
 
2934
    {
 
2935
      double easting, northing;
 
2936
 
 
2937
      Eat_Noise(inputFile);
 
2938
      tempErrorCode = readCoord( &easting, &northing );
 
2939
      if(!tempErrorCode)
 
2940
      {
 
2941
        return new MapProjectionCoordinates(CoordinateType::cassini, easting, northing);
 
2942
      }
 
2943
      else
 
2944
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2945
      break;
 
2946
    }
 
2947
    case CoordinateType::cylindricalEqualArea:
 
2948
    {
 
2949
      double easting, northing;
 
2950
 
 
2951
      Eat_Noise(inputFile);
 
2952
      tempErrorCode = readCoord( &easting, &northing );
 
2953
      if(!tempErrorCode)
 
2954
      {
 
2955
        return new MapProjectionCoordinates(CoordinateType::cylindricalEqualArea, easting, northing);
 
2956
      }
 
2957
      else
 
2958
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2959
      break;
 
2960
    }
 
2961
    case CoordinateType::eckert4:
 
2962
    {
 
2963
      double easting, northing;
 
2964
 
 
2965
      Eat_Noise(inputFile);
 
2966
      tempErrorCode = readCoord( &easting, &northing );
 
2967
      if(!tempErrorCode)
 
2968
      {
 
2969
        return new MapProjectionCoordinates(CoordinateType::eckert4, easting, northing);
 
2970
      }
 
2971
      else
 
2972
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2973
      break;
 
2974
    }
 
2975
    case CoordinateType::eckert6:
 
2976
    {
 
2977
      double easting, northing;
 
2978
 
 
2979
      Eat_Noise(inputFile);
 
2980
      tempErrorCode = readCoord( &easting, &northing );
 
2981
      if(!tempErrorCode)
 
2982
      {
 
2983
        return new MapProjectionCoordinates(CoordinateType::eckert6, easting, northing);
 
2984
      }
 
2985
      else
 
2986
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
2987
      break;
 
2988
    }
 
2989
    case CoordinateType::equidistantCylindrical:
 
2990
    {
 
2991
      double easting, northing;
 
2992
 
 
2993
      Eat_Noise(inputFile);
 
2994
      tempErrorCode = readCoord( &easting, &northing );
 
2995
      if(!tempErrorCode)
 
2996
      {
 
2997
        return new MapProjectionCoordinates(CoordinateType::equidistantCylindrical, easting, northing);
 
2998
      }
 
2999
      else
 
3000
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3001
      break;
 
3002
    }
 
3003
    case CoordinateType::gnomonic:
 
3004
    {
 
3005
      double easting, northing;
 
3006
 
 
3007
      Eat_Noise(inputFile);
 
3008
      tempErrorCode = readCoord( &easting, &northing );
 
3009
      if(!tempErrorCode)
 
3010
      {
 
3011
        return new MapProjectionCoordinates(CoordinateType::gnomonic, easting, northing);
 
3012
      }
 
3013
      else
 
3014
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3015
      break;
 
3016
    }
 
3017
    case CoordinateType::lambertConformalConic1Parallel:
 
3018
    {
 
3019
      double easting, northing;
 
3020
 
 
3021
      Eat_Noise(inputFile);
 
3022
      tempErrorCode = readCoord( &easting, &northing );
 
3023
      if(!tempErrorCode)
 
3024
      {
 
3025
        return new MapProjectionCoordinates(CoordinateType::lambertConformalConic1Parallel, easting, northing);
 
3026
      }
 
3027
      else
 
3028
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3029
      break;
 
3030
    }
 
3031
    case CoordinateType::lambertConformalConic2Parallels:
 
3032
    {
 
3033
      double easting, northing;
 
3034
 
 
3035
      Eat_Noise(inputFile);
 
3036
      tempErrorCode = readCoord( &easting, &northing );
 
3037
      if(!tempErrorCode)
 
3038
      {
 
3039
        return new MapProjectionCoordinates(CoordinateType::lambertConformalConic2Parallels, easting, northing);
 
3040
      }
 
3041
      else
 
3042
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3043
      break;
 
3044
    }
 
3045
    case CoordinateType::mercatorStandardParallel:
 
3046
    {
 
3047
      double easting, northing;
 
3048
 
 
3049
      Eat_Noise(inputFile);
 
3050
      tempErrorCode = readCoord( &easting, &northing );
 
3051
      if(!tempErrorCode)
 
3052
      {
 
3053
        return new MapProjectionCoordinates(CoordinateType::mercatorStandardParallel, easting, northing);
 
3054
      }
 
3055
      else
 
3056
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3057
      break;
 
3058
    }
 
3059
    case CoordinateType::mercatorScaleFactor:
 
3060
    {
 
3061
      double easting, northing;
 
3062
 
 
3063
      Eat_Noise(inputFile);
 
3064
      tempErrorCode = readCoord( &easting, &northing );
 
3065
      if(!tempErrorCode)
 
3066
      {
 
3067
        return new MapProjectionCoordinates(CoordinateType::mercatorScaleFactor, easting, northing);
 
3068
      }
 
3069
      else
 
3070
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3071
      break;
 
3072
    }
 
3073
    case CoordinateType::millerCylindrical:
 
3074
    {
 
3075
      double easting, northing;
 
3076
 
 
3077
      Eat_Noise(inputFile);
 
3078
      tempErrorCode = readCoord( &easting, &northing );
 
3079
      if(!tempErrorCode)
 
3080
      {
 
3081
        return new MapProjectionCoordinates(CoordinateType::millerCylindrical, easting, northing);
 
3082
      }
 
3083
      else
 
3084
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3085
      break;
 
3086
    }
 
3087
    case CoordinateType::mollweide:
 
3088
    {
 
3089
      double easting, northing;
 
3090
 
 
3091
      Eat_Noise(inputFile);
 
3092
      tempErrorCode = readCoord( &easting, &northing );
 
3093
      if(!tempErrorCode)
 
3094
      {
 
3095
        return new MapProjectionCoordinates(CoordinateType::mollweide, easting, northing);
 
3096
      }
 
3097
      else
 
3098
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3099
      break;
 
3100
    }
 
3101
    case CoordinateType::neys:
 
3102
    {
 
3103
      double easting, northing;
 
3104
 
 
3105
      Eat_Noise(inputFile);
 
3106
      tempErrorCode = readCoord( &easting, &northing );
 
3107
      if(!tempErrorCode)
 
3108
      {
 
3109
        return new MapProjectionCoordinates(CoordinateType::neys, easting, northing);
 
3110
      }
 
3111
      else
 
3112
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3113
      break;
 
3114
    }
 
3115
    case CoordinateType::newZealandMapGrid:
 
3116
    {
 
3117
      double easting, northing;
 
3118
 
 
3119
      Eat_Noise(inputFile);
 
3120
      tempErrorCode = readCoord( &easting, &northing );
 
3121
      if(!tempErrorCode)
 
3122
      {
 
3123
        return new MapProjectionCoordinates(CoordinateType::newZealandMapGrid, easting, northing);
 
3124
      }
 
3125
      else
 
3126
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3127
      break;
 
3128
    }
 
3129
    case CoordinateType::obliqueMercator:
 
3130
    {
 
3131
      double easting, northing;
 
3132
 
 
3133
      Eat_Noise(inputFile);
 
3134
      tempErrorCode = readCoord( &easting, &northing );
 
3135
      if(!tempErrorCode)
 
3136
      {
 
3137
        return new MapProjectionCoordinates(CoordinateType::obliqueMercator, easting, northing);
 
3138
      }
 
3139
      else
 
3140
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3141
      break;
 
3142
    }
 
3143
    case CoordinateType::orthographic:
 
3144
    {
 
3145
      double easting, northing;
 
3146
 
 
3147
      Eat_Noise(inputFile);
 
3148
      tempErrorCode = readCoord( &easting, &northing );
 
3149
      if(!tempErrorCode)
 
3150
      {
 
3151
        return new MapProjectionCoordinates(CoordinateType::orthographic, easting, northing);
 
3152
      }
 
3153
      else
 
3154
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3155
      break;
 
3156
    }
 
3157
    case CoordinateType::polarStereographicStandardParallel:
 
3158
    {
 
3159
      double easting, northing;
 
3160
 
 
3161
      Eat_Noise(inputFile);
 
3162
      tempErrorCode = readCoord( &easting, &northing );
 
3163
      if(!tempErrorCode)
 
3164
      {
 
3165
        return new MapProjectionCoordinates(CoordinateType::polarStereographicStandardParallel, easting, northing);
 
3166
      }
 
3167
      else
 
3168
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3169
      break;
 
3170
    }
 
3171
    case CoordinateType::polarStereographicScaleFactor:
 
3172
    {
 
3173
      double easting, northing;
 
3174
 
 
3175
      Eat_Noise(inputFile);
 
3176
      tempErrorCode = readCoord( &easting, &northing );
 
3177
      if(!tempErrorCode)
 
3178
      {
 
3179
        return new MapProjectionCoordinates(CoordinateType::polarStereographicScaleFactor, easting, northing);
 
3180
      }
 
3181
      else
 
3182
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3183
      break;
 
3184
    }
 
3185
    case CoordinateType::polyconic:
 
3186
    {
 
3187
      double easting, northing;
 
3188
 
 
3189
      Eat_Noise(inputFile);
 
3190
      tempErrorCode = readCoord( &easting, &northing );
 
3191
      if(!tempErrorCode)
 
3192
      {
 
3193
        return new MapProjectionCoordinates(CoordinateType::polyconic, easting, northing);
 
3194
      }
 
3195
      else
 
3196
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3197
      break;
 
3198
    }
 
3199
    case CoordinateType::sinusoidal:
 
3200
    {
 
3201
      double easting, northing;
 
3202
 
 
3203
      Eat_Noise(inputFile);
 
3204
      tempErrorCode = readCoord( &easting, &northing );
 
3205
      if(!tempErrorCode)
 
3206
      {
 
3207
        return new MapProjectionCoordinates(CoordinateType::sinusoidal, easting, northing);
 
3208
      }
 
3209
      else
 
3210
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3211
      break;
 
3212
    }
 
3213
    case CoordinateType::stereographic:
 
3214
    {
 
3215
      double easting, northing;
 
3216
 
 
3217
      Eat_Noise(inputFile);
 
3218
      tempErrorCode = readCoord( &easting, &northing );
 
3219
      if(!tempErrorCode)
 
3220
      {
 
3221
        return new MapProjectionCoordinates(CoordinateType::stereographic, easting, northing);
 
3222
      }
 
3223
      else
 
3224
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3225
      break;
 
3226
    }
 
3227
    case CoordinateType::transverseCylindricalEqualArea:
 
3228
    {
 
3229
      double easting, northing;
 
3230
 
 
3231
      Eat_Noise(inputFile);
 
3232
      tempErrorCode = readCoord( &easting, &northing );
 
3233
      if(!tempErrorCode)
 
3234
      {
 
3235
        return new MapProjectionCoordinates(CoordinateType::transverseCylindricalEqualArea, easting, northing);
 
3236
      }
 
3237
      else
 
3238
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3239
      break;
 
3240
    }
 
3241
    case CoordinateType::transverseMercator:
 
3242
    {
 
3243
      double easting, northing;
 
3244
 
 
3245
      Eat_Noise(inputFile);
 
3246
      tempErrorCode = readCoord( &easting, &northing );
 
3247
      if(!tempErrorCode)
 
3248
      {
 
3249
        return new MapProjectionCoordinates(CoordinateType::transverseMercator, easting, northing);
 
3250
      }
 
3251
      else
 
3252
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3253
      break;
 
3254
    }
 
3255
    case CoordinateType::vanDerGrinten:
 
3256
    {
 
3257
      double easting, northing;
 
3258
 
 
3259
      Eat_Noise(inputFile);
 
3260
      tempErrorCode = readCoord( &easting, &northing );
 
3261
      if(!tempErrorCode)
 
3262
      {
 
3263
        return new MapProjectionCoordinates(CoordinateType::vanDerGrinten, easting, northing);
 
3264
      }
 
3265
      else
 
3266
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3267
      break;
 
3268
    }
 
3269
    case CoordinateType::britishNationalGrid:
 
3270
    {
 
3271
      BNGCoordinates coord;
 
3272
      char return_Parameter[32];
 
3273
      int i = 0;
 
3274
 
 
3275
      Eat_Noise(inputFile);
 
3276
      if (!feof(inputFile) && (fscanf(inputFile, "%255[ 1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]", return_Parameter)))
 
3277
      {
 
3278
        for (i = 0;(unsigned int)i < strlen(return_Parameter); i++)
 
3279
          return_Parameter[i] = (char)toupper(return_Parameter[i]);
 
3280
 
 
3281
        return new BNGCoordinates(CoordinateType::britishNationalGrid, return_Parameter);
 
3282
      }
 
3283
      else
 
3284
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3285
 
 
3286
      break;
 
3287
    }
 
3288
    case CoordinateType::globalAreaReferenceSystem:
 
3289
    {
 
3290
      GARSCoordinates coord;
 
3291
      char return_Parameter[32];
 
3292
      int i = 0;
 
3293
 
 
3294
      Eat_Noise(inputFile);
 
3295
      if (!feof(inputFile) && (fscanf(inputFile, "%255[1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]", return_Parameter)))
 
3296
      {
 
3297
        for (i = 0;(unsigned int)i < strlen(return_Parameter); i++)
 
3298
          return_Parameter[i] = (char)toupper(return_Parameter[i]);
 
3299
 
 
3300
        return new GARSCoordinates(CoordinateType::globalAreaReferenceSystem, return_Parameter);
 
3301
      }
 
3302
      else
 
3303
        throw CoordinateConversionException( FileErrorMessages::errorParsingFile );
 
3304
 
 
3305
      break;
 
3306
    }
 
3307
    default:
 
3308
      throw CoordinateConversionException( FileErrorMessages::invalidTargetCoordinateSystem );
 
3309
  }
 
3310
 
 
3311
  return 0;
 
3312
}
 
3313
 
 
3314
 
 
3315
long Fiomeths::readCoord(double *easting, double *northing)
 
3316
{
 
3317
  char buf[256];
 
3318
  FVC_Status error_Code = FVC_Success;
 
3319
 
 
3320
  if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n]", buf)))
 
3321
    error_Code = (FVC_Status)String_to_Double(buf, easting);
 
3322
  else
 
3323
    error_Code = FVC_Error;
 
3324
 
 
3325
  if(!error_Code)
 
3326
  {
 
3327
    fscanf(inputFile, "%[, \t]", buf);
 
3328
    if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n;]", buf)))
 
3329
      error_Code = (FVC_Status)String_to_Double(buf, northing);
 
3330
    else
 
3331
      error_Code = FVC_Error;
 
3332
  }
 
3333
  return error_Code;
 
3334
}
 
3335
 
 
3336
 
 
3337
long Fiomeths::readHeight(char* height)
 
3338
{
 
3339
  char buf[256];
 
3340
  FVC_Status error_Code = FVC_Success;
 
3341
 
 
3342
  fscanf(inputFile, "%[, \t]", buf);
 
3343
  if (!feof(inputFile) && (fscanf(inputFile, "%255[^, \t\n;]", buf)))
 
3344
    strcpy(height, buf);
 
3345
  else
 
3346
    error_Code = FVC_Error;
 
3347
 
 
3348
  return error_Code;
 
3349
}
 
3350
 
 
3351
 
 
3352
Accuracy* Fiomeths::readConversionErrors( char* errors )
 
3353
{
 
3354
  char buf[256] = "";
 
3355
  double ce90 = -1.0;
 
3356
  double le90 = -1.0;
 
3357
  double se90 = -1.0;
 
3358
  int index = 0;
 
3359
 
 
3360
  sscanf(errors, "%[^:\t]", buf);
 
3361
  if(strstr(errors, ce90_String))
 
3362
  {
 
3363
    index = strlen(buf);
 
3364
    buf[0] = 0;
 
3365
    sscanf(errors + index, "%[: ]", buf);
 
3366
    index += strlen(buf);
 
3367
    buf[0] = 0;
 
3368
    sscanf(errors + index, "%[^,]", buf);
 
3369
    if(strcmp(buf, "Unk") == 0)
 
3370
      ce90 = -1.0;
 
3371
    else
 
3372
      ce90 = atof(buf);
 
3373
    index += strlen(buf);
 
3374
    buf[0] = 0;
 
3375
 
 
3376
    sscanf(errors + index, "%[, ]", buf);
 
3377
    index += strlen(buf);
 
3378
    buf[0] = 0;
 
3379
    sscanf(errors + index, "%[^:\t]", buf);
 
3380
    if(strstr(errors, le90_String))
 
3381
    {
 
3382
      index += strlen(buf);
 
3383
      buf[0] = 0;
 
3384
      sscanf(errors + index, "%[: ]", buf);
 
3385
      index += strlen(buf);
 
3386
      buf[0] = 0;
 
3387
      sscanf(errors + index, "%[^,]", buf);
 
3388
      if(strcmp(buf, "Unk") == 0)
 
3389
        le90 = -1.0;
 
3390
      else
 
3391
        le90 = atof(buf);
 
3392
      index += strlen(buf);
 
3393
      buf[0] = 0;
 
3394
 
 
3395
      sscanf(errors + index, "%[, ]", buf);
 
3396
      index += strlen(buf);
 
3397
      buf[0] = 0;
 
3398
      sscanf(errors + index, "%[^:\t]", buf);
 
3399
      if(strstr(errors, se90_String))
 
3400
      {
 
3401
        index += strlen(buf);
 
3402
        buf[0] = 0;
 
3403
        sscanf(errors + index, "%[: ]", buf);
 
3404
        index += strlen(buf);
 
3405
        buf[0] = 0;
 
3406
        sscanf(errors + index, "%[^,\n]", buf);
 
3407
        if(strcmp(buf, "Unk") == 0 || strcmp(buf, "Unk ") == 0)
 
3408
          se90 = -1.0;
 
3409
        else
 
3410
          se90 = atof(buf);
 
3411
      }
 
3412
    }
 
3413
  }
 
3414
 
 
3415
  return new Accuracy( ce90, le90, se90 );
 
3416
}
 
3417
 
 
3418
 
 
3419
void Fiomeths::convert( std::vector<MSP::CCS::CoordinateTuple*>& sourceCoordinateCollection, std::vector<MSP::CCS::Accuracy*>& sourceAccuracyCollection, std::vector<TrailingHeight>& trailingHeightCollection, std::vector<MSP::CCS::CoordinateTuple*>& targetCoordinateCollection, std::vector<MSP::CCS::Accuracy*>& targetAccuracyCollection )
 
3420
{
 
3421
  int numSourceCoordinates = sourceCoordinateCollection.size();
 
3422
 
 
3423
  // Convert
 
3424
/*  std::vector<CoordinateTuple*> targetCoordinateCollection;
 
3425
  targetCoordinateCollection.reserve( numSourceCoordinates );
 
3426
  std::vector<Accuracy> targetAccuracyCollection;
 
3427
  targetAccuracyCollection.reserve( numSourceCoordinates );*/
 
3428
//  targetCoordinateCollection.reserve( numSourceCoordinates );
 
3429
//  targetAccuracyCollection.reserve( numSourceCoordinates );
 
3430
 
 
3431
  static clock_t startTime, stopTime;
 
3432
///  static time_t t_start, t_stop;
 
3433
 
 
3434
        startTime = clock();
 
3435
///     t_start = time( NULL );
 
3436
 
 
3437
  coordinateConversionService->convertSourceToTargetCollection( sourceCoordinateCollection, sourceAccuracyCollection, targetCoordinateCollection, targetAccuracyCollection );
 
3438
 
 
3439
        stopTime = clock();
 
3440
///     t_stop = time( NULL );
 
3441
 
 
3442
  _elapsedTime = ( double )( stopTime - startTime ) / CLOCKS_PER_SEC;
 
3443
///  _elapsedTime = ( double )( t_stop - t_start );
 
3444
 
 
3445
  // Write coordinates to output file
 
3446
  int numTargetCoordinates = targetCoordinateCollection.size();
 
3447
 
 
3448
  int numTargetAccuracies = targetAccuracyCollection.size();
 
3449
  int numTrailingHeights = trailingHeightCollection.size();
 
3450
 
 
3451
  if( ( numTargetCoordinates == numTargetAccuracies ) && ( numTargetCoordinates == numTrailingHeights ) )
 
3452
  {
 
3453
    for( int i = 0; i < numTargetCoordinates; i++ )
 
3454
    {
 
3455
      CoordinateTuple* targetCoordinate = targetCoordinateCollection[i];
 
3456
      Accuracy* targetAccuracy = targetAccuracyCollection[i];
 
3457
      TrailingHeight trailingHeight = trailingHeightCollection[i];
 
3458
 
 
3459
      if( targetCoordinate->coordinateType() == invalid )
 
3460
      {
 
3461
        Output_String( outputFile, targetCoordinate->errorMessage() );
 
3462
      }
 
3463
      else
 
3464
      {
 
3465
        // Write any warning messages
 
3466
        int length = strlen( targetCoordinate->warningMessage() );
 
3467
        if( length > 0 )
 
3468
        {
 
3469
          Output_String( outputFile, "# Warning: " );
 
3470
 
 
3471
          char buf[256];
 
3472
          const char* targetWarningMessage = targetCoordinate->warningMessage();
 
3473
 
 
3474
          int index = 0;
 
3475
          do
 
3476
          {
 
3477
            buf[0] = 0;
 
3478
            const char* tempWarningMessage = targetWarningMessage + index;
 
3479
            sscanf(tempWarningMessage, "%[^\n]", buf);
 
3480
            index += strlen( buf );
 
3481
            Output_String( outputFile, buf );
 
3482
            buf[0] = 0;
 
3483
            sscanf(targetWarningMessage + index, "%[\n]", buf);
 
3484
            index += strlen( buf );
 
3485
          }
 
3486
          while( strlen( buf ) > 0 && index < length );
 
3487
 
 
3488
          Output_Newline(outputFile);
 
3489
 
 
3490
          _numWarnings ++;
 
3491
        }
 
3492
 
 
3493
        // Write any error messages
 
3494
        length = strlen( targetCoordinate->errorMessage() );
 
3495
        if( length > 0)
 
3496
        {
 
3497
          Output_String( outputFile, "# Error: " );
 
3498
 
 
3499
          char buf[256];
 
3500
          const char* targetErrorMessage = targetCoordinate->errorMessage();
 
3501
 
 
3502
          int index = 0;
 
3503
          do
 
3504
          {
 
3505
            buf[0] = 0;
 
3506
            const char* tempErrorMessage = targetErrorMessage + index;
 
3507
            sscanf(tempErrorMessage, "%[^\n]", buf);
 
3508
            index += strlen( buf );
 
3509
            Output_String( outputFile, buf );
 
3510
            buf[0] = 0;
 
3511
            sscanf(targetErrorMessage + index, "%[\n]", buf);
 
3512
            index += strlen( buf );
 
3513
          }
 
3514
          while( strlen( buf ) > 0 && index < length );
 
3515
 
 
3516
          _numErrors ++;
 
3517
        }
 
3518
        else
 
3519
        {
 
3520
          writeTargetCoordinate( targetCoordinate );
 
3521
          if( trailingHeight.heightPresent )
 
3522
            writeHeight( trailingHeight.height );
 
3523
          writeTargetAccuracy( targetAccuracy );
 
3524
        }
 
3525
 
 
3526
        // Write out any comments on the coordinate line in the source file or end the current coordinate line
 
3527
        CoordinateTuple* sourceCoordinate = sourceCoordinateCollection[i];
 
3528
        if( strlen( sourceCoordinate->errorMessage() ) > 0 )
 
3529
        {
 
3530
          Output_String( outputFile, " " );
 
3531
          Output_String( outputFile, sourceCoordinate->errorMessage() );
 
3532
        }
 
3533
        else
 
3534
          Output_Newline(outputFile);
 
3535
      }
 
3536
    }
 
3537
  }
 
3538
 
 
3539
  // Delete lists
 
3540
  int i = 0;  // initialize i outside loop for unix
 
3541
  for( i = 0; i < numSourceCoordinates; i++ )
 
3542
  {
 
3543
    delete sourceCoordinateCollection[i];
 
3544
  }
 
3545
  sourceCoordinateCollection.clear();
 
3546
 
 
3547
  int numSourceAccuracy = sourceAccuracyCollection.size();
 
3548
  for( i = 0; i < numSourceAccuracy; i++ )
 
3549
  {
 
3550
    delete sourceAccuracyCollection[i];
 
3551
  }
 
3552
  sourceAccuracyCollection.clear();
 
3553
 
 
3554
  for( i = 0; i < numTargetCoordinates; i++ )
 
3555
  {
 
3556
    delete targetCoordinateCollection[i];
 
3557
  }
 
3558
  targetCoordinateCollection.clear();
 
3559
 
 
3560
  for( i = 0; i < numTargetAccuracies; i++ )
 
3561
  {
 
3562
    delete targetAccuracyCollection[i];
 
3563
  }
 
3564
  targetAccuracyCollection.clear();
 
3565
}
 
3566
 
 
3567
 
 
3568
CoordinateTuple* Fiomeths::initTargetCoordinate()
 
3569
{
 
3570
  switch( targetProjectionType )
 
3571
  {
 
3572
    case CoordinateType::albersEqualAreaConic:
 
3573
      return new MapProjectionCoordinates(CoordinateType::albersEqualAreaConic);
 
3574
    case CoordinateType::azimuthalEquidistant:
 
3575
      return new MapProjectionCoordinates(CoordinateType::azimuthalEquidistant);
 
3576
    case CoordinateType::bonne:
 
3577
      return new MapProjectionCoordinates(CoordinateType::bonne);
 
3578
    case CoordinateType::britishNationalGrid:
 
3579
      return new BNGCoordinates(CoordinateType::britishNationalGrid);
 
3580
    case CoordinateType::cassini:
 
3581
      return new MapProjectionCoordinates(CoordinateType::cassini);
 
3582
    case CoordinateType::cylindricalEqualArea:
 
3583
      return new MapProjectionCoordinates(CoordinateType::cylindricalEqualArea);
 
3584
    case CoordinateType::eckert4:
 
3585
      return new MapProjectionCoordinates(CoordinateType::eckert4);
 
3586
    case CoordinateType::eckert6:
 
3587
      return new MapProjectionCoordinates(CoordinateType::eckert6);
 
3588
    case CoordinateType::equidistantCylindrical:
 
3589
      return new MapProjectionCoordinates(CoordinateType::equidistantCylindrical);
 
3590
    case CoordinateType::geocentric:
 
3591
      return new CartesianCoordinates(CoordinateType::geocentric);
 
3592
    case CoordinateType::geodetic:
 
3593
      return new GeodeticCoordinates(CoordinateType::geodetic);
 
3594
    case CoordinateType::georef:
 
3595
      return new GEOREFCoordinates(CoordinateType::georef);
 
3596
    case CoordinateType::globalAreaReferenceSystem:
 
3597
      return new GARSCoordinates(CoordinateType::globalAreaReferenceSystem);
 
3598
    case CoordinateType::gnomonic:
 
3599
      return new MapProjectionCoordinates(CoordinateType::gnomonic);
 
3600
    case CoordinateType::lambertConformalConic1Parallel:
 
3601
      return new MapProjectionCoordinates(CoordinateType::lambertConformalConic1Parallel);
 
3602
    case CoordinateType::lambertConformalConic2Parallels:
 
3603
      return new MapProjectionCoordinates(CoordinateType::lambertConformalConic2Parallels);
 
3604
    case CoordinateType::localCartesian:
 
3605
      return new CartesianCoordinates(CoordinateType::localCartesian);
 
3606
    case CoordinateType::mercatorStandardParallel:
 
3607
      return new MapProjectionCoordinates(CoordinateType::mercatorStandardParallel);
 
3608
    case CoordinateType::mercatorScaleFactor:
 
3609
      return new MapProjectionCoordinates(CoordinateType::mercatorScaleFactor);
 
3610
    case CoordinateType::militaryGridReferenceSystem:
 
3611
      return new MGRSorUSNGCoordinates(CoordinateType::militaryGridReferenceSystem);
 
3612
    case CoordinateType::millerCylindrical:
 
3613
      return new MapProjectionCoordinates(CoordinateType::millerCylindrical);
 
3614
    case CoordinateType::mollweide:
 
3615
      return new MapProjectionCoordinates(CoordinateType::mollweide);
 
3616
    case CoordinateType::newZealandMapGrid:
 
3617
      return new MapProjectionCoordinates(CoordinateType::newZealandMapGrid);
 
3618
    case CoordinateType::neys:
 
3619
      return new MapProjectionCoordinates(CoordinateType::neys);
 
3620
    case CoordinateType::obliqueMercator:
 
3621
      return new MapProjectionCoordinates(CoordinateType::obliqueMercator);
 
3622
    case CoordinateType::orthographic:
 
3623
      return new MapProjectionCoordinates(CoordinateType::orthographic);
 
3624
    case CoordinateType::polarStereographicStandardParallel:
 
3625
      return new MapProjectionCoordinates(CoordinateType::polarStereographicStandardParallel);
 
3626
    case CoordinateType::polarStereographicScaleFactor:
 
3627
      return new MapProjectionCoordinates(CoordinateType::polarStereographicScaleFactor);
 
3628
    case CoordinateType::polyconic:
 
3629
      return new MapProjectionCoordinates(CoordinateType::polyconic);
 
3630
    case CoordinateType::sinusoidal:
 
3631
      return new MapProjectionCoordinates(CoordinateType::sinusoidal);
 
3632
    case CoordinateType::stereographic:
 
3633
      return new MapProjectionCoordinates(CoordinateType::stereographic);
 
3634
    case CoordinateType::transverseCylindricalEqualArea:
 
3635
      return new MapProjectionCoordinates(CoordinateType::transverseCylindricalEqualArea);
 
3636
    case CoordinateType::transverseMercator:
 
3637
      return new MapProjectionCoordinates(CoordinateType::transverseMercator);
 
3638
    case CoordinateType::universalPolarStereographic:
 
3639
      return new UPSCoordinates(CoordinateType::universalPolarStereographic);
 
3640
    case CoordinateType::universalTransverseMercator:
 
3641
      return new UTMCoordinates(CoordinateType::universalTransverseMercator);
 
3642
    case CoordinateType::usNationalGrid:
 
3643
      return new MGRSorUSNGCoordinates(CoordinateType::usNationalGrid);
 
3644
    case CoordinateType::vanDerGrinten:
 
3645
      return new MapProjectionCoordinates(CoordinateType::vanDerGrinten);
 
3646
    default:   
 
3647
      throw CoordinateConversionException( FileErrorMessages::invalidTargetCoordinateSystem );
 
3648
  }
 
3649
}
 
3650
 
 
3651
 
 
3652
void Fiomeths::writeTargetCoordinate( CoordinateTuple* targetCoordinate )
 
3653
{
 
3654
  char meter_str[15];
 
3655
  switch( targetProjectionType )
 
3656
  {
 
3657
    case CoordinateType::geodetic:
 
3658
    {
 
3659
      char latitude_str[15];
 
3660
      char longitude_str[15];
 
3661
      if( dynamic_cast< GeodeticParameters* >( targetParameters ) && dynamic_cast< GeodeticCoordinates* >( targetCoordinate ) )
 
3662
      {
 
3663
        GeodeticParameters params = ( *dynamic_cast< GeodeticParameters* >( targetParameters ) );
 
3664
        GeodeticCoordinates coord = ( *dynamic_cast< GeodeticCoordinates* >( targetCoordinate ) );
 
3665
        if( outputLatitudeLongitudeOrder )  // first value is latitude, second value is longitude
 
3666
        {
 
3667
          Latitude_to_String( ( coord.latitude()*180 )/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds );
 
3668
          fprintf(outputFile, "%s", latitude_str);
 
3669
          fprintf(outputFile, ", ");
 
3670
          Longitude_to_String( ( coord.longitude()*180 )/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds );
 
3671
          fprintf(outputFile, "%s", longitude_str);
 
3672
        }
 
3673
        else
 
3674
        {
 
3675
          Longitude_to_String( ( coord.longitude()*180 )/PI, longitude_str, _useNSEW, _useMinutes, _useSeconds );
 
3676
          fprintf(outputFile, "%s", longitude_str);
 
3677
          fprintf(outputFile, ", ");
 
3678
          Latitude_to_String( ( coord.latitude()*180 )/PI, latitude_str, _useNSEW, _useMinutes, _useSeconds );
 
3679
          fprintf(outputFile, "%s", latitude_str);
 
3680
        }
 
3681
        /*only output height if not No_Height*/
 
3682
        if( params.heightType() != HeightType::noHeight )
 
3683
        {
 
3684
          fprintf(outputFile, ", ");
 
3685
          Meter_to_String(coord.height(), meter_str);
 
3686
          fprintf(outputFile, "%s", meter_str);
 
3687
        }
 
3688
      }
 
3689
      else
 
3690
      {
 
3691
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3692
        _numErrors++;
 
3693
      }
 
3694
      break;
 
3695
    }
 
3696
    case CoordinateType::georef: 
 
3697
    {
 
3698
      if( dynamic_cast< GEOREFCoordinates* >( targetCoordinate ) )
 
3699
      {
 
3700
        GEOREFCoordinates coord = ( *dynamic_cast< GEOREFCoordinates* >( targetCoordinate ) );
 
3701
        fprintf(outputFile, "%s", coord.GEOREFString());
 
3702
      }
 
3703
      else
 
3704
      {
 
3705
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3706
        _numErrors++;
 
3707
      }
 
3708
      break;
 
3709
    }
 
3710
    case CoordinateType::geocentric: 
 
3711
    case CoordinateType::localCartesian:  
 
3712
    {
 
3713
      if( dynamic_cast< CartesianCoordinates* >( targetCoordinate ) )
 
3714
      {
 
3715
        CartesianCoordinates coord = ( *dynamic_cast< CartesianCoordinates* >( targetCoordinate ) );
 
3716
        writeCoord( coord.x(), coord.y() );
 
3717
        fprintf(outputFile, ", ");
 
3718
        Meter_to_String( coord.z(), meter_str );
 
3719
        fprintf(outputFile, "%s", meter_str);
 
3720
      }
 
3721
      else
 
3722
      {
 
3723
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3724
        _numErrors++;
 
3725
      }
 
3726
      break;
 
3727
    }
 
3728
    case CoordinateType::militaryGridReferenceSystem:  
 
3729
    case CoordinateType::usNationalGrid: 
 
3730
    {
 
3731
      if( dynamic_cast< MGRSorUSNGCoordinates* >( targetCoordinate ) )
 
3732
      {
 
3733
        MGRSorUSNGCoordinates coord = ( *dynamic_cast< MGRSorUSNGCoordinates* >( targetCoordinate ) );
 
3734
        fprintf( outputFile, "%s", coord.MGRSString() );
 
3735
      }
 
3736
      else
 
3737
      {
 
3738
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3739
        _numErrors++;
 
3740
      }
 
3741
      break;
 
3742
    }
 
3743
    case CoordinateType::universalTransverseMercator:  
 
3744
    {
 
3745
      if( dynamic_cast< UTMCoordinates* >( targetCoordinate ) )
 
3746
      {
 
3747
        UTMCoordinates coord = ( *dynamic_cast< UTMCoordinates* >( targetCoordinate ) );
 
3748
        fprintf(outputFile, "%d", coord.zone());
 
3749
        fprintf(outputFile, ", ");
 
3750
        fprintf(outputFile, "%c", coord.hemisphere());
 
3751
        fprintf(outputFile, ", ");
 
3752
        writeCoord( coord.easting(), coord.northing() );
 
3753
      }
 
3754
      else
 
3755
      {
 
3756
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3757
        _numErrors++;
 
3758
      }
 
3759
      break;
 
3760
    }
 
3761
    case CoordinateType::universalPolarStereographic:  
 
3762
    {
 
3763
      if( dynamic_cast< UPSCoordinates* >( targetCoordinate ) )
 
3764
      {
 
3765
        UPSCoordinates coord = ( *dynamic_cast< UPSCoordinates* >( targetCoordinate ) );
 
3766
        fprintf(outputFile, "%c", coord.hemisphere());
 
3767
        fprintf(outputFile, ", ");
 
3768
        writeCoord( coord.easting(), coord.northing() );
 
3769
      }
 
3770
      else
 
3771
      {
 
3772
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3773
        _numErrors++;
 
3774
      }
 
3775
      break;
 
3776
    }
 
3777
    case CoordinateType::albersEqualAreaConic: 
 
3778
    case CoordinateType::azimuthalEquidistant: 
 
3779
    case CoordinateType::bonne:
 
3780
    case CoordinateType::cassini:  
 
3781
    case CoordinateType::cylindricalEqualArea:  
 
3782
    case CoordinateType::eckert4:  
 
3783
    case CoordinateType::eckert6:  
 
3784
    case CoordinateType::equidistantCylindrical: 
 
3785
    case CoordinateType::gnomonic: 
 
3786
    case CoordinateType::lambertConformalConic1Parallel:  
 
3787
    case CoordinateType::lambertConformalConic2Parallels: 
 
3788
    case CoordinateType::mercatorStandardParallel: 
 
3789
    case CoordinateType::mercatorScaleFactor: 
 
3790
    case CoordinateType::millerCylindrical:
 
3791
    case CoordinateType::mollweide:
 
3792
    case CoordinateType::neys:  
 
3793
    case CoordinateType::newZealandMapGrid:
 
3794
    case CoordinateType::obliqueMercator:
 
3795
    case CoordinateType::orthographic:  
 
3796
    case CoordinateType::polarStereographicStandardParallel: 
 
3797
    case CoordinateType::polarStereographicScaleFactor: 
 
3798
    case CoordinateType::polyconic:
 
3799
    case CoordinateType::sinusoidal:  
 
3800
    case CoordinateType::stereographic:
 
3801
    case CoordinateType::transverseCylindricalEqualArea:  
 
3802
    case CoordinateType::transverseMercator:  
 
3803
    case CoordinateType::vanDerGrinten:
 
3804
    {
 
3805
      if( dynamic_cast< MapProjectionCoordinates* >( targetCoordinate ) )
 
3806
      {
 
3807
        MapProjectionCoordinates coord = *( dynamic_cast< MapProjectionCoordinates* >( targetCoordinate ) );
 
3808
        writeCoord( coord.easting(), coord.northing() );
 
3809
      }
 
3810
      else
 
3811
      {
 
3812
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3813
        _numErrors++;
 
3814
      }
 
3815
      break;
 
3816
    }
 
3817
    case CoordinateType::britishNationalGrid:  
 
3818
    {
 
3819
      if( dynamic_cast< BNGCoordinates* >( targetCoordinate ) )
 
3820
      {
 
3821
        BNGCoordinates coord = ( *dynamic_cast< BNGCoordinates* >( targetCoordinate ) );
 
3822
        fprintf( outputFile, "%s", coord.BNGString() );
 
3823
      }
 
3824
      else
 
3825
      {
 
3826
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3827
        _numErrors++;
 
3828
      }
 
3829
      break;
 
3830
    }
 
3831
    case CoordinateType::globalAreaReferenceSystem: 
 
3832
    {
 
3833
      if( dynamic_cast< GARSCoordinates* >( targetCoordinate ) )
 
3834
      {
 
3835
        GARSCoordinates coord = ( *dynamic_cast< GARSCoordinates* >( targetCoordinate ) );
 
3836
        fprintf( outputFile, "%s", coord.GARSString() );
 
3837
      }
 
3838
      else
 
3839
      {
 
3840
        fprintf(outputFile, FileErrorMessages::invalidTargetCoordinates );
 
3841
        _numErrors++;
 
3842
      }
 
3843
      break;
 
3844
    }
 
3845
  }
 
3846
}
 
3847
 
 
3848
 
 
3849
void Fiomeths::writeCoord(double easting, double northing)
 
3850
{
 
3851
  char meter_str[15];
 
3852
 
 
3853
  Meter_to_String(easting,meter_str);
 
3854
  fprintf(outputFile, "%s", meter_str);
 
3855
  fprintf(outputFile, ", ");
 
3856
  Meter_to_String(northing,meter_str);
 
3857
  fprintf(outputFile, "%s", meter_str);
 
3858
}
 
3859
 
 
3860
 
 
3861
void Fiomeths::writeHeight(char* height)
 
3862
{
 
3863
  fprintf(outputFile, ", ");
 
3864
  fprintf(outputFile, "%s", height);
 
3865
}
 
3866
 
 
3867
 
 
3868
void Fiomeths::writeTargetAccuracy( Accuracy* accuracy )
 
3869
{
 
3870
  double ce90 = accuracy->circularError90();
 
3871
  double le90 = accuracy->linearError90();
 
3872
  double se90 = accuracy->sphericalError90();
 
3873
 
 
3874
  if(!((ce90 == -1.0) && (le90 == -1.0) && (se90 == -1.0)))
 
3875
  {
 
3876
    fprintf(outputFile, "; CE90: ");
 
3877
    if (ce90 == -1.0)
 
3878
      fprintf(outputFile,"Unk");
 
3879
    else
 
3880
      fprintf(outputFile,"%1.0f",ce90);
 
3881
    fprintf(outputFile, ", LE90: ");
 
3882
    if (le90 == -1.0)
 
3883
      fprintf(outputFile,"Unk");
 
3884
    else
 
3885
      fprintf(outputFile,"%1.0f",le90);
 
3886
    fprintf(outputFile, ", SE90: ");
 
3887
    if (se90 == -1.0)
 
3888
      fprintf(outputFile,"Unk");
 
3889
    else
 
3890
      fprintf(outputFile,"%1.0f",se90);
 
3891
  }
 
3892
}
 
3893
 
 
3894
 
 
3895
void Fiomeths::writeExampleCoord()
 
3896
{
 
3897
  char latitude_str[15];
 
3898
  char longitude_str[15];
 
3899
  char meter_str[15];
 
3900
 
 
3901
  switch( targetProjectionType )
 
3902
  {
 
3903
    case CoordinateType::globalAreaReferenceSystem:
 
3904
    {
 
3905
      fprintf(outputFile, "361HN37");
 
3906
      break;
 
3907
    }
 
3908
    case CoordinateType::geodetic:
 
3909
    {
 
3910
      Latitude_to_String(0, latitude_str, _useNSEW, _useMinutes, _useSeconds);
 
3911
      fprintf(outputFile, "%s", latitude_str);
 
3912
      fprintf(outputFile, ", ");
 
3913
      Longitude_to_String(0, longitude_str, _useNSEW, _useMinutes, _useSeconds);
 
3914
      fprintf(outputFile, "%s", longitude_str);
 
3915
 
 
3916
      GeodeticParameters params = *dynamic_cast< GeodeticParameters* >( coordinateConversionService->getCoordinateSystem( SourceOrTarget::target ) );
 
3917
 
 
3918
      /*only output height if not No_Height*/
 
3919
      if( params.heightType() != HeightType::noHeight )
 
3920
      {
 
3921
        fprintf(outputFile, ", ");
 
3922
        Meter_to_String(0,meter_str);
 
3923
        fprintf(outputFile, "%s", meter_str);
 
3924
      }
 
3925
      break;
 
3926
    }
 
3927
    case CoordinateType::georef:
 
3928
    {
 
3929
      fprintf(outputFile, "NGAA0000000000");
 
3930
      break;
 
3931
    }
 
3932
    case CoordinateType::geocentric:
 
3933
    {
 
3934
      writeCoord(0, 0);
 
3935
      fprintf(outputFile, ", ");
 
3936
      Meter_to_String(0,meter_str);
 
3937
      fprintf(outputFile, "%s", meter_str);
 
3938
      break;
 
3939
    }
 
3940
    case CoordinateType::localCartesian:
 
3941
    {
 
3942
      writeCoord(0, 0);
 
3943
      fprintf(outputFile, ", ");
 
3944
      Meter_to_String(0,meter_str);
 
3945
      fprintf(outputFile, "%s", meter_str);
 
3946
      break;
 
3947
    }
 
3948
    case CoordinateType::militaryGridReferenceSystem:
 
3949
    {
 
3950
      fprintf(outputFile, "31NEA0000000000");
 
3951
      break;
 
3952
    }
 
3953
    case CoordinateType::usNationalGrid:
 
3954
    {
 
3955
      fprintf(outputFile, "31NEA0000000000");
 
3956
      break;
 
3957
    }
 
3958
    case CoordinateType::universalTransverseMercator:
 
3959
    {
 
3960
      UTMParameters params = *dynamic_cast< UTMParameters* >( coordinateConversionService->getCoordinateSystem( SourceOrTarget::target ) );
 
3961
 
 
3962
      if (params.override())
 
3963
        fprintf(outputFile, "%d", params.zone());
 
3964
      else
 
3965
        fprintf(outputFile, "%d", 0);
 
3966
      fprintf(outputFile, ", ");
 
3967
      fprintf(outputFile, "N");
 
3968
      fprintf(outputFile, ", ");
 
3969
      writeCoord(500000, 0);
 
3970
      break;
 
3971
    }
 
3972
    case CoordinateType::universalPolarStereographic:
 
3973
    {
 
3974
      fprintf(outputFile, "N");
 
3975
      fprintf(outputFile, ", ");
 
3976
      writeCoord(2000000, 2000000);
 
3977
      break;
 
3978
    }
 
3979
    case CoordinateType::britishNationalGrid:
 
3980
    {
 
3981
      fprintf(outputFile, "SV 0000000000");
 
3982
      break;
 
3983
    }
 
3984
    case CoordinateType::albersEqualAreaConic:
 
3985
    case CoordinateType::azimuthalEquidistant:
 
3986
    case CoordinateType::bonne:
 
3987
    case CoordinateType::cassini:
 
3988
    case CoordinateType::cylindricalEqualArea:
 
3989
    case CoordinateType::eckert4:
 
3990
    case CoordinateType::eckert6:
 
3991
    case CoordinateType::equidistantCylindrical:
 
3992
    case CoordinateType::gnomonic:
 
3993
    case CoordinateType::lambertConformalConic1Parallel:
 
3994
    case CoordinateType::lambertConformalConic2Parallels:
 
3995
    case CoordinateType::mercatorStandardParallel:
 
3996
    case CoordinateType::mercatorScaleFactor:
 
3997
    case CoordinateType::millerCylindrical:
 
3998
    case CoordinateType::mollweide:
 
3999
    case CoordinateType::neys:
 
4000
    case CoordinateType::obliqueMercator:
 
4001
    case CoordinateType::orthographic:
 
4002
    case CoordinateType::polarStereographicStandardParallel:
 
4003
    case CoordinateType::polarStereographicScaleFactor:
 
4004
    case CoordinateType::polyconic:
 
4005
    case CoordinateType::sinusoidal:
 
4006
    case CoordinateType::stereographic:
 
4007
    case CoordinateType::transverseCylindricalEqualArea:
 
4008
    case CoordinateType::transverseMercator:
 
4009
    case CoordinateType::vanDerGrinten:
 
4010
    {
 
4011
      writeCoord(0, 0);
 
4012
      break;
 
4013
    }
 
4014
    case CoordinateType::newZealandMapGrid:
 
4015
    {
 
4016
      writeCoord(2510000, 6023150);
 
4017
      break;
 
4018
    }
 
4019
    default:
 
4020
      throw CoordinateConversionException( FileErrorMessages::invalidTargetCoordinateSystem );    
 
4021
  }
 
4022
}
 
4023
 
 
4024
 
 
4025
 
 
4026
// CLASSIFICATION: UNCLASSIFIED