-
Notifications
You must be signed in to change notification settings - Fork 10
/
geokeys.go
2479 lines (2396 loc) · 75.5 KB
/
geokeys.go
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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package lidario
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"math"
"strings"
)
// GeoKeys structure
type GeoKeys struct {
GeoKeyDirectory []uint16
GeoDoubleParams []float64
GeoASCIIParams string
Tags []GeoTiffTag
}
func (gk *GeoKeys) addKeyDirectory(data []uint8) {
// convert the binary data to an array of u16's
i := 0
for i < len(data) {
k := binary.LittleEndian.Uint16(data[i : i+2])
// k := uint16(data[i]) | (uint16(data[i+1]) << uint16(8))
gk.GeoKeyDirectory = append(gk.GeoKeyDirectory, k)
i += 2
}
}
func (gk *GeoKeys) addDoubleParams(data []uint8) {
i := 0
for i < len(data) {
k := math.Float64frombits(binary.LittleEndian.Uint64(data[i : i+8]))
gk.GeoDoubleParams = append(gk.GeoDoubleParams, k)
i += 8
}
}
func (gk *GeoKeys) addASCIIParams(data []uint8) {
gk.GeoASCIIParams = string(data[:])
}
func (gk *GeoKeys) getIFDSlice() []IfdEntry {
if len(gk.GeoKeyDirectory) == 0 {
panic("Error reading geokeys")
}
numKeys := gk.GeoKeyDirectory[3]
ifdData := make([]IfdEntry, 0)
for i := uint16(0); i < numKeys; i++ {
offset := 4 * (i + 1)
keyID := gk.GeoKeyDirectory[offset]
var fieldType uint16
tiffTagLocation := gk.GeoKeyDirectory[offset+1]
count := gk.GeoKeyDirectory[offset+2]
valueOffset := gk.GeoKeyDirectory[offset+3]
var data []byte
if tiffTagLocation == 34737 {
// ASCII data
fieldType = 2
value := gk.GeoASCIIParams[valueOffset:(valueOffset + count)]
value = strings.Replace(value, "|", "", -1)
vals := []byte(value)
for _, b := range vals {
data = append(data, b)
}
} else if tiffTagLocation == 34736 {
// double (float64) data
fieldType = 12
value := gk.GeoDoubleParams[valueOffset:(valueOffset + count)]
for i := uint16(0); i < count; i++ {
bits := math.Float64bits(value[i])
bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, bits)
for j := 0; j < len(bytes); j++ {
data = append(data, bytes[j])
}
}
} else if tiffTagLocation == 0 {
// short (u16) data
fieldType = 3
bytes := make([]byte, 2)
binary.LittleEndian.PutUint16(bytes, valueOffset)
data = append(data, bytes[0])
data = append(data, bytes[1])
}
ifd := CreateIfdEntry(int(keyID), GeotiffDataType(fieldType), uint32(count), data, binary.LittleEndian)
ifdData = append(ifdData, ifd)
}
return ifdData
}
func (gk *GeoKeys) interpretGeokeys() string {
if len(gk.GeoKeyDirectory) == 0 {
return "There are no geokeys"
}
m := gk.getIFDSlice()
var buffer bytes.Buffer
var s string
for i, v := range m {
s = fmt.Sprintf("Geokey %v { %v }\n", i+1, v)
buffer.WriteString(s)
}
return buffer.String()
}
// errors types
var errUnsupportedDataType = errors.New("Unsupported data type")
// IfdEntry IFD entry
type IfdEntry struct {
tag GeoTiffTag
dataType GeotiffDataType
count uint32
rawData []byte
byteOrder binary.ByteOrder
}
// AddData adds data to the IFD entry
func (ifd *IfdEntry) AddData(data []byte) {
if data != nil {
ifd.rawData = append(ifd.rawData, data...)
}
}
// CreateIfdEntry returns a new IFD entry
func CreateIfdEntry(code int, dataType GeotiffDataType, count uint32, data interface{}, byteOrder binary.ByteOrder) IfdEntry {
var ret IfdEntry
if myTag, ok := tagMap[code]; !ok {
panic(errors.New("unrecognized tag"))
} else {
ret.tag = myTag
}
ret.dataType = dataType
ret.count = count
ret.byteOrder = byteOrder
if data != nil {
// if dataType != DTASCII {
buf := new(bytes.Buffer)
binary.Write(buf, byteOrder, data)
ret.rawData = buf.Bytes()
// } else {
// if str, ok := data.(string); ok {
// ret.rawData = []byte(str)
// }
// }
}
return ret
}
// InterpretDataAsInt interprets the data as an integer
func (ifd *IfdEntry) InterpretDataAsInt() (u []uint, err error) {
u = make([]uint, ifd.count)
switch ifd.dataType {
case DTByte:
for i := uint32(0); i < ifd.count; i++ {
u[i] = uint(ifd.rawData[i])
}
case DTShort:
for i := uint32(0); i < ifd.count; i++ {
u[i] = uint(ifd.byteOrder.Uint16(ifd.rawData[2*i : 2*(i+1)]))
}
case DTLong:
for i := uint32(0); i < ifd.count; i++ {
u[i] = uint(ifd.byteOrder.Uint32(ifd.rawData[4*i : 4*(i+1)]))
}
default:
return nil, errUnsupportedDataType
}
return u, nil
}
// InterpretDataAsFloat interprets the data as a float
func (ifd *IfdEntry) InterpretDataAsFloat() (u []float64, err error) {
u = make([]float64, ifd.count)
switch ifd.dataType {
case DTFloat:
u2 := make([]float32, ifd.count)
for i := uint32(0); i < ifd.count; i++ {
// I'm not sure this code will work
buf := bytes.NewReader(ifd.rawData[4*i : 4*(i+1)])
binary.Read(buf, ifd.byteOrder, &u2[i])
}
for i := uint32(0); i < ifd.count; i++ {
u[i] = float64(u2[i])
}
case DTDouble:
for i := uint32(0); i < ifd.count; i++ {
buf := bytes.NewReader(ifd.rawData[8*i : 8*(i+1)])
binary.Read(buf, ifd.byteOrder, &u[i])
}
default:
return nil, errUnsupportedDataType
}
return u, nil
}
// InterpretDataAsRational interprets the data as a rational number
func (ifd *IfdEntry) InterpretDataAsRational() (u []float64, err error) {
u = make([]float64, ifd.count)
switch ifd.dataType {
case DTRational:
offset := 0
for i := uint32(0); i < ifd.count; i++ {
v1 := uint(ifd.byteOrder.Uint32(ifd.rawData[offset : offset+4]))
v2 := uint(ifd.byteOrder.Uint32(ifd.rawData[offset+4 : offset+8]))
u[i] = float64(v1) / float64(v2)
offset += 8
}
default:
return nil, errUnsupportedDataType
}
return u, nil
}
// InterpretDataAsASCII decodes the IFD entry in p, which must be of the ASCII
// type, and returns the decoded uint values.
func (ifd *IfdEntry) InterpretDataAsASCII() (u []string, err error) {
u = make([]string, 1)
switch ifd.dataType {
case DTASCII:
u[0] = string(ifd.rawData[:ifd.count-1])
default:
return nil, errUnsupportedDataType
}
return u, nil
}
func (ifd IfdEntry) String() string {
s := ifd.tag
retVal := fmt.Sprintf("%v, dataType: %v, count: %v", s, ifd.dataType, ifd.count)
switch ifd.dataType {
case DTByte,
DTLong:
v, _ := ifd.InterpretDataAsInt()
return fmt.Sprintf("%s value: %v", retVal, v)
case DTShort:
v, _ := ifd.InterpretDataAsInt()
if ifd.count == 1 {
if strVal, ok := tagLookupTable(&ifd); ok == nil {
return fmt.Sprintf("%s value: [%v, %s]", retVal, v[0], strVal)
}
return fmt.Sprintf("%s value: %v", retVal, v)
}
return fmt.Sprintf("%s value: %v", retVal, v)
case DTRational:
v, _ := ifd.InterpretDataAsRational()
return fmt.Sprintf("%s value: %v", retVal, v)
case DTFloat,
DTDouble:
v, _ := ifd.InterpretDataAsFloat()
return fmt.Sprintf("%s value: %f", retVal, v)
case DTASCII:
// v, _ := ifd.InterpretDataAsASCII()
return fmt.Sprintf("%s value: %v", retVal, string(ifd.rawData)) //v)
}
return retVal
}
// make a slice of IfdEntries sortable by its GeoTiffTag code
type ifdSortedByCode []IfdEntry
func (a ifdSortedByCode) Len() int { return len(a) }
func (a ifdSortedByCode) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ifdSortedByCode) Less(i, j int) bool { return a[i].tag.Code < a[j].tag.Code }
// GeotiffDataType geoTIFF data type
type GeotiffDataType int
// Data types (p. 14-16 of the spec).
const (
DTByte = 1
DTASCII = 2
DTShort = 3
DTLong = 4
DTRational = 5
DTSbyte = 6
DTUndefined = 7
DTSshort = 8
DTSlong = 9
DTSrational = 10
DTFloat = 11
DTDouble = 12
)
// The length of one instance of each data type in bytes.
var dataTypeLengths = [...]uint32{0, 1, 1, 2, 4, 8, 1, 2, 2, 4, 8, 8, 16}
var dataTypeList = []string{
"Byte",
"ASCII",
"Short",
"Long",
"Rational",
"Sbyte",
"Undefined",
"Sshort",
"Slong",
"Srational",
"Float",
"Double",
}
// String returns the English name of the DataType ("Byte", "ASCII", ...).
func (g GeotiffDataType) String() string { return dataTypeList[g-1] }
// GetBitLength returns the bit length
func (g GeotiffDataType) GetBitLength() uint32 {
return dataTypeLengths[g]
}
// GeoTiffTag data structure
type GeoTiffTag struct {
Name string
Code int
}
func (g GeoTiffTag) String() string {
return fmt.Sprintf("name: %s, code: %d", g.Name, g.Code)
}
// Tags (see p. 28-41 of the spec).
var tagMap = map[int]GeoTiffTag{
254: GeoTiffTag{"NewSubFileType", 254},
256: GeoTiffTag{"ImageWidth", 256},
257: GeoTiffTag{"ImageLength", 257},
258: GeoTiffTag{"BitsPerSample", 258},
259: GeoTiffTag{"Compression", 259},
262: GeoTiffTag{"PhotometricInterpretation", 262},
266: GeoTiffTag{"FillOrder", 266},
269: GeoTiffTag{"DocumentName", 269},
284: GeoTiffTag{"PlanarConfiguration", 284},
270: GeoTiffTag{"ImageDescription", 270},
271: GeoTiffTag{"Make", 271},
272: GeoTiffTag{"Model", 272},
273: GeoTiffTag{"StripOffsets", 273},
274: GeoTiffTag{"Orientation", 274},
277: GeoTiffTag{"SamplesPerPixel", 277},
278: GeoTiffTag{"RowsPerStrip", 278},
279: GeoTiffTag{"StripByteCounts", 279},
282: GeoTiffTag{"XResolution", 282},
283: GeoTiffTag{"YResolution", 283},
296: GeoTiffTag{"ResolutionUnit", 296},
305: GeoTiffTag{"Software", 305},
306: GeoTiffTag{"DateTime", 306},
322: GeoTiffTag{"TileWidth", 322},
323: GeoTiffTag{"TileLength", 323},
324: GeoTiffTag{"TileOffsets", 324},
325: GeoTiffTag{"TileByteCounts", 325},
317: GeoTiffTag{"Predictor", 317},
320: GeoTiffTag{"ColorMap", 320},
338: GeoTiffTag{"ExtraSamples", 338},
339: GeoTiffTag{"SampleFormat", 339},
34735: GeoTiffTag{"GeoKeyDirectoryTag", 34735},
34736: GeoTiffTag{"GeoDoubleParamsTag", 34736},
34737: GeoTiffTag{"GeoAsciiParamsTag", 34737},
33550: GeoTiffTag{"ModelPixelScaleTag", 33550},
33922: GeoTiffTag{"ModelTiepointTag", 33922},
34264: GeoTiffTag{"ModelTransformationTag", 34264},
42112: GeoTiffTag{"GDAL_METADATA", 42112},
42113: GeoTiffTag{"GDAL_NODATA", 42113},
1024: GeoTiffTag{"GTModelTypeGeoKey", 1024},
1025: GeoTiffTag{"GTRasterTypeGeoKey", 1025},
1026: GeoTiffTag{"GTCitationGeoKey", 1026},
2048: GeoTiffTag{"GeographicTypeGeoKey", 2048},
2049: GeoTiffTag{"GeogCitationGeoKey", 2049},
2050: GeoTiffTag{"GeogGeodeticDatumGeoKey", 2050},
2051: GeoTiffTag{"GeogPrimeMeridianGeoKey", 2051},
2061: GeoTiffTag{"GeogPrimeMeridianLongGeoKey", 2061},
2052: GeoTiffTag{"GeogLinearUnitsGeoKey", 2052},
2053: GeoTiffTag{"GeogLinearUnitSizeGeoKey", 2053},
2054: GeoTiffTag{"GeogAngularUnitsGeoKey", 2054},
2055: GeoTiffTag{"GeogAngularUnitSizeGeoKey", 2055},
2056: GeoTiffTag{"GeogEllipsoidGeoKey", 2056},
2057: GeoTiffTag{"GeogSemiMajorAxisGeoKey", 2057},
2058: GeoTiffTag{"GeogSemiMinorAxisGeoKey", 2058},
2059: GeoTiffTag{"GeogInvFlatteningGeoKey", 2059},
2060: GeoTiffTag{"GeogAzimuthUnitsGeoKey", 2060},
3072: GeoTiffTag{"ProjectedCSTypeGeoKey", 3072},
3073: GeoTiffTag{"PCSCitationGeoKey", 3073},
3074: GeoTiffTag{"ProjectionGeoKey", 3074},
3075: GeoTiffTag{"ProjCoordTransGeoKey", 3075},
3076: GeoTiffTag{"ProjLinearUnitsGeoKey", 3076},
3077: GeoTiffTag{"ProjLinearUnitSizeGeoKey", 3077},
3078: GeoTiffTag{"ProjStdParallel1GeoKey", 3078},
3079: GeoTiffTag{"ProjStdParallel2GeoKey", 3079},
3080: GeoTiffTag{"ProjNatOriginLongGeoKey", 3080},
3081: GeoTiffTag{"ProjNatOriginLatGeoKey", 3081},
3082: GeoTiffTag{"ProjFalseEastingGeoKey", 3082},
3083: GeoTiffTag{"ProjFalseNorthingGeoKey", 3083},
3084: GeoTiffTag{"ProjFalseOriginLongGeoKey", 3084},
3085: GeoTiffTag{"ProjFalseOriginLatGeoKey", 3085},
3086: GeoTiffTag{"ProjFalseOriginEastingGeoKey", 3086},
3087: GeoTiffTag{"ProjFalseOriginNorthingGeoKey", 3087},
3088: GeoTiffTag{"ProjCenterLongGeoKey", 3088},
3089: GeoTiffTag{"ProjCenterLatGeoKey", 3089},
3090: GeoTiffTag{"ProjCenterEastingGeoKey", 3090},
3091: GeoTiffTag{"ProjFalseOriginNorthingGeoKey", 3091},
3092: GeoTiffTag{"ProjScaleAtNatOriginGeoKey", 3092},
3093: GeoTiffTag{"ProjScaleAtCenterGeoKey", 3093},
3094: GeoTiffTag{"ProjAzimuthAngleGeoKey", 3094},
3095: GeoTiffTag{"ProjStraightVertPoleLongGeoKey", 3095},
4096: GeoTiffTag{"VerticalCSTypeGeoKey", 4096},
4097: GeoTiffTag{"VerticalCitationGeoKey", 4097},
4098: GeoTiffTag{"VerticalDatumGeoKey", 4098},
4099: GeoTiffTag{"VerticalUnitsGeoKey", 4099},
50844: GeoTiffTag{"RPCCoefficientTag", 50844},
34377: GeoTiffTag{"Photoshop", 34377},
}
const (
leHeader = "II\x2A\x00" // Header for little-endian files.
beHeader = "MM\x00\x2A" // Header for big-endian files.
ifdLen = 12 // Length of an IFD entry in bytes.
)
// Data types (p. 14-16 of the spec).
const (
dtByte = 1
dtASCII = 2
dtShort = 3
dtLong = 4
dtRational = 5
dtSbyte = 6
dtUndefined = 7
dtSshort = 8
dtSlong = 9
dtSrational = 10
dtFloat = 11
dtDouble = 12
)
// The length of one instance of each data type in bytes.
var lengths = [...]uint32{0, 1, 1, 2, 4, 8, 1, 2, 2, 4, 8, 8, 16}
// Tags (see p. 28-41 of the spec).
const (
tNewSubfileType = 254
tImageWidth = 256
tImageLength = 257
tBitsPerSample = 258
tCompression = 259
tPhotometricInterpretation = 262
tFillOrder = 266
tDocumentName = 269
tPlanarConfiguration = 284
tStripOffsets = 273
tOrientation = 274
tSamplesPerPixel = 277
tRowsPerStrip = 278
tStripByteCounts = 279
tTileWidth = 322
tTileLength = 323
tTileOffsets = 324
tTileByteCounts = 325
tXResolution = 282
tYResolution = 283
tResolutionUnit = 296
tSoftware = 305
tPredictor = 317
tColorMap = 320
tExtraSamples = 338
tSampleFormat = 339
tGDALMETADATA = 42112
tGDALNODATA = 42113
tModelPixelScaleTag = 33550
tModelTransformationTag = 34264
tModelTiepointTag = 33922
tGeoKeyDirectoryTag = 34735
tGeoDoubleParamsTag = 34736
tGeoASCIIParamsTag = 34737
tIntergraphMatrixTag = 33920
tGTModelTypeGeoKey = 1024
tGTRasterTypeGeoKey = 1025
tGTCitationGeoKey = 1026
tGeographicTypeGeoKey = 2048
tGeogCitationGeoKey = 2049
tGeogGeodeticDatumGeoKey = 2050
tGeogPrimeMeridianGeoKey = 2051
tGeogLinearUnitsGeoKey = 2052
tGeogLinearUnitSizeGeoKey = 2053
tGeogAngularUnitsGeoKey = 2054
tGeogAngularUnitSizeGeoKey = 2055
tGeogEllipsoidGeoKey = 2056
tGeogSemiMajorAxisGeoKey = 2057
tGeogSemiMinorAxisGeoKey = 2058
tGeogInvFlatteningGeoKey = 2059
tGeogAzimuthUnitsGeoKey = 2060
tGeogPrimeMeridianLongGeoKey = 2061
tProjectedCSTypeGeoKey = 3072
tPCSCitationGeoKey = 3073
tProjectionGeoKey = 3074
tProjCoordTransGeoKey = 3075
tProjLinearUnitsGeoKey = 3076
tProjLinearUnitSizeGeoKey = 3077
tProjStdParallel1GeoKey = 3078
tProjStdParallel2GeoKey = 3079
tProjNatOriginLongGeoKey = 3080
tProjNatOriginLatGeoKey = 3081
tProjFalseEastingGeoKey = 3082
tProjFalseNorthingGeoKey = 3083
tProjFalseOriginLongGeoKey = 3084
tProjFalseOriginLatGeoKey = 3085
tProjFalseOriginEastingGeoKey = 3086
tProjFalseOriginNorthingGeoKey = 3087
tProjCenterLongGeoKey = 3088
tProjCenterLatGeoKey = 3089
tProjCenterEastingGeoKey = 3090
tProjCenterNorthingGeoKey = 3091
tProjScaleAtNatOriginGeoKey = 3092
tProjScaleAtCenterGeoKey = 3093
tProjAzimuthAngleGeoKey = 3094
tProjStraightVertPoleLongGeoKey = 3095
tVerticalCSTypeGeoKey = 4096
tVerticalCitationGeoKey = 4097
tVerticalDatumGeoKey = 4098
tVerticalUnitsGeoKey = 4099
tPhotoshop = 34377
)
// imageMode represents the mode of the image.
type imageMode int
const (
mBilevel imageMode = iota
mPaletted
mGray
mGrayInvert
mRGB
mRGBA
mNRGBA
)
// Compression types (defined in various places in the spec and supplements).
const (
cNone = 1
cCCITT = 2
cG3 = 3 // Group 3 Fax.
cG4 = 4 // Group 4 Fax.
cLZW = 5
cJPEGOld = 6 // Superseded by cJPEG.
cJPEG = 7
cDeflate = 8 // zlib compression.
cPackBits = 32773
cDeflateOld = 32946 // Superseded by cDeflate.
)
// Photometric interpretation values (see p. 37 of the spec).
const (
PIWhiteIsZero = 0
PIBlackIsZero = 1
PIRGB = 2
PIPaletted = 3
PITransMask = 4
PICMYK = 5
PIYCbCr = 6
PICIELab = 8
)
// Sample formats (page 80 of the spec).
const (
SFUnsignedInteger = 1
SFSignedInteger = 2
SFFloatingPoint = 3
SFUknown = 4
)
// Values for the tPredictor tag (page 64-65 of the spec).
const (
prNone = 1
prHorizontal = 2
)
// Values for the tResolutionUnit tag (page 18).
const (
resNone = 1
resPerInch = 2 // Dots per inch.
resPerCM = 3 // Dots per centimeter.
)
// If an IfdEntry is of Short data type and length 1, it may be a keyword.
// This function simply returns the keyword if it exists and is known.
func tagLookupTable(entry *IfdEntry) (string, error) {
if entry.dataType == DTShort && entry.count == 1 {
code := entry.tag.Code
// is there a corresponding map?
if m, ok := keywordMap[code]; ok {
values, _ := entry.InterpretDataAsInt()
if v, ok := m[values[0]]; ok {
return v, nil
}
return "", errors.New("Could not locate entry")
}
return "", errors.New("Could not locate entry")
}
return "", errors.New("Could not locate entry")
}
var keywordMap = map[int]map[uint]string{
259: compressionMap,
262: photometricMap,
284: planarConfiguationMap,
296: resolutionUnitsMap,
317: predictorMap,
339: sampleFormatMap,
1024: gtModelTypeGeoKeyMap,
1025: gtRasterTypeGeoKeyMap,
2048: geographicTypeMap,
2050: geodeticDatumMap,
2051: primeMeridianMap,
2052: linearUnitsMap,
2054: angularUnitsMap,
2056: ellipsoidMap,
3072: projectedCSMap,
3074: projectionMap,
3075: projCoordTransGeoKeyMap,
3076: linearUnitsMap,
4096: verticalCSTypeMap,
4099: verticalUnitsMap,
}
var photometricMap = map[uint]string{
0: "WhiteIsZero",
1: "BlackIsZero",
2: "RGB",
3: "Paletted",
4: "TransMask",
5: "pCMYK",
6: "pYCbCr",
7: "pCIELab",
}
var resolutionUnitsMap = map[uint]string{
1: "None",
2: "Dots per inch",
3: "Dots per centimeter",
}
var compressionMap = map[uint]string{
1: "None",
2: "CCITT",
3: "G3",
4: "G4",
5: "LZW",
6: "JPEGOld",
7: "JPEG",
8: "Deflate",
32773: "PackBits",
32946: "DeflateOld",
}
var predictorMap = map[uint]string{
1: "None",
2: "Horizontal",
}
var planarConfiguationMap = map[uint]string{
1: "Contiguous",
2: "Separate",
}
var sampleFormatMap = map[uint]string{
1: "Unsigned integer data",
2: "Signed integer data",
3: "Floating point data",
4: "Undefined data format",
}
var gtModelTypeGeoKeyMap = map[uint]string{
1: "ModelTypeProjected",
2: "ModelTypeGeographic",
3: "ModelTypeGeocentric",
}
var gtRasterTypeGeoKeyMap = map[uint]string{
1: "RasterPixelIsArea",
2: "RasterPixelIsPoint",
}
var linearUnitsMap = map[uint]string{
9001: "Linear_Meter",
9002: "Linear_Foot",
9003: "Linear_Foot_US_Survey",
9004: "Linear_Foot_Modified_American",
9005: "Linear_Foot_Clarke",
9006: "Linear_Foot_Indian",
9007: "Linear_Link",
9008: "Linear_Link_Benoit",
9009: "Linear_Link_Sears",
9010: "Linear_Chain_Benoit",
9011: "Linear_Chain_Sears",
9012: "Linear_Yard_Sears",
9013: "Linear_Yard_Indian",
9014: "Linear_Fathom",
9015: "Linear_Mile_International_Nautical",
}
var angularUnitsMap = map[uint]string{
9101: "Angular_Radian",
9102: "Angular_Degree",
9103: "Angular_Arc_Minute",
9104: "Angular_Arc_Second",
9105: "Angular_Grad",
9106: "Angular_Gon",
9107: "Angular_DMS",
9108: "Angular_DMS_Hemisphere",
}
var verticalUnitsMap = map[uint]string{
9001: "Linear_Meter",
9002: "Linear_Foot",
9003: "Linear_Foot_US_Survey",
9004: "Linear_Foot_Modified_American",
9005: "Linear_Foot_Clarke",
9006: "Linear_Foot_Indian",
9007: "Linear_Link",
9008: "Linear_Link_Benoit",
9009: "Linear_Link_Sears",
9010: "Linear_Chain_Benoit",
9011: "Linear_Chain_Sears",
9012: "Linear_Yard_Sears",
9013: "Linear_Yard_Indian",
9014: "Linear_Fathom",
9015: "Linear_Mile_International_Nautical",
}
var geographicTypeMap = map[uint]string{
4201: "GCS_Adindan",
4202: "GCS_AGD66",
4203: "GCS_AGD84",
4204: "GCS_Ain_el_Abd",
4205: "GCS_Afgooye",
4206: "GCS_Agadez",
4207: "GCS_Lisbon",
4208: "GCS_Aratu",
4209: "GCS_Arc_1950",
4210: "GCS_Arc_1960",
4211: "GCS_Batavia",
4212: "GCS_Barbados",
4213: "GCS_Beduaram",
4214: "GCS_Beijing_1954",
4215: "GCS_Belge_1950",
4216: "GCS_Bermuda_1957",
4217: "GCS_Bern_1898",
4218: "GCS_Bogota",
4219: "GCS_Bukit_Rimpah",
4220: "GCS_Camacupa",
4221: "GCS_Campo_Inchauspe",
4222: "GCS_Cape",
4223: "GCS_Carthage",
4224: "GCS_Chua",
4225: "GCS_Corrego_Alegre",
4226: "GCS_Cote_d_Ivoire",
4227: "GCS_Deir_ez_Zor",
4228: "GCS_Douala",
4229: "GCS_Egypt_1907",
4230: "GCS_ED50",
4231: "GCS_ED87",
4232: "GCS_Fahud",
4233: "GCS_Gandajika_1970",
4234: "GCS_Garoua",
4235: "GCS_Guyane_Francaise",
4236: "GCS_Hu_Tzu_Shan",
4237: "GCS_HD72",
4238: "GCS_ID74",
4239: "GCS_Indian_1954",
4240: "GCS_Indian_1975",
4241: "GCS_Jamaica_1875",
4242: "GCS_JAD69",
4243: "GCS_Kalianpur",
4244: "GCS_Kandawala",
4245: "GCS_Kertau",
4246: "GCS_KOC",
4247: "GCS_La_Canoa",
4248: "GCS_PSAD56",
4249: "GCS_Lake",
4250: "GCS_Leigon",
4251: "GCS_Liberia_1964",
4252: "GCS_Lome",
4253: "GCS_Luzon_1911",
4254: "GCS_Hito_XVIII_1963",
4255: "GCS_Herat_North",
4256: "GCS_Mahe_1971",
4257: "GCS_Makassar",
4258: "GCS_EUREF89",
4259: "GCS_Malongo_1987",
4260: "GCS_Manoca",
4261: "GCS_Merchich",
4262: "GCS_Massawa",
4263: "GCS_Minna",
4264: "GCS_Mhast",
4265: "GCS_Monte_Mario",
4266: "GCS_M_poraloko",
4267: "GCS_NAD27",
4268: "GCS_NAD_Michigan",
4269: "GCS_NAD83",
4270: "GCS_Nahrwan_1967",
4271: "GCS_Naparima_1972",
4272: "GCS_GD49",
4273: "GCS_NGO_1948",
4274: "GCS_Datum_73",
4275: "GCS_NTF",
4276: "GCS_NSWC_9Z_2",
4277: "GCS_OSGB_1936",
4278: "GCS_OSGB70",
4279: "GCS_OS_SN80",
4280: "GCS_Padang",
4281: "GCS_Palestine_1923",
4282: "GCS_Pointe_Noire",
4283: "GCS_GDA94",
4284: "GCS_Pulkovo_1942",
4285: "GCS_Qatar",
4286: "GCS_Qatar_1948",
4287: "GCS_Qornoq",
4288: "GCS_Loma_Quintana",
4289: "GCS_Amersfoort",
4290: "GCS_RT38",
4291: "GCS_SAD69",
4292: "GCS_Sapper_Hill_1943",
4293: "GCS_Schwarzeck",
4294: "GCS_Segora",
4295: "GCS_Serindung",
4296: "GCS_Sudan",
4297: "GCS_Tananarive",
4298: "GCS_Timbalai_1948",
4299: "GCS_TM65",
4300: "GCS_TM75",
4301: "GCS_Tokyo",
4302: "GCS_Trinidad_1903",
4303: "GCS_TC_1948",
4304: "GCS_Voirol_1875",
4305: "GCS_Voirol_Unifie",
4306: "GCS_Bern_1938",
4307: "GCS_Nord_Sahara_1959",
4308: "GCS_Stockholm_1938",
4309: "GCS_Yacare",
4310: "GCS_Yoff",
4311: "GCS_Zanderij",
4312: "GCS_MGI",
4313: "GCS_Belge_1972",
4314: "GCS_DHDN",
4315: "GCS_Conakry_1905",
4322: "GCS_WGS_72",
4324: "GCS_WGS_72BE",
4326: "GCS_WGS_84",
4801: "GCS_Bern_1898_Bern",
4802: "GCS_Bogota_Bogota",
4803: "GCS_Lisbon_Lisbon",
4804: "GCS_Makassar_Jakarta",
4805: "GCS_MGI_Ferro",
4806: "GCS_Monte_Mario_Rome",
4807: "GCS_NTF_Paris",
4808: "GCS_Padang_Jakarta",
4809: "GCS_Belge_1950_Brussels",
4810: "GCS_Tananarive_Paris",
4811: "GCS_Voirol_1875_Paris",
4812: "GCS_Voirol_Unifie_Paris",
4813: "GCS_Batavia_Jakarta",
4901: "GCS_ATF_Paris",
4902: "GCS_NDG_Paris",
4001: "GCSE_Airy1830",
4002: "GCSE_AiryModified1849",
4003: "GCSE_AustralianNationalSpheroid",
4004: "GCSE_Bessel1841",
4005: "GCSE_BesselModified",
4006: "GCSE_BesselNamibia",
4007: "GCSE_Clarke1858",
4008: "GCSE_Clarke1866",
4009: "GCSE_Clarke1866Michigan",
4010: "GCSE_Clarke1880_Benoit",
4011: "GCSE_Clarke1880_IGN",
4012: "GCSE_Clarke1880_RGS",
4013: "GCSE_Clarke1880_Arc",
4014: "GCSE_Clarke1880_SGA1922",
4015: "GCSE_Everest1830_1937Adjustment",
4016: "GCSE_Everest1830_1967Definition",
4017: "GCSE_Everest1830_1975Definition",
4018: "GCSE_Everest1830Modified",
4019: "GCSE_GRS1980",
4020: "GCSE_Helmert1906",
4021: "GCSE_IndonesianNationalSpheroid",
4022: "GCSE_International1924",
4023: "GCSE_International1967",
4024: "GCSE_Krassowsky1940",
4025: "GCSE_NWL9D",
4026: "GCSE_NWL10D",
4027: "GCSE_Plessis1817",
4028: "GCSE_Struve1860",
4029: "GCSE_WarOffice",
4030: "GCSE_WGS84",
4031: "GCSE_GEM10C",
4032: "GCSE_OSU86F",
4033: "GCSE_OSU91A",
4034: "GCSE_Clarke1880",
4035: "GCSE_Sphere",
}
var geodeticDatumMap = map[uint]string{
6201: "Datum_Adindan",
6202: "Datum_Australian_Geodetic_Datum_1966",
6203: "Datum_Australian_Geodetic_Datum_1984",
6204: "Datum_Ain_el_Abd_1970",
6205: "Datum_Afgooye",
6206: "Datum_Agadez",
6207: "Datum_Lisbon",
6208: "Datum_Aratu",
6209: "Datum_Arc_1950",
6210: "Datum_Arc_1960",
6211: "Datum_Batavia",
6212: "Datum_Barbados",
6213: "Datum_Beduaram",
6214: "Datum_Beijing_1954",
6215: "Datum_Reseau_National_Belge_1950",
6216: "Datum_Bermuda_1957",
6217: "Datum_Bern_1898",
6218: "Datum_Bogota",
6219: "Datum_Bukit_Rimpah",
6220: "Datum_Camacupa",
6221: "Datum_Campo_Inchauspe",
6222: "Datum_Cape",
6223: "Datum_Carthage",
6224: "Datum_Chua",
6225: "Datum_Corrego_Alegre",
6226: "Datum_Cote_d_Ivoire",
6227: "Datum_Deir_ez_Zor",
6228: "Datum_Douala",
6229: "Datum_Egypt_1907",
6230: "Datum_European_Datum_1950",
6231: "Datum_European_Datum_1987",
6232: "Datum_Fahud",
6233: "Datum_Gandajika_1970",
6234: "Datum_Garoua",
6235: "Datum_Guyane_Francaise",
6236: "Datum_Hu_Tzu_Shan",
6237: "Datum_Hungarian_Datum_1972",
6238: "Datum_Indonesian_Datum_1974",
6239: "Datum_Indian_1954",
6240: "Datum_Indian_1975",
6241: "Datum_Jamaica_1875",
6242: "Datum_Jamaica_1969",
6243: "Datum_Kalianpur",
6244: "Datum_Kandawala",
6245: "Datum_Kertau",
6246: "Datum_Kuwait_Oil_Company",
6247: "Datum_La_Canoa",
6248: "Datum_Provisional_S_American_Datum_1956",
6249: "Datum_Lake",
6250: "Datum_Leigon",
6251: "Datum_Liberia_1964",
6252: "Datum_Lome",
6253: "Datum_Luzon_1911",
6254: "Datum_Hito_XVIII_1963",
6255: "Datum_Herat_North",
6256: "Datum_Mahe_1971",
6257: "Datum_Makassar",
6258: "Datum_European_Reference_System_1989",
6259: "Datum_Malongo_1987",
6260: "Datum_Manoca",
6261: "Datum_Merchich",
6262: "Datum_Massawa",
6263: "Datum_Minna",
6264: "Datum_Mhast",
6265: "Datum_Monte_Mario",
6266: "Datum_M_poraloko",
6267: "Datum_North_American_Datum_1927",
6268: "Datum_NAD_Michigan",
6269: "Datum_North_American_Datum_1983",
6270: "Datum_Nahrwan_1967",
6271: "Datum_Naparima_1972",
6272: "Datum_New_Zealand_Geodetic_Datum_1949",
6273: "Datum_NGO_1948",
6274: "Datum_Datum_73",
6275: "Datum_Nouvelle_Triangulation_Francaise",
6276: "Datum_NSWC_9Z_2",
6277: "Datum_OSGB_1936",
6278: "Datum_OSGB_1970_SN",