Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

geo_names.c

00001 /*
00002  * geo_names.c
00003  *
00004  *  This encapsulates all of the value-naming mechanism of 
00005  *  libgeotiff. 
00006  *
00007  *  Written By: Niles Ritter
00008  */
00009 
00010 #include "geotiffio.h"
00011 #include "geonames.h"
00012 #include "geo_tiffp.h" /* for tag names */
00013 
00014 static KeyInfo _formatInfo[] =  {
00015    {TYPE_BYTE,    "Byte"},
00016    {TYPE_SHORT,   "Short"},
00017    {TYPE_LONG,    "Long"},
00018    {TYPE_RATIONAL,"Rational"},
00019    {TYPE_ASCII,   "Ascii"},
00020    {TYPE_FLOAT,   "Float"},
00021    {TYPE_DOUBLE,  "Double"},
00022    {TYPE_SBYTE,   "SignedByte"},
00023    {TYPE_SSHORT,  "SignedShort"},
00024    {TYPE_SLONG,  "SignedLong"},
00025    {TYPE_UNKNOWN, "Unknown"},
00026     END_LIST
00027 };
00028 
00029 static KeyInfo _tagInfo[] =  {
00030     {GTIFF_PIXELSCALE,  "ModelPixelScaleTag"},
00031     {GTIFF_TRANSMATRIX, "ModelTransformationTag"},
00032     {GTIFF_TIEPOINTS,   "ModelTiepointTag"},
00033      /* This alias maps the Intergraph symbol to the current tag */
00034     {GTIFF_TRANSMATRIX, "IntergraphMatrixTag"},
00035     END_LIST
00036 };
00037 
00038 static char *FindName(KeyInfo *info,int key)
00039 {
00040    static char errmsg[80];
00041    
00042    while (info->ki_key>=0 && info->ki_key != key) info++;
00043 
00044    if (info->ki_key<0)
00045    {
00046            sprintf(errmsg,"Unknown-%d", key );
00047            return errmsg;
00048    }
00049    return info->ki_name;
00050 }
00051 
00052 char *GTIFKeyName(geokey_t key)
00053 {
00054    return FindName( &_keyInfo[0],key);
00055 }
00056 
00057 char *GTIFTypeName(tagtype_t type)
00058 {
00059    return FindName( &_formatInfo[0],type);
00060 }
00061 
00062 char *GTIFTagName(int tag)
00063 {
00064    return FindName( &_tagInfo[0],tag);
00065 }
00066 
00067 char *GTIFValueName(geokey_t key, int value)
00068 {
00069    KeyInfo *info;
00070    
00071    switch (key)
00072    {
00073         /* All codes using linear/angular/whatever units */
00074         case GeogLinearUnitsGeoKey: 
00075         case ProjLinearUnitsGeoKey: 
00076         case GeogAngularUnitsGeoKey: 
00077         case GeogAzimuthUnitsGeoKey: 
00078                                       info=_geounitsValue; break;
00079 
00080         /* put other key-dependent lists here */
00081         case GTModelTypeGeoKey:       info=_modeltypeValue; break;
00082         case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
00083         case GeographicTypeGeoKey:    info=_geographicValue; break;
00084         case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
00085         case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
00086         case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
00087         case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
00088         case ProjectionGeoKey:        info=_projectionValue; break;
00089         case ProjCoordTransGeoKey:    info=_coordtransValue; break;
00090         case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
00091         case VerticalDatumGeoKey:     info=_vdatumValue; break;
00092 
00093         /* And if all else fails... */
00094         default:                      info = _csdefaultValue;break;
00095    }
00096    
00097    return FindName( info,value);
00098 }
00099 
00100 /* 
00101  * Inverse Utilities (name->code) 
00102  */
00103 
00104 
00105 static int FindCode(KeyInfo *info,char *key)
00106 {
00107    while (info->ki_key>=0 && strcmp(info->ki_name,key) ) info++;
00108 
00109    if (info->ki_key<0)
00110    {
00111         /* not a registered key; might be generic code */
00112         if (!strncmp(key,"Unknown-",8))
00113         {
00114                 int code=-1;
00115                 sscanf(key,"Unknown-%d",&code);
00116                 return code;
00117         }
00118         else return -1;
00119    }
00120    return info->ki_key;
00121 }
00122 
00123 int GTIFKeyCode(char *key)
00124 {
00125    return FindCode( &_keyInfo[0],key);
00126 }
00127 
00128 int GTIFTypeCode(char *type)
00129 {
00130    return FindCode( &_formatInfo[0],type);
00131 }
00132 
00133 int GTIFTagCode(char *tag)
00134 {
00135    return FindCode( &_tagInfo[0],tag);
00136 }
00137 
00138 
00139 /*
00140  *  The key must be determined with GTIFKeyCode() before
00141  *  the name can be encoded.
00142  */
00143 int GTIFValueCode(geokey_t key, char *name)
00144 {
00145    KeyInfo *info;
00146    
00147    switch (key)
00148    {
00149         /* All codes using linear/angular/whatever units */
00150         case GeogLinearUnitsGeoKey: 
00151         case ProjLinearUnitsGeoKey: 
00152         case GeogAngularUnitsGeoKey: 
00153         case GeogAzimuthUnitsGeoKey: 
00154                                       info=_geounitsValue; break;
00155 
00156         /* put other key-dependent lists here */
00157         case GTModelTypeGeoKey:       info=_modeltypeValue; break;
00158         case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
00159         case GeographicTypeGeoKey:    info=_geographicValue; break;
00160         case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
00161         case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
00162         case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
00163         case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
00164         case ProjectionGeoKey:        info=_projectionValue; break;
00165         case ProjCoordTransGeoKey:    info=_coordtransValue; break;
00166         case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
00167         case VerticalDatumGeoKey:     info=_vdatumValue; break;
00168 
00169         /* And if all else fails... */
00170         default:                      info = _csdefaultValue;break;
00171    }
00172    
00173    return FindCode( info,name);
00174 }
00175 

Generated at Sun Mar 4 23:32:44 2001 for libgeotiff by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000