1 /*
2  * geo_names.c
3  *
4  *  This encapsulates all of the value-naming mechanism of
5  *  libgeotiff.
6  *
7  *  Written By: Niles Ritter
8  *
9  *  copyright (c) 1995   Niles D. Ritter
10  *
11  *  Permission granted to use this software, so long as this copyright
12  *  notice accompanies any products derived therefrom.
13  *
14  */
15 
16 #include "geotiffio.h"
17 #include "geonames.h"
18 #include "geo_tiffp.h" /* for tag names */
19 
20 static KeyInfo _formatInfo[] =  {
21    {TYPE_BYTE,    "Byte"},
22    {TYPE_SHORT,   "Short"},
23    {TYPE_LONG,    "Long"},
24    {TYPE_RATIONAL,"Rational"},
25    {TYPE_ASCII,   "Ascii"},
26    {TYPE_FLOAT,   "Float"},
27    {TYPE_DOUBLE,  "Double"},
28    {TYPE_SBYTE,   "SignedByte"},
29    {TYPE_SSHORT,  "SignedShort"},
30    {TYPE_SLONG,  "SignedLong"},
31    {TYPE_UNKNOWN, "Unknown"},
32     END_LIST
33 };
34 
35 static KeyInfo _tagInfo[] =  {
36     {GTIFF_PIXELSCALE,  "ModelPixelScaleTag"},
37     {GTIFF_TRANSMATRIX, "ModelTransformationTag"},
38     {GTIFF_TIEPOINTS,   "ModelTiepointTag"},
39      /* This alias maps the Intergraph symbol to the current tag */
40     {GTIFF_TRANSMATRIX, "IntergraphMatrixTag"},
41     END_LIST
42 };
43 
FindName(KeyInfo * info,int key)44 static char *FindName(KeyInfo *info,int key)
45 {
46    static char errmsg[80];
47 
48    while (info->ki_key>=0 && info->ki_key != key) info++;
49 
50    if (info->ki_key<0)
51    {
52 	   sprintf(errmsg,"Unknown-%d", key );
53 	   return errmsg;
54    }
55    return info->ki_name;
56 }
57 
GTIFKeyName(geokey_t key)58 char *GTIFKeyName(geokey_t key)
59 {
60    return FindName( &_keyInfo[0],key);
61 }
62 
GTIFTypeName(tagtype_t type)63 char *GTIFTypeName(tagtype_t type)
64 {
65    return FindName( &_formatInfo[0],type);
66 }
67 
GTIFTagName(int tag)68 char *GTIFTagName(int tag)
69 {
70    return FindName( &_tagInfo[0],tag);
71 }
72 
GTIFValueName(geokey_t key,int value)73 char *GTIFValueName(geokey_t key, int value)
74 {
75    KeyInfo *info;
76 
77    switch (key)
78    {
79 	/* All codes using linear/angular/whatever units */
80 	case GeogLinearUnitsGeoKey:
81 	case ProjLinearUnitsGeoKey:
82 	case GeogAngularUnitsGeoKey:
83 	case GeogAzimuthUnitsGeoKey:
84     case VerticalUnitsGeoKey:
85 		                      info=_geounitsValue; break;
86 
87    	/* put other key-dependent lists here */
88 	case GTModelTypeGeoKey:       info=_modeltypeValue; break;
89 	case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
90 	case GeographicTypeGeoKey:    info=_geographicValue; break;
91 	case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
92 	case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
93 	case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
94 	case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
95 	case ProjectionGeoKey:        info=_projectionValue; break;
96 	case ProjCoordTransGeoKey:    info=_coordtransValue; break;
97 	case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
98 	case VerticalDatumGeoKey:     info=_vdatumValue; break;
99 
100 	/* And if all else fails... */
101    	default:                      info = _csdefaultValue;break;
102    }
103 
104    return FindName( info,value);
105 }
106 
107 /*
108  * Inverse Utilities (name->code)
109  */
110 
111 
FindCode(KeyInfo * info,char * key)112 static int FindCode(KeyInfo *info,char *key)
113 {
114    while (info->ki_key>=0 && strcmp(info->ki_name,key) ) info++;
115 
116    if (info->ki_key<0)
117    {
118 	/* not a registered key; might be generic code */
119 	if (!strncmp(key,"Unknown-",8))
120 	{
121 		int code=-1;
122 		sscanf(key,"Unknown-%d",&code);
123 		return code;
124 	}
125 	else return -1;
126    }
127    return info->ki_key;
128 }
129 
GTIFKeyCode(char * key)130 int GTIFKeyCode(char *key)
131 {
132    return FindCode( &_keyInfo[0],key);
133 }
134 
GTIFTypeCode(char * type)135 int GTIFTypeCode(char *type)
136 {
137    return FindCode( &_formatInfo[0],type);
138 }
139 
GTIFTagCode(char * tag)140 int GTIFTagCode(char *tag)
141 {
142    return FindCode( &_tagInfo[0],tag);
143 }
144 
145 
146 /*
147  *  The key must be determined with GTIFKeyCode() before
148  *  the name can be encoded.
149  */
GTIFValueCode(geokey_t key,char * name)150 int GTIFValueCode(geokey_t key, char *name)
151 {
152    KeyInfo *info;
153 
154    switch (key)
155    {
156 	/* All codes using linear/angular/whatever units */
157 	case GeogLinearUnitsGeoKey:
158 	case ProjLinearUnitsGeoKey:
159 	case GeogAngularUnitsGeoKey:
160 	case GeogAzimuthUnitsGeoKey:
161     case VerticalUnitsGeoKey:
162 		                      info=_geounitsValue; break;
163 
164    	/* put other key-dependent lists here */
165 	case GTModelTypeGeoKey:       info=_modeltypeValue; break;
166 	case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
167 	case GeographicTypeGeoKey:    info=_geographicValue; break;
168 	case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
169 	case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
170 	case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
171 	case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
172 	case ProjectionGeoKey:        info=_projectionValue; break;
173 	case ProjCoordTransGeoKey:    info=_coordtransValue; break;
174 	case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
175 	case VerticalDatumGeoKey:     info=_vdatumValue; break;
176 
177 	/* And if all else fails... */
178    	default:                      info = _csdefaultValue;break;
179    }
180 
181    return FindCode( info,name);
182 }
183 
184