Codebase list libgeotiff / debian/1.4.1%7Eexp1 geo_extra.c
debian/1.4.1%7Eexp1

Tree @debian/1.4.1%7Eexp1 (Download .tar.gz)

geo_extra.c @debian/1.4.1%7Eexp1raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/******************************************************************************
 * $Id: geo_extra.c 1568 2009-04-22 21:10:55Z warmerdam $
 *
 * Project:  libgeotiff
 * Purpose:  Code to normalize a few common PCS values without use of CSV
 *           files.
 * Author:   Frank Warmerdam, warmerda@home.com
 *
 ******************************************************************************
 * Copyright (c) 1999, Frank Warmerdam
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *****************************************************************************/

/*
#include "geotiff.h"
#include "geo_tiffp.h"
#include "geo_keyp.h"
*/

#include "geo_normalize.h"
#include "geovalues.h"

static int StatePlaneTable[] = 
{
    PCS_NAD83_Alabama_East,		Proj_Alabama_CS83_East,
    PCS_NAD83_Alabama_West,		Proj_Alabama_CS83_West,

    PCS_NAD83_Alaska_zone_1,		Proj_Alaska_CS83_1,
    PCS_NAD83_Alaska_zone_2,		Proj_Alaska_CS83_2,
    PCS_NAD83_Alaska_zone_3,		Proj_Alaska_CS83_3,
    PCS_NAD83_Alaska_zone_4,		Proj_Alaska_CS83_4,
    PCS_NAD83_Alaska_zone_5,		Proj_Alaska_CS83_5,
    PCS_NAD83_Alaska_zone_6,		Proj_Alaska_CS83_6,
    PCS_NAD83_Alaska_zone_7,		Proj_Alaska_CS83_7,
    PCS_NAD83_Alaska_zone_8,		Proj_Alaska_CS83_8,
    PCS_NAD83_Alaska_zone_9,		Proj_Alaska_CS83_9,
    PCS_NAD83_Alaska_zone_10,		Proj_Alaska_CS83_10,

    PCS_NAD83_California_1,		Proj_California_CS83_1,
    PCS_NAD83_California_2,		Proj_California_CS83_2,
    PCS_NAD83_California_3,		Proj_California_CS83_3,
    PCS_NAD83_California_4,		Proj_California_CS83_4,
    PCS_NAD83_California_5,		Proj_California_CS83_5,
    PCS_NAD83_California_6,		Proj_California_CS83_6,

    PCS_NAD83_Arizona_East,		Proj_Arizona_CS83_east,
    PCS_NAD83_Arizona_Central,		Proj_Arizona_CS83_Central,
    PCS_NAD83_Arizona_West,		Proj_Arizona_CS83_west,

    PCS_NAD83_Arkansas_North,		Proj_Arkansas_CS83_North,
    PCS_NAD83_Arkansas_South,		Proj_Arkansas_CS83_South,

    PCS_NAD83_Colorado_North,		Proj_Colorado_CS83_North,
    PCS_NAD83_Colorado_Central,		Proj_Colorado_CS83_Central,
    PCS_NAD83_Colorado_South,		Proj_Colorado_CS83_South,

    PCS_NAD83_Connecticut,		Proj_Connecticut_CS83,

    PCS_NAD83_Delaware,			Proj_Delaware_CS83,

    PCS_NAD83_Florida_East,		Proj_Florida_CS83_East,
    PCS_NAD83_Florida_North,		Proj_Florida_CS83_North,
    PCS_NAD83_Florida_West,		Proj_Florida_CS83_West,

    PCS_NAD83_Hawaii_zone_1,		Proj_Hawaii_CS83_1,
    PCS_NAD83_Hawaii_zone_2,		Proj_Hawaii_CS83_2,
    PCS_NAD83_Hawaii_zone_3,		Proj_Hawaii_CS83_3,
    PCS_NAD83_Hawaii_zone_4,		Proj_Hawaii_CS83_4,
    PCS_NAD83_Hawaii_zone_5,		Proj_Hawaii_CS83_5,

    PCS_NAD83_Georgia_East,		Proj_Georgia_CS83_East,
    PCS_NAD83_Georgia_West,		Proj_Georgia_CS83_West,

    PCS_NAD83_Idaho_East,		Proj_Idaho_CS83_East,
    PCS_NAD83_Idaho_Central,		Proj_Idaho_CS83_Central,
    PCS_NAD83_Idaho_West,		Proj_Idaho_CS83_West,

    PCS_NAD83_Illinois_East,		Proj_Illinois_CS83_East,
    PCS_NAD83_Illinois_West,		Proj_Illinois_CS83_West,

    PCS_NAD83_Indiana_East,		Proj_Indiana_CS83_East,
    PCS_NAD83_Indiana_West,		Proj_Indiana_CS83_West,

    PCS_NAD83_Iowa_North,      		Proj_Iowa_CS83_North,
    PCS_NAD83_Iowa_South,      		Proj_Iowa_CS83_South,

    PCS_NAD83_Kansas_North,		Proj_Kansas_CS83_North,
    PCS_NAD83_Kansas_South,		Proj_Kansas_CS83_South,

    PCS_NAD83_Kentucky_North,		Proj_Kentucky_CS83_North,
    PCS_NAD83_Kentucky_South,		Proj_Kentucky_CS83_South,

    PCS_NAD83_Louisiana_North,		Proj_Louisiana_CS83_North,
    PCS_NAD83_Louisiana_South,		Proj_Louisiana_CS83_South,

    PCS_NAD83_Maine_East,		Proj_Maine_CS83_East,
    PCS_NAD83_Maine_West,		Proj_Maine_CS83_West,

    PCS_NAD83_Maryland,			Proj_Maryland_CS83,

    PCS_NAD83_Massachusetts,		Proj_Massachusetts_CS83_Mainland,
    PCS_NAD83_Massachusetts_Is,		Proj_Massachusetts_CS83_Island,

    PCS_NAD83_Michigan_North,		Proj_Michigan_CS83_North,
    PCS_NAD83_Michigan_Central,		Proj_Michigan_CS83_Central,
    PCS_NAD83_Michigan_South,		Proj_Michigan_CS83_South,

    PCS_NAD83_Minnesota_North,		Proj_Minnesota_CS83_North,
    PCS_NAD83_Minnesota_Cent,		Proj_Minnesota_CS83_Central,
    PCS_NAD83_Minnesota_South,		Proj_Minnesota_CS83_South,

    PCS_NAD83_Mississippi_East,		Proj_Mississippi_CS83_East,
    PCS_NAD83_Mississippi_West,		Proj_Mississippi_CS83_West,

    PCS_NAD83_Missouri_East,		Proj_Missouri_CS83_East,
    PCS_NAD83_Missouri_Central,		Proj_Missouri_CS83_Central,
    PCS_NAD83_Missouri_West,		Proj_Missouri_CS83_West,

    PCS_NAD83_Montana,			Proj_Montana_CS83,

    PCS_NAD83_Nebraska,			Proj_Nebraska_CS83,

    PCS_NAD83_Nevada_East,		Proj_Nevada_CS83_East,
    PCS_NAD83_Nevada_Central,		Proj_Nevada_CS83_Central,
    PCS_NAD83_Nevada_West,		Proj_Nevada_CS83_West,

    PCS_NAD83_New_Hampshire,		Proj_New_Hampshire_CS83,

    PCS_NAD83_New_Jersey,		Proj_New_Jersey_CS83,

    PCS_NAD83_New_Mexico_East,		Proj_New_Mexico_CS83_East,
    PCS_NAD83_New_Mexico_Cent,		Proj_New_Mexico_CS83_Central,
    PCS_NAD83_New_Mexico_West,		Proj_New_Mexico_CS83_West,

    PCS_NAD83_New_York_East,		Proj_New_York_CS83_East,
    PCS_NAD83_New_York_Central,		Proj_New_York_CS83_Central,
    PCS_NAD83_New_York_West,		Proj_New_York_CS83_West,
    PCS_NAD83_New_York_Long_Is,		Proj_New_York_CS83_Long_Island,

    PCS_NAD83_North_Carolina,	       	Proj_North_Carolina_CS83,

    PCS_NAD83_North_Dakota_N,		Proj_North_Dakota_CS83_North,
    PCS_NAD83_North_Dakota_S,		Proj_North_Dakota_CS83_South,

    PCS_NAD83_Ohio_North,		Proj_Ohio_CS83_North,
    PCS_NAD83_Ohio_South,		Proj_Ohio_CS83_South,

    PCS_NAD83_Oklahoma_North,		Proj_Oklahoma_CS83_North,
    PCS_NAD83_Oklahoma_South,		Proj_Oklahoma_CS83_South,

    PCS_NAD83_Oregon_North,		Proj_Oregon_CS83_North,
    PCS_NAD83_Oregon_South,		Proj_Oregon_CS83_South,

    PCS_NAD83_Pennsylvania_N,		Proj_Pennsylvania_CS83_North,
    PCS_NAD83_Pennsylvania_S,		Proj_Pennsylvania_CS83_South,

    PCS_NAD83_Rhode_Island,		Proj_Rhode_Island_CS83,

    PCS_NAD83_South_Carolina,		Proj_South_Carolina_CS83,

    PCS_NAD83_South_Dakota_N,		Proj_South_Dakota_CS83_North,
    PCS_NAD83_South_Dakota_S,		Proj_South_Dakota_CS83_South,

    PCS_NAD83_Tennessee,		Proj_Tennessee_CS83,

    PCS_NAD83_Texas_North,		Proj_Texas_CS83_North,
    PCS_NAD83_Texas_North_Cen,		Proj_Texas_CS83_North_Central,
    PCS_NAD83_Texas_Central,		Proj_Texas_CS83_Central,
    PCS_NAD83_Texas_South_Cen,		Proj_Texas_CS83_South_Central,
    PCS_NAD83_Texas_South,		Proj_Texas_CS83_South,

    PCS_NAD83_Utah_North,		Proj_Utah_CS83_North,
    PCS_NAD83_Utah_Central,		Proj_Utah_CS83_Central,
    PCS_NAD83_Utah_South,		Proj_Utah_CS83_South,

    PCS_NAD83_Vermont,			Proj_Vermont_CS83,

    PCS_NAD83_Virginia_North,		Proj_Virginia_CS83_North,
    PCS_NAD83_Virginia_South,		Proj_Virginia_CS83_South,

    PCS_NAD83_Washington_North,		Proj_Washington_CS83_North,
    PCS_NAD83_Washington_South,		Proj_Washington_CS83_South,

    PCS_NAD83_West_Virginia_N,		Proj_West_Virginia_CS83_North,
    PCS_NAD83_West_Virginia_S,		Proj_West_Virginia_CS83_South,

    PCS_NAD83_Wisconsin_North,		Proj_Wisconsin_CS83_North,
    PCS_NAD83_Wisconsin_Cen,		Proj_Wisconsin_CS83_Central,
    PCS_NAD83_Wisconsin_South,		Proj_Wisconsin_CS83_South,

    PCS_NAD83_Wyoming_East,		Proj_Wyoming_CS83_East,
    PCS_NAD83_Wyoming_E_Cen,		Proj_Wyoming_CS83_East_Central,
    PCS_NAD83_Wyoming_W_Cen,		Proj_Wyoming_CS83_West_Central,
    PCS_NAD83_Wyoming_West,		Proj_Wyoming_CS83_West,
    
    PCS_NAD83_Puerto_Rico_Virgin_Is,	Proj_Puerto_Rico_Virgin_Is,

    PCS_NAD27_Alabama_East,		Proj_Alabama_CS27_East,
    PCS_NAD27_Alabama_West,		Proj_Alabama_CS27_West,

    PCS_NAD27_Alaska_zone_1,		Proj_Alaska_CS27_1,
    PCS_NAD27_Alaska_zone_2,		Proj_Alaska_CS27_2,
    PCS_NAD27_Alaska_zone_3,		Proj_Alaska_CS27_3,
    PCS_NAD27_Alaska_zone_4,		Proj_Alaska_CS27_4,
    PCS_NAD27_Alaska_zone_5,		Proj_Alaska_CS27_5,
    PCS_NAD27_Alaska_zone_6,		Proj_Alaska_CS27_6,
    PCS_NAD27_Alaska_zone_7,		Proj_Alaska_CS27_7,
    PCS_NAD27_Alaska_zone_8,		Proj_Alaska_CS27_8,
    PCS_NAD27_Alaska_zone_9,		Proj_Alaska_CS27_9,
    PCS_NAD27_Alaska_zone_10,		Proj_Alaska_CS27_10,

    PCS_NAD27_California_I,		Proj_California_CS27_I,
    PCS_NAD27_California_II,		Proj_California_CS27_II,
    PCS_NAD27_California_III,		Proj_California_CS27_III,
    PCS_NAD27_California_IV,		Proj_California_CS27_IV,
    PCS_NAD27_California_V,		Proj_California_CS27_V,
    PCS_NAD27_California_VI,		Proj_California_CS27_VI,
    PCS_NAD27_California_VII,		Proj_California_CS27_VII,

    PCS_NAD27_Arizona_East,		Proj_Arizona_Coordinate_System_east,
    PCS_NAD27_Arizona_Central,		Proj_Arizona_Coordinate_System_Central,
    PCS_NAD27_Arizona_West,		Proj_Arizona_Coordinate_System_west,

    PCS_NAD27_Arkansas_North,		Proj_Arkansas_CS27_North,
    PCS_NAD27_Arkansas_South,		Proj_Arkansas_CS27_South,

    PCS_NAD27_Colorado_North,		Proj_Colorado_CS27_North,
    PCS_NAD27_Colorado_Central,		Proj_Colorado_CS27_Central,
    PCS_NAD27_Colorado_South,		Proj_Colorado_CS27_South,

    PCS_NAD27_Connecticut,		Proj_Connecticut_CS27,

    PCS_NAD27_Delaware,			Proj_Delaware_CS27,

    PCS_NAD27_Florida_East,		Proj_Florida_CS27_East,
    PCS_NAD27_Florida_North,		Proj_Florida_CS27_North,
    PCS_NAD27_Florida_West,		Proj_Florida_CS27_West,

    PCS_NAD27_Hawaii_zone_1,		Proj_Hawaii_CS27_1,
    PCS_NAD27_Hawaii_zone_2,		Proj_Hawaii_CS27_2,
    PCS_NAD27_Hawaii_zone_3,		Proj_Hawaii_CS27_3,
    PCS_NAD27_Hawaii_zone_4,		Proj_Hawaii_CS27_4,
    PCS_NAD27_Hawaii_zone_5,		Proj_Hawaii_CS27_5,

    PCS_NAD27_Georgia_East,		Proj_Georgia_CS27_East,
    PCS_NAD27_Georgia_West,		Proj_Georgia_CS27_West,

    PCS_NAD27_Idaho_East,		Proj_Idaho_CS27_East,
    PCS_NAD27_Idaho_Central,		Proj_Idaho_CS27_Central,
    PCS_NAD27_Idaho_West,		Proj_Idaho_CS27_West,

    PCS_NAD27_Illinois_East,		Proj_Illinois_CS27_East,
    PCS_NAD27_Illinois_West,		Proj_Illinois_CS27_West,

    PCS_NAD27_Indiana_East,		Proj_Indiana_CS27_East,
    PCS_NAD27_Indiana_West,		Proj_Indiana_CS27_West,

    PCS_NAD27_Iowa_North,      		Proj_Iowa_CS27_North,
    PCS_NAD27_Iowa_South,      		Proj_Iowa_CS27_South,

    PCS_NAD27_Kansas_North,		Proj_Kansas_CS27_North,
    PCS_NAD27_Kansas_South,		Proj_Kansas_CS27_South,

    PCS_NAD27_Kentucky_North,		Proj_Kentucky_CS27_North,
    PCS_NAD27_Kentucky_South,		Proj_Kentucky_CS27_South,

    PCS_NAD27_Louisiana_North,		Proj_Louisiana_CS27_North,
    PCS_NAD27_Louisiana_South,		Proj_Louisiana_CS27_South,

    PCS_NAD27_Maine_East,		Proj_Maine_CS27_East,
    PCS_NAD27_Maine_West,		Proj_Maine_CS27_West,

    PCS_NAD27_Maryland,			Proj_Maryland_CS27,

    PCS_NAD27_Massachusetts,		Proj_Massachusetts_CS27_Mainland,
    PCS_NAD27_Massachusetts_Is,		Proj_Massachusetts_CS27_Island,

    PCS_NAD27_Michigan_North,		Proj_Michigan_CS27_North,
    PCS_NAD27_Michigan_Central,		Proj_Michigan_CS27_Central,
    PCS_NAD27_Michigan_South,		Proj_Michigan_CS27_South,

    PCS_NAD27_Minnesota_North,		Proj_Minnesota_CS27_North,
    PCS_NAD27_Minnesota_Cent,		Proj_Minnesota_CS27_Central,
    PCS_NAD27_Minnesota_South,		Proj_Minnesota_CS27_South,

    PCS_NAD27_Mississippi_East,		Proj_Mississippi_CS27_East,
    PCS_NAD27_Mississippi_West,		Proj_Mississippi_CS27_West,

    PCS_NAD27_Missouri_East,		Proj_Missouri_CS27_East,
    PCS_NAD27_Missouri_Central,		Proj_Missouri_CS27_Central,
    PCS_NAD27_Missouri_West,		Proj_Missouri_CS27_West,

    PCS_NAD27_Montana_North,		Proj_Montana_CS27_North,
    PCS_NAD27_Montana_Central,		Proj_Montana_CS27_Central,
    PCS_NAD27_Montana_South,		Proj_Montana_CS27_South,

    PCS_NAD27_Nebraska_North,		Proj_Nebraska_CS27_North,
    PCS_NAD27_Nebraska_South,		Proj_Nebraska_CS27_South,

    PCS_NAD27_Nevada_East,		Proj_Nevada_CS27_East,
    PCS_NAD27_Nevada_Central,		Proj_Nevada_CS27_Central,
    PCS_NAD27_Nevada_West,		Proj_Nevada_CS27_West,

    PCS_NAD27_New_Hampshire,		Proj_New_Hampshire_CS27,

    PCS_NAD27_New_Jersey,		Proj_New_Jersey_CS27,

    PCS_NAD27_New_Mexico_East,		Proj_New_Mexico_CS27_East,
    PCS_NAD27_New_Mexico_Cent,		Proj_New_Mexico_CS27_Central,
    PCS_NAD27_New_Mexico_West,		Proj_New_Mexico_CS27_West,

    PCS_NAD27_New_York_East,		Proj_New_York_CS27_East,
    PCS_NAD27_New_York_Central,		Proj_New_York_CS27_Central,
    PCS_NAD27_New_York_West,		Proj_New_York_CS27_West,
    PCS_NAD27_New_York_Long_Is,		Proj_New_York_CS27_Long_Island,

    PCS_NAD27_North_Carolina,	       	Proj_North_Carolina_CS27,

    PCS_NAD27_North_Dakota_N,		Proj_North_Dakota_CS27_North,
    PCS_NAD27_North_Dakota_S,		Proj_North_Dakota_CS27_South,

    PCS_NAD27_Ohio_North,		Proj_Ohio_CS27_North,
    PCS_NAD27_Ohio_South,		Proj_Ohio_CS27_South,

    PCS_NAD27_Oklahoma_North,		Proj_Oklahoma_CS27_North,
    PCS_NAD27_Oklahoma_South,		Proj_Oklahoma_CS27_South,

    PCS_NAD27_Oregon_North,		Proj_Oregon_CS27_North,
    PCS_NAD27_Oregon_South,		Proj_Oregon_CS27_South,

    PCS_NAD27_Pennsylvania_N,		Proj_Pennsylvania_CS27_North,
    PCS_NAD27_Pennsylvania_S,		Proj_Pennsylvania_CS27_South,

    PCS_NAD27_Rhode_Island,		Proj_Rhode_Island_CS27,

    PCS_NAD27_South_Carolina_N,		Proj_South_Carolina_CS27_North,
    PCS_NAD27_South_Carolina_S,		Proj_South_Carolina_CS27_South,

    PCS_NAD27_South_Dakota_N,		Proj_South_Dakota_CS27_North,
    PCS_NAD27_South_Dakota_S,		Proj_South_Dakota_CS27_South,

    PCS_NAD27_Tennessee,		Proj_Tennessee_CS27,

    PCS_NAD27_Texas_North,		Proj_Texas_CS27_North,
    PCS_NAD27_Texas_North_Cen,		Proj_Texas_CS27_North_Central,
    PCS_NAD27_Texas_Central,		Proj_Texas_CS27_Central,
    PCS_NAD27_Texas_South_Cen,		Proj_Texas_CS27_South_Central,
    PCS_NAD27_Texas_South,		Proj_Texas_CS27_South,

    PCS_NAD27_Utah_North,		Proj_Utah_CS27_North,
    PCS_NAD27_Utah_Central,		Proj_Utah_CS27_Central,
    PCS_NAD27_Utah_South,		Proj_Utah_CS27_South,

    PCS_NAD27_Vermont,			Proj_Vermont_CS27,

    PCS_NAD27_Virginia_North,		Proj_Virginia_CS27_North,
    PCS_NAD27_Virginia_South,		Proj_Virginia_CS27_South,

    PCS_NAD27_Washington_North,		Proj_Washington_CS27_North,
    PCS_NAD27_Washington_South,		Proj_Washington_CS27_South,

    PCS_NAD27_West_Virginia_N,		Proj_West_Virginia_CS27_North,
    PCS_NAD27_West_Virginia_S,		Proj_West_Virginia_CS27_South,

    PCS_NAD27_Wisconsin_North,		Proj_Wisconsin_CS27_North,
    PCS_NAD27_Wisconsin_Cen,		Proj_Wisconsin_CS27_Central,
    PCS_NAD27_Wisconsin_South,		Proj_Wisconsin_CS27_South,

    PCS_NAD27_Wyoming_East,		Proj_Wyoming_CS27_East,
    PCS_NAD27_Wyoming_E_Cen,		Proj_Wyoming_CS27_East_Central,
    PCS_NAD27_Wyoming_W_Cen,		Proj_Wyoming_CS27_West_Central,
    PCS_NAD27_Wyoming_West,		Proj_Wyoming_CS27_West,
    
    PCS_NAD27_Puerto_Rico,		Proj_Puerto_Rico_CS27,

    KvUserDefined
};

