LCOV - code coverage report
Current view: directory - frmts/gtiff/libgeotiff - geo_names.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 59 0 0.0 %
Date: 2012-04-28 Functions: 10 0 0.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               0 : static char *FindName(KeyInfo *info,int key)
      45                 : {
      46                 :    static char errmsg[80];
      47                 :    
      48               0 :    while (info->ki_key>=0 && info->ki_key != key) info++;
      49                 : 
      50               0 :    if (info->ki_key<0)
      51                 :    {
      52               0 :      sprintf(errmsg,"Unknown-%d", key );
      53               0 :      return errmsg;
      54                 :    }
      55               0 :    return info->ki_name;
      56                 : }
      57                 : 
      58               0 : char *GTIFKeyName(geokey_t key)
      59                 : {
      60               0 :    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               0 : char *GTIFValueName(geokey_t key, int value)
      74                 : {
      75                 :    KeyInfo *info;
      76                 :    
      77               0 :    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               0 :                           info=_geounitsValue; break;
      86                 : 
      87                 :     /* put other key-dependent lists here */
      88               0 :   case GTModelTypeGeoKey:       info=_modeltypeValue; break;
      89               0 :   case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
      90               0 :   case GeographicTypeGeoKey:    info=_geographicValue; break;
      91               0 :   case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
      92               0 :   case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
      93               0 :   case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
      94               0 :   case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
      95               0 :   case ProjectionGeoKey:        info=_projectionValue; break;
      96               0 :   case ProjCoordTransGeoKey:    info=_coordtransValue; break;
      97               0 :   case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
      98               0 :   case VerticalDatumGeoKey:     info=_vdatumValue; break;
      99                 : 
     100                 :   /* And if all else fails... */
     101               0 :     default:                      info = _csdefaultValue;break;
     102                 :    }
     103                 :    
     104               0 :    return FindName( info,value);
     105                 : }
     106                 : 
     107                 : /* 
     108                 :  * Inverse Utilities (name->code) 
     109                 :  */
     110                 : 
     111                 : 
     112               0 : static int FindCode(KeyInfo *info,char *key)
     113                 : {
     114               0 :    while (info->ki_key>=0 && strcmp(info->ki_name,key) ) info++;
     115                 : 
     116               0 :    if (info->ki_key<0)
     117                 :    {
     118                 :   /* not a registered key; might be generic code */
     119               0 :   if (!strncmp(key,"Unknown-",8))
     120                 :   {
     121               0 :     int code=-1;
     122               0 :     sscanf(key,"Unknown-%d",&code);
     123               0 :     return code;
     124                 :   }
     125               0 :   else return -1;
     126                 :    }
     127               0 :    return info->ki_key;
     128                 : }
     129                 : 
     130               0 : int GTIFKeyCode(char *key)
     131                 : {
     132               0 :    return FindCode( &_keyInfo[0],key);
     133                 : }
     134                 : 
     135               0 : int GTIFTypeCode(char *type)
     136                 : {
     137               0 :    return FindCode( &_formatInfo[0],type);
     138                 : }
     139                 : 
     140               0 : int GTIFTagCode(char *tag)
     141                 : {
     142               0 :    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                 :  */
     150               0 : int GTIFValueCode(geokey_t key, char *name)
     151                 : {
     152                 :    KeyInfo *info;
     153                 :    
     154               0 :    switch (key)
     155                 :    {
     156                 :   /* All codes using linear/angular/whatever units */
     157                 :   case GeogLinearUnitsGeoKey: 
     158                 :   case ProjLinearUnitsGeoKey: 
     159                 :   case GeogAngularUnitsGeoKey: 
     160                 :   case GeogAzimuthUnitsGeoKey: 
     161               0 :                           info=_geounitsValue; break;
     162                 : 
     163                 :     /* put other key-dependent lists here */
     164               0 :   case GTModelTypeGeoKey:       info=_modeltypeValue; break;
     165               0 :   case GTRasterTypeGeoKey:      info=_rastertypeValue; break;
     166               0 :   case GeographicTypeGeoKey:    info=_geographicValue; break;
     167               0 :   case GeogGeodeticDatumGeoKey: info=_geodeticdatumValue; break;
     168               0 :   case GeogEllipsoidGeoKey:     info=_ellipsoidValue; break;
     169               0 :   case GeogPrimeMeridianGeoKey: info=_primemeridianValue; break;
     170               0 :   case ProjectedCSTypeGeoKey:   info=_pcstypeValue; break;
     171               0 :   case ProjectionGeoKey:        info=_projectionValue; break;
     172               0 :   case ProjCoordTransGeoKey:    info=_coordtransValue; break;
     173               0 :   case VerticalCSTypeGeoKey:    info=_vertcstypeValue; break;
     174               0 :   case VerticalDatumGeoKey:     info=_vdatumValue; break;
     175                 : 
     176                 :   /* And if all else fails... */
     177               0 :     default:                      info = _csdefaultValue;break;
     178                 :    }
     179                 :    
     180               0 :    return FindCode( info,name);
     181                 : }
     182                 : 

Generated by: LCOV version 1.7