LCOV - code coverage report
Current view: directory - frmts/gtiff/libgeotiff - geo_names.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 59 14 23.7 %
Date: 2010-01-09 Functions: 10 3 30.0 %

       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                 : 
      44              62 : static char *FindName(KeyInfo *info,int key)
      45                 : {
      46                 :    static char errmsg[80];
      47                 :    
      48              62 :    while (info->ki_key>=0 && info->ki_key != key) info++;
      49                 : 
      50              62 :    if (info->ki_key<0)
      51                 :    {
      52               0 :      sprintf(errmsg,"Unknown-%d", key );
      53               0 :      return errmsg;
      54                 :    }
      55              62 :    return info->ki_name;
      56                 : }
      57                 : 
      58              42 : char *GTIFKeyName(geokey_t key)
      59                 : {
      60              42 :    return FindName( &_keyInfo[0],key);
      61                 : }
      62                 : 
      63               0 : char *GTIFTypeName(tagtype_t type)
      64                 : {
      65               0 :    return FindName( &_formatInfo[0],type);
      66                 : }
      67                 : 
      68               0 : char *GTIFTagName(int tag)
      69                 : {
      70               0 :    return FindName( &_tagInfo[0],tag);
      71                 : }
      72                 : 
      73              20 : char *GTIFValueName(geokey_t key, int value)
      74                 : {
      75                 :    KeyInfo *info;
      76                 :    
      77              20 :    switch (key)
      78                 :    {
      79                 :   /* All codes using linear/angular/whatever units */
      80                 :   case GeogLinearUnitsGeoKey: 
      81                 :   case ProjLinearUnitsGeoKey: 
      82                 :   case GeogAngularUnitsGeoKey: 
      83                 :   case GeogAzimuthUnitsGeoKey: 
      84               2 :                           info=_geounitsValue; break;
      85                 : 
      86                 :     /* put other key-dependent lists here */
      87               6 :   case GTModelTypeGeoKey:       info=_modeltypeValue; break;
      88               6 :   case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
      89               4 :   case GeographicTypeGeoKey:    info=_geographicValue; break;
      90               0 :   case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
      91               0 :   case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
      92               0 :   case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
      93               2 :   case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
      94               0 :   case ProjectionGeoKey:        info=_projectionValue; break;
      95               0 :   case ProjCoordTransGeoKey:    info=_coordtransValue; break;
      96               0 :   case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
      97               0 :   case VerticalDatumGeoKey:     info=_vdatumValue; break;
      98                 : 
      99                 :   /* And if all else fails... */
     100               0 :     default:                      info = _csdefaultValue;break;
     101                 :    }
     102                 :    
     103              20 :    return FindName( info,value);
     104                 : }
     105                 : 
     106                 : /* 
     107                 :  * Inverse Utilities (name->code) 
     108                 :  */
     109                 : 
     110                 : 
     111               0 : static int FindCode(KeyInfo *info,char *key)
     112                 : {
     113               0 :    while (info->ki_key>=0 && strcmp(info->ki_name,key) ) info++;
     114                 : 
     115               0 :    if (info->ki_key<0)
     116                 :    {
     117                 :   /* not a registered key; might be generic code */
     118               0 :   if (!strncmp(key,"Unknown-",8))
     119                 :   {
     120               0 :     int code=-1;
     121               0 :     sscanf(key,"Unknown-%d",&code);
     122               0 :     return code;
     123                 :   }
     124               0 :   else return -1;
     125                 :    }
     126               0 :    return info->ki_key;
     127                 : }
     128                 : 
     129               0 : int GTIFKeyCode(char *key)
     130                 : {
     131               0 :    return FindCode( &_keyInfo[0],key);
     132                 : }
     133                 : 
     134               0 : int GTIFTypeCode(char *type)
     135                 : {
     136               0 :    return FindCode( &_formatInfo[0],type);
     137                 : }
     138                 : 
     139               0 : int GTIFTagCode(char *tag)
     140                 : {
     141               0 :    return FindCode( &_tagInfo[0],tag);
     142                 : }
     143                 : 
     144                 : 
     145                 : /*
     146                 :  *  The key must be determined with GTIFKeyCode() before
     147                 :  *  the name can be encoded.
     148                 :  */
     149               0 : int GTIFValueCode(geokey_t key, char *name)
     150                 : {
     151                 :    KeyInfo *info;
     152                 :    
     153               0 :    switch (key)
     154                 :    {
     155                 :   /* All codes using linear/angular/whatever units */
     156                 :   case GeogLinearUnitsGeoKey: 
     157                 :   case ProjLinearUnitsGeoKey: 
     158                 :   case GeogAngularUnitsGeoKey: 
     159                 :   case GeogAzimuthUnitsGeoKey: 
     160               0 :                           info=_geounitsValue; break;
     161                 : 
     162                 :     /* put other key-dependent lists here */
     163               0 :   case GTModelTypeGeoKey:       info=_modeltypeValue; break;
     164               0 :   case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
     165               0 :   case GeographicTypeGeoKey:    info=_geographicValue; break;
     166               0 :   case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
     167               0 :   case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
     168               0 :   case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
     169               0 :   case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
     170               0 :   case ProjectionGeoKey:        info=_projectionValue; break;
     171               0 :   case ProjCoordTransGeoKey:    info=_coordtransValue; break;
     172               0 :   case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
     173               0 :   case VerticalDatumGeoKey:     info=_vdatumValue; break;
     174                 : 
     175                 :   /* And if all else fails... */
     176               0 :     default:                      info = _csdefaultValue;break;
     177                 :    }
     178                 :    
     179               0 :    return FindCode( info,name);
     180                 : }
     181                 : 

Generated by: LCOV version 1.7