/************************************************************************/
/*                          GTIFMapSysToPCS()                           */
/*                                                                      */
/*      Given a Datum, MapSys and zone value generate the best PCS      */
/*      code possible.                                                  */
/************************************************************************/

int	GTIFMapSysToPCS( int MapSys, int Datum, int nZone )

{
    int		PCSCode = KvUserDefined;

    if( MapSys == MapSys_UTM_North )
    {
	if( Datum == GCS_NAD27 )
	    PCSCode = PCS_NAD27_UTM_zone_3N + nZone - 3;
	else if( Datum == GCS_NAD83 )
	    PCSCode = PCS_NAD83_UTM_zone_3N + nZone - 3;
	else if( Datum == GCS_WGS_72 )
	    PCSCode = PCS_WGS72_UTM_zone_1N + nZone - 1;
	else if( Datum == GCS_WGS_72BE )
	    PCSCode = PCS_WGS72BE_UTM_zone_1N + nZone - 1;
	else if( Datum == GCS_WGS_84 )
	    PCSCode = PCS_WGS84_UTM_zone_1N + nZone - 1;
    }
    else if( MapSys == MapSys_UTM_South )
    {
	if( Datum == GCS_WGS_72 )
	    PCSCode = PCS_WGS72_UTM_zone_1S + nZone - 1;
	else if( Datum == GCS_WGS_72BE )
	    PCSCode = PCS_WGS72BE_UTM_zone_1S + nZone - 1;
	else if( Datum == GCS_WGS_84 )
	    PCSCode = PCS_WGS84_UTM_zone_1S + nZone - 1;
    }
    else if( MapSys == MapSys_State_Plane_27 )
    {
	int		i;

        PCSCode = 10000 + nZone;
	for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
	{
	    if( StatePlaneTable[i+1] == PCSCode )
	        PCSCode = StatePlaneTable[i];
	}

        /* Old EPSG code was in error for Tennesse CS27, override */
        if( nZone == 4100 )
            PCSCode = 2204;
    }
    else if( MapSys == MapSys_State_Plane_83 )
    {
	int		i;

        PCSCode = 10000 + nZone + 30;

	for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
	{
	    if( StatePlaneTable[i+1] == PCSCode )
	        PCSCode = StatePlaneTable[i];
	}

        /* Old EPSG code was in error for Kentucky North CS83, override */
        if( nZone == 1601 )
            PCSCode = 2205;
    }

    return( PCSCode );
}

