LCOV - code coverage report
Current view: directory - frmts/gtiff/libgeotiff - geo_get.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 29 22 75.9 %
Date: 2010-01-09 Functions: 3 2 66.7 %

       1                 : /**********************************************************************
       2                 :  *
       3                 :  *  geo_get.c  -- Public routines for GEOTIFF GeoKey access.
       4                 :  *
       5                 :  *    Written By: Niles D. Ritter.
       6                 :  *
       7                 :  *  copyright (c) 1995   Niles D. Ritter
       8                 :  *
       9                 :  *  Permission granted to use this software, so long as this copyright
      10                 :  *  notice accompanies any products derived therefrom.
      11                 :  *
      12                 :  *  Revision History;
      13                 :  *
      14                 :  *    20 June, 1995      Niles D. Ritter         New
      15                 :  *    3 July,  1995      Greg Martin             Fix strings and index
      16                 :  *    6 July,  1995      Niles D. Ritter         Unfix indexing.
      17                 :  *
      18                 :  **********************************************************************/
      19                 : 
      20                 : #include "geotiff.h"   /* public interface        */
      21                 : #include "geo_tiffp.h" /* external TIFF interface */
      22                 : #include "geo_keyp.h"  /* private interface       */
      23                 : 
      24                 : /* return the Header info of this geotiff file */
      25                 : 
      26             896 : void GTIFDirectoryInfo(GTIF *gtif, int version[3], int *keycount)
      27                 : {
      28             896 :         if (version)
      29                 :         {
      30             896 :                 version[0]  = gtif->gt_version;
      31             896 :                 version[1]  = gtif->gt_rev_major;
      32             896 :                 version[2]  = gtif->gt_rev_minor;
      33                 :         }
      34             896 :         if (keycount) *keycount = gtif->gt_num_keys;
      35             896 : }
      36                 : 
      37                 : 
      38               0 : int GTIFKeyInfo(GTIF *gtif, geokey_t key, int *size, tagtype_t* type)
      39                 : {
      40               0 :         int index = gtif->gt_keyindex[ key ];
      41                 :         GeoKey *keyptr;
      42                 : 
      43               0 :         if (!index) return 0;
      44                 : 
      45               0 :         keyptr = gtif->gt_keys + index;
      46               0 :         if (size) *size = (int) keyptr->gk_size;
      47               0 :         if (type) *type = keyptr->gk_type;
      48                 : 
      49               0 :         return keyptr->gk_count;
      50                 : }
      51                 : 
      52                 : /** 
      53                 : 
      54                 : This function reads the value of a single GeoKey from a GeoTIFF file.
      55                 : 
      56                 : @param gtif The geotiff information handle from GTIFNew().
      57                 : 
      58                 : @param thekey The geokey_t name (such as ProjectedCSTypeGeoKey).
      59                 : This must come from the list of legal geokey_t values
      60                 : (an enumeration) listed below.
      61                 : 
      62                 : @param val The <b>val</b> argument is a pointer to the
      63                 : variable into which the value should be read.  The type of the variable
      64                 : varies depending on the geokey_t given.  While there is no ready mapping
      65                 : of geokey_t values onto types, in general code values are of type <i>short</i>,
      66                 : citations are strings, and everything else is of type <i>double</i>.  Note
      67                 : that pointer's to <i>int</i> should never be passed to GTIFKeyGet() for
      68                 : integer values as they will be shorts, and the int's may not be properly
      69                 : initialized (and will be grossly wrong on MSB systems).
      70                 : 
      71                 : @param index Indicates how far into the list of values
      72                 : for this geokey to offset. Should normally be zero.
      73                 : 
      74                 : @param count Indicates how many values
      75                 : to read.  At this time all keys except for strings have only one value,
      76                 : so <b>index</b> should be zero, and <b>count</b> should be one.
      77                 : 
      78                 : @return The GTIFKeyGet() function returns the number of values read.  Normally
      79                 : this would be one if successful or zero if the key doesn't exist for this
      80                 : file.
      81                 : 
      82                 : From geokeys.inc we see the following geokey_t values are possible:<p>
      83                 : 
      84                 : <pre>
      85                 : -- 6.2.1 GeoTIFF Configuration Keys --
      86                 : 
      87                 : ValuePair(  GTModelTypeGeoKey,  1024) -- Section 6.3.1.1 Codes       --
      88                 : ValuePair(  GTRasterTypeGeoKey, 1025) -- Section 6.3.1.2 Codes       --
      89                 : ValuePair(  GTCitationGeoKey, 1026) -- documentation --
      90                 : 
      91                 : -- 6.2.2 Geographic CS Parameter Keys --
      92                 : 
      93                 : ValuePair(  GeographicTypeGeoKey, 2048) -- Section 6.3.2.1 Codes     --
      94                 : ValuePair(  GeogCitationGeoKey, 2049) -- documentation             --
      95                 : ValuePair(  GeogGeodeticDatumGeoKey,  2050) -- Section 6.3.2.2 Codes     --
      96                 : ValuePair(  GeogPrimeMeridianGeoKey,  2051) -- Section 6.3.2.4 codes     --
      97                 : ValuePair(  GeogLinearUnitsGeoKey,  2052) -- Section 6.3.1.3 Codes     --
      98                 : ValuePair(  GeogLinearUnitSizeGeoKey, 2053) -- meters                    --
      99                 : ValuePair(  GeogAngularUnitsGeoKey, 2054) -- Section 6.3.1.4 Codes     --
     100                 : ValuePair(  GeogAngularUnitSizeGeoKey,  2055) -- radians                   --
     101                 : ValuePair(  GeogEllipsoidGeoKey,  2056) -- Section 6.3.2.3 Codes     --
     102                 : ValuePair(  GeogSemiMajorAxisGeoKey,  2057) -- GeogLinearUnits           --
     103                 : ValuePair(  GeogSemiMinorAxisGeoKey,  2058) -- GeogLinearUnits           --
     104                 : ValuePair(  GeogInvFlatteningGeoKey,  2059) -- ratio                     --
     105                 : ValuePair(  GeogAzimuthUnitsGeoKey, 2060) -- Section 6.3.1.4 Codes     --
     106                 : ValuePair(  GeogPrimeMeridianLongGeoKey,  2061) -- GeoAngularUnit            --
     107                 : 
     108                 : -- 6.2.3 Projected CS Parameter Keys --
     109                 : --    Several keys have been renamed,--
     110                 : --    and the deprecated names aliased for backward compatibility --
     111                 : 
     112                 : ValuePair(  ProjectedCSTypeGeoKey,  3072)     -- Section 6.3.3.1 codes   --
     113                 : ValuePair(  PCSCitationGeoKey,  3073)     -- documentation           --
     114                 : ValuePair(  ProjectionGeoKey, 3074)     -- Section 6.3.3.2 codes   --
     115                 : ValuePair(  ProjCoordTransGeoKey, 3075)     -- Section 6.3.3.3 codes   --
     116                 : ValuePair(  ProjLinearUnitsGeoKey,  3076)     -- Section 6.3.1.3 codes   --
     117                 : ValuePair(  ProjLinearUnitSizeGeoKey, 3077)     -- meters                  --
     118                 : ValuePair(  ProjStdParallel1GeoKey, 3078)     -- GeogAngularUnit --
     119                 : ValuePair(  ProjStdParallelGeoKey,ProjStdParallel1GeoKey) -- ** alias **   --
     120                 : ValuePair(  ProjStdParallel2GeoKey, 3079)     -- GeogAngularUnit --
     121                 : ValuePair(  ProjNatOriginLongGeoKey,  3080)     -- GeogAngularUnit --
     122                 : ValuePair(  ProjOriginLongGeoKey,ProjNatOriginLongGeoKey) -- ** alias **     --
     123                 : ValuePair(  ProjNatOriginLatGeoKey, 3081)     -- GeogAngularUnit --
     124                 : ValuePair(  ProjOriginLatGeoKey,ProjNatOriginLatGeoKey)   -- ** alias **     --
     125                 : ValuePair(  ProjFalseEastingGeoKey, 3082)     -- ProjLinearUnits --
     126                 : ValuePair(  ProjFalseNorthingGeoKey,  3083)     -- ProjLinearUnits --
     127                 : ValuePair(  ProjFalseOriginLongGeoKey,  3084)     -- GeogAngularUnit --
     128                 : ValuePair(  ProjFalseOriginLatGeoKey, 3085)     -- GeogAngularUnit --
     129                 : ValuePair(  ProjFalseOriginEastingGeoKey, 3086)     -- ProjLinearUnits --
     130                 : ValuePair(  ProjFalseOriginNorthingGeoKey,  3087)     -- ProjLinearUnits --
     131                 : ValuePair(  ProjCenterLongGeoKey, 3088)     -- GeogAngularUnit --
     132                 : ValuePair(  ProjCenterLatGeoKey,  3089)     -- GeogAngularUnit --
     133                 : ValuePair(  ProjCenterEastingGeoKey,  3090)     -- ProjLinearUnits --
     134                 : ValuePair(  ProjCenterNorthingGeoKey, 3091)     -- ProjLinearUnits --
     135                 : ValuePair(  ProjScaleAtNatOriginGeoKey, 3092)     -- ratio   --
     136                 : ValuePair(  ProjScaleAtOriginGeoKey,ProjScaleAtNatOriginGeoKey)  -- ** alias **   --
     137                 : ValuePair(  ProjScaleAtCenterGeoKey,  3093)     -- ratio   --
     138                 : ValuePair(  ProjAzimuthAngleGeoKey, 3094)     -- GeogAzimuthUnit --
     139                 : ValuePair(  ProjStraightVertPoleLongGeoKey, 3095)     -- GeogAngularUnit --
     140                 : 
     141                 :  6.2.4 Vertical CS Keys 
     142                 :    
     143                 : ValuePair(  VerticalCSTypeGeoKey, 4096)  -- Section 6.3.4.1 codes   --
     144                 : ValuePair(  VerticalCitationGeoKey, 4097)  -- documentation --
     145                 : ValuePair(  VerticalDatumGeoKey,  4098)  -- Section 6.3.4.2 codes   --
     146                 : ValuePair(  VerticalUnitsGeoKey,  4099)  -- Section 6.3.1 (.x) codes   --
     147                 : </pre>
     148                 : */
     149                 : 
     150           15725 : int GTIFKeyGet(GTIF *gtif, geokey_t thekey, void *val, int index, int count)
     151                 : {
     152           15725 :         int kindex = gtif->gt_keyindex[ thekey ];
     153                 :         GeoKey *key;
     154                 :         gsize_t size;
     155                 :         char *data;
     156                 :         tagtype_t type;
     157                 : 
     158           15725 :         if (!kindex) return 0;
     159                 : 
     160            5050 :         key = gtif->gt_keys+kindex;
     161            5050 :         if (!count) count = key->gk_count - index;
     162            5050 :         if (count <=0) return 0;
     163            5050 :         if (count > key->gk_count) count = key->gk_count;
     164            5050 :         size = key->gk_size;
     165            5050 :         type = key->gk_type;
     166                 : 
     167            5050 :         if (count==1 && type==TYPE_SHORT) data = (char *)&key->gk_data;
     168            1207 :         else data = key->gk_data;
     169                 : 
     170            5050 :         _GTIFmemcpy( val, data + index*size, count*size );
     171                 : 
     172            5050 :         if (type==TYPE_ASCII)
     173              23 :            ((char *)val)[count-1] = '\0'; /* replace last char with NULL */
     174                 : 
     175            5050 :         return count;
     176                 : }

Generated by: LCOV version 1.7