-
Notifications
You must be signed in to change notification settings - Fork 2
/
geo_names.c
182 lines (154 loc) · 4.54 KB
/
geo_names.c
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
/*
* geo_names.c
*
* This encapsulates all of the value-naming mechanism of
* libgeotiff.
*
* Written By: Niles Ritter
*
* copyright (c) 1995 Niles D. Ritter
*
* Permission granted to use this software, so long as this copyright
* notice accompanies any products derived therefrom.
*
*/
#include "geotiffio.h"
#include "geonames.h"
#include "geo_tiffp.h" /* for tag names */
static KeyInfo _formatInfo[] = {
{TYPE_BYTE, "Byte"},
{TYPE_SHORT, "Short"},
{TYPE_LONG, "Long"},
{TYPE_RATIONAL,"Rational"},
{TYPE_ASCII, "Ascii"},
{TYPE_FLOAT, "Float"},
{TYPE_DOUBLE, "Double"},
{TYPE_SBYTE, "SignedByte"},
{TYPE_SSHORT, "SignedShort"},
{TYPE_SLONG, "SignedLong"},
{TYPE_UNKNOWN, "Unknown"},
END_LIST
};
static KeyInfo _tagInfo[] = {
{GTIFF_PIXELSCALE, "ModelPixelScaleTag"},
{GTIFF_TRANSMATRIX, "ModelTransformationTag"},
{GTIFF_TIEPOINTS, "ModelTiepointTag"},
/* This alias maps the Intergraph symbol to the current tag */
{GTIFF_TRANSMATRIX, "IntergraphMatrixTag"},
END_LIST
};
static char *FindName(KeyInfo *info,int key)
{
static char errmsg[80];
while (info->ki_key>=0 && info->ki_key != key) info++;
if (info->ki_key<0)
{
sprintf(errmsg,"Unknown-%d", key );
return errmsg;
}
return info->ki_name;
}
char *GTIFKeyName(geokey_t key)
{
return FindName( &_keyInfo[0],key);
}
char *GTIFTypeName(tagtype_t type)
{
return FindName( &_formatInfo[0],type);
}
char *GTIFTagName(int tag)
{
return FindName( &_tagInfo[0],tag);
}
char *GTIFValueName(geokey_t key, int value)
{
KeyInfo *info;
switch (key)
{
/* All codes using linear/angular/whatever units */
case GeogLinearUnitsGeoKey:
case ProjLinearUnitsGeoKey:
case GeogAngularUnitsGeoKey:
case GeogAzimuthUnitsGeoKey:
case VerticalUnitsGeoKey:
info=_geounitsValue; break;
/* put other key-dependent lists here */
case GTModelTypeGeoKey: info=_modeltypeValue; break;
case GTRasterTypeGeoKey: info=_rastertypeValue; break;
case GeographicTypeGeoKey: info=_geographicValue; break;
case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
case GeogEllipsoidGeoKey: info=_ellipsoidValue; break;
case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
case ProjectedCSTypeGeoKey: info=_pcstypeValue; break;
case ProjectionGeoKey: info=_projectionValue; break;
case ProjCoordTransGeoKey: info=_coordtransValue; break;
case VerticalCSTypeGeoKey: info=_vertcstypeValue; break;
case VerticalDatumGeoKey: info=_vdatumValue; break;
/* And if all else fails... */
default: info = _csdefaultValue;break;
}
return FindName( info,value);
}
/*
* Inverse Utilities (name->code)
*/
static int FindCode(KeyInfo *info,char *key)
{
while (info->ki_key>=0 && strcmp(info->ki_name,key) ) info++;
if (info->ki_key<0)
{
/* not a registered key; might be generic code */
if (!strncmp(key,"Unknown-",8))
{
int code=-1;
sscanf(key,"Unknown-%d",&code);
return code;
}
else return -1;
}
return info->ki_key;
}
int GTIFKeyCode(char *key)
{
return FindCode( &_keyInfo[0],key);
}
int GTIFTypeCode(char *type)
{
return FindCode( &_formatInfo[0],type);
}
int GTIFTagCode(char *tag)
{
return FindCode( &_tagInfo[0],tag);
}
/*
* The key must be determined with GTIFKeyCode() before
* the name can be encoded.
*/
int GTIFValueCode(geokey_t key, char *name)
{
KeyInfo *info;
switch (key)
{
/* All codes using linear/angular/whatever units */
case GeogLinearUnitsGeoKey:
case ProjLinearUnitsGeoKey:
case GeogAngularUnitsGeoKey:
case GeogAzimuthUnitsGeoKey:
info=_geounitsValue; break;
/* put other key-dependent lists here */
case GTModelTypeGeoKey: info=_modeltypeValue; break;
case GTRasterTypeGeoKey: info=_rastertypeValue; break;
case GeographicTypeGeoKey: info=_geographicValue; break;
case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
case GeogEllipsoidGeoKey: info=_ellipsoidValue; break;
case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
case ProjectedCSTypeGeoKey: info=_pcstypeValue; break;
case ProjectionGeoKey: info=_projectionValue; break;
case ProjCoordTransGeoKey: info=_coordtransValue; break;
case VerticalCSTypeGeoKey: info=_vertcstypeValue; break;
case VerticalDatumGeoKey: info=_vdatumValue; break;
/* And if all else fails... */
default: info = _csdefaultValue;break;
}
return FindCode( info,name);
}