/************************************************************************/
/*                          GTIFMapSysToProj()                          */
/*                                                                      */
/*      Given a MapSys and zone value generate the best Proj_           */
/*      code possible.                                                  */
/************************************************************************/

int	GTIFMapSysToProj( int MapSys, int nZone )

{
    int		ProjCode = KvUserDefined;

    if( MapSys == MapSys_UTM_North )
    {
        ProjCode = Proj_UTM_zone_1N + nZone - 1;
    }
    else if( MapSys == MapSys_UTM_South )
    {
        ProjCode = Proj_UTM_zone_1S + nZone - 1;
    }
    else if( MapSys == MapSys_State_Plane_27 )
    {
        ProjCode = 10000 + nZone;

        /* Tennesse override */
        if( nZone == 4100 )
            ProjCode = 15302;
    }
    else if( MapSys == MapSys_State_Plane_83 )
    {
        ProjCode = 10000 + nZone + 30;

        /* Kentucky North override */
        if( nZone == 1601 )
            ProjCode = 15303;
    }

    return( ProjCode );
}

/************************************************************************/
/*                          GTIFPCSToMapSys()                           */
/************************************************************************/

/**
 * Translate a PCS_ code into a UTM or State Plane map system, a datum,
 * and a zone if possible.
 *
 * @param PCSCode The projection code (PCS_*) as would be stored in the
 * ProjectedCSTypeGeoKey of a GeoTIFF file.
 *
 * @param pDatum Pointer to an integer into which the datum code (GCS_*)
 * is put if the function succeeds.
 *
 * @param pZone Pointer to an integer into which the zone will be placed
 * if the function is successful.
 *
 * @return Returns either MapSys_UTM_North, MapSys_UTM_South,
 * MapSys_State_Plane_83, MapSys_State_Plane_27 or KvUserDefined.
 * KvUserDefined indicates that the
 * function failed to recognise the projection as UTM or State Plane.
 *
 * The zone value is only set if the return code is other than KvUserDefined.
 * For utm map system the returned zone will be between 1 and 60.  For
 * State Plane, the USGS state plane zone number is returned.  For instance,
 * Alabama East is zone 101.
 *
 * The datum (really this is the GCS) is set to a GCS_ value such as GCS_NAD27.
 *
 * This function is useful to recognise (most) UTM and State Plane coordinate
 * systems, even if CSV files aren't available to translate them automatically.
 * It is used as a fallback mechanism by GTIFGetDefn() for normalization when
 * CSV files aren't found. 
 */

int GTIFPCSToMapSys( int PCSCode, int * pDatum, int * pZone )

{
    int		Datum = KvUserDefined, Proj = KvUserDefined;
    int		nZone = KvUserDefined, i;

/* -------------------------------------------------------------------- */
/*      UTM with various datums.  Note there are lots of PCS UTM        */
/*      codes not done yet which use strange datums.                    */
/* -------------------------------------------------------------------- */
    if( PCSCode >= PCS_NAD27_UTM_zone_3N && PCSCode <= PCS_NAD27_UTM_zone_22N )
    {
	Datum = GCS_NAD27;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_NAD27_UTM_zone_3N + 3;
    }
    else if( PCSCode >= PCS_NAD83_UTM_zone_3N 
	     && PCSCode <= PCS_NAD83_UTM_zone_23N )
    {
	Datum = GCS_NAD83;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_NAD83_UTM_zone_3N + 3;
    }

    else if( PCSCode >= PCS_WGS72_UTM_zone_1N
	     && PCSCode <= PCS_WGS72_UTM_zone_60N )
    {
	Datum = GCS_WGS_72;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_WGS72_UTM_zone_1N + 1;
    }
    else if( PCSCode >= PCS_WGS72_UTM_zone_1S
	     && PCSCode <= PCS_WGS72_UTM_zone_60S )
    {
	Datum = GCS_WGS_72;
	Proj = MapSys_UTM_South;
	nZone = PCSCode - PCS_WGS72_UTM_zone_1S + 1;
    }

    else if( PCSCode >= PCS_WGS72BE_UTM_zone_1N
	     && PCSCode <= PCS_WGS72BE_UTM_zone_60N )
    {
	Datum = GCS_WGS_72BE;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_WGS72BE_UTM_zone_1N + 1;
    }
    else if( PCSCode >= PCS_WGS72BE_UTM_zone_1S
	     && PCSCode <= PCS_WGS72BE_UTM_zone_60S )
    {
	Datum = GCS_WGS_72BE;
	Proj = MapSys_UTM_South;
	nZone = PCSCode - PCS_WGS72BE_UTM_zone_1S + 1;
    }

    else if( PCSCode >= PCS_WGS84_UTM_zone_1N
	     && PCSCode <= PCS_WGS84_UTM_zone_60N )
    {
	Datum = GCS_WGS_84;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_WGS84_UTM_zone_1N + 1;
    }
    else if( PCSCode >= PCS_WGS84_UTM_zone_1S
	     && PCSCode <= PCS_WGS84_UTM_zone_60S )
    {
	Datum = GCS_WGS_84;
	Proj = MapSys_UTM_South;
	nZone = PCSCode - PCS_WGS84_UTM_zone_1S + 1;
    }
    else if( PCSCode >= PCS_SAD69_UTM_zone_18N 
	     && PCSCode <= PCS_SAD69_UTM_zone_22N )
    {
	Datum = KvUserDefined;
	Proj = MapSys_UTM_North;
	nZone = PCSCode - PCS_SAD69_UTM_zone_18N + 18;
    }
    else if( PCSCode >= PCS_SAD69_UTM_zone_17S
	     && PCSCode <= PCS_SAD69_UTM_zone_25S )
    {
	Datum = KvUserDefined;
	Proj = MapSys_UTM_South;
	nZone = PCSCode - PCS_SAD69_UTM_zone_17S + 17;
    }

/* -------------------------------------------------------------------- */
/*      State Plane zones, first we translate any PCS_ codes to		*/
/*	a Proj_ code that we can get a handle on.			*/
/* -------------------------------------------------------------------- */
    for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
    {
	if( StatePlaneTable[i] == PCSCode )
	    PCSCode = StatePlaneTable[i+1];
    }

    if( PCSCode <= 15900 && PCSCode >= 10000 )
    {
	if( (PCSCode % 100) >= 30 )
        {
            Proj = MapSys_State_Plane_83;
	    Datum = GCS_NAD83;
        }
	else
        {
            Proj = MapSys_State_Plane_27;
	    Datum = GCS_NAD27;
        }
	
	nZone = PCSCode - 10000;
	if( Datum == GCS_NAD83 )
	    nZone -= 30;
    }

    if( pDatum != NULL )
        *pDatum = Datum;

    if( pZone != NULL )
        *pZone = nZone;

    return( Proj );
}

/************************************************************************/
/*                          GTIFProjToMapSys()                          */
/************************************************************************/

/**
 * Translate a Proj_ code into a UTM or State Plane map system, and a zone
 * if possible.
 *
 * @param ProjCode The projection code (Proj_*) as would be stored in the
 * ProjectionGeoKey of a GeoTIFF file.
 * @param pZone Pointer to an integer into which the zone will be placed
 * if the function is successful.
 *
 * @return Returns either MapSys_UTM_North, MapSys_UTM_South,
 * MapSys_State_Plane_27, MapSys_State_Plane_83 or KvUserDefined.
 * KvUserDefined indicates that the
 * function failed to recognise the projection as UTM or State Plane.
 *
 * The zone value is only set if the return code is other than KvUserDefined.
 * For utm map system the returned zone will be between 1 and 60.  For
 * State Plane, the USGS state plane zone number is returned.  For instance,
 * Alabama East is zone 101.
 *
 * This function is useful to recognise UTM and State Plane coordinate
 * systems, and to extract zone numbers so the projections can be
 * represented as UTM rather than as the underlying projection method such
 * Transverse Mercator for instance.
 */

int GTIFProjToMapSys( int ProjCode, int * pZone )

{
    int		nZone = KvUserDefined;
    int		MapSys = KvUserDefined;

/* -------------------------------------------------------------------- */
/*      Handle UTM.                                                     */
/* -------------------------------------------------------------------- */
    if( ProjCode >= Proj_UTM_zone_1N && ProjCode <= Proj_UTM_zone_60N )
    {
	MapSys = MapSys_UTM_North;
	nZone = ProjCode - Proj_UTM_zone_1N + 1;
    }
    else if( ProjCode >= Proj_UTM_zone_1S && ProjCode <= Proj_UTM_zone_60S )
    {
	MapSys = MapSys_UTM_South;
	nZone = ProjCode - Proj_UTM_zone_1S + 1;
    }

/* -------------------------------------------------------------------- */
/*      Handle State Plane.  I think there are some anomolies in        */
/*      here, so this is a bit risky.                                   */
/* -------------------------------------------------------------------- */
    else if( ProjCode >= 10101 && ProjCode <= 15299 )
    {
        if( ProjCode % 100 >= 30 )
        {
            MapSys = MapSys_State_Plane_83;
            nZone = ProjCode - 10000 - 30;
        }
        else
        {
            MapSys = MapSys_State_Plane_27;
            nZone = ProjCode - 10000;
        }
    }
    
    if( pZone != NULL )
        *pZone = nZone;

    return( MapSys );
}