1 // This is core/vil/file_formats/vil_geotiff_header.h
2 #ifndef vil_geotiff_header_h_
3 #define vil_geotiff_header_h_
4 //:
5 // \file
6 // \author    Gamze Tunali
7 // \date      Jan 31, 2007
8 // \brief A header structure for geotiff files
9 //
10 // This class is responsible for extracting (putting) information
11 // from (into) the geotiff header that is required to specify a vil_image_resource
12 // There are bool flags that indicate that the item has been successfully
13 // read (written) to the open geotiff file.
14 //
15 // \verbatim
16 //  Modifications
17 //   <none>
18 // \endverbatim
19 
20 #include <vector>
21 #ifdef _MSC_VER
22 #  include <vcl_msvc_warnings.h>
23 #endif
24 #include <tiffio.h>
25 #include <geotiffio.h>
26 
27 class vil_geotiff_header
28 {
29  public:
30 
31   typedef enum {UNDEF=-1, NORTH=0, SOUTH=1} GTIF_HEMISPH;
32   vil_geotiff_header(TIFF* tif);
33 
34   // destructor frees up gtif
~vil_geotiff_header()35   virtual ~vil_geotiff_header() { GTIFFree(gtif_); }
36 
gtif_number_of_keys()37   int gtif_number_of_keys() const { return number_of_geokeys_; }
38 
39   bool gtif_tiepoints(std::vector<std::vector<double> > &tiepoints);
40 
41   bool gtif_pixelscale(double &scale_x, double &scale_y, double &scale_z);
42 
43   //:returns the matrix in the argument
44   bool gtif_trans_matrix (double* &trans_matrix);
45 
46   //: returns the Zone and the Hemisphere (0 for N, 1 for S);
47   bool PCS_WGS84_UTM_zone(int &zone, GTIF_HEMISPH &hemisph);
48 
49   //: returns the Zone and the Hemisphere (0 for N, 1 for S);
50   bool PCS_NAD83_UTM_zone(int &zone, GTIF_HEMISPH &hemisph);
51 
52   //: returns true if in geographic coords, linear units are in meters and angular units are in degrees
53   bool GCS_WGS84_MET_DEG();
54 
55   //: other header fields
56   bool gtif_modeltype(modeltype_t& type);
57   bool gtif_rastertype(rastertype_t& type);
58   bool geounits(geounits_t& units);
59 
60   //: <key> : key id
61   // <value>: a single value or an array of values
62   // <size>:  the size of individual key values
63   // <length> : the number of values in the value array
64   // <type>: the type of the key
65   bool get_key_value(geokey_t key, void** value,
66                      int& size, int& length, tagtype_t& type);
67 
print_gtif()68   void print_gtif(){ if (gtif_) GTIFPrint(gtif_, nullptr, nullptr); }
69 
70  private:
71 
72   TIFF* tif_;
73   GTIF* gtif_;
74 
75   // the current version is 1, changes only Tag's key structure is changed
76   unsigned short key_directory_version_;
77 
78   // the revision number is key_revision.minor_revision
79   unsigned short key_revision_;
80   unsigned short minor_revision_;
81 
82   // the number of keys defined in the rest of the tag
83   int number_of_geokeys_;
84 
85 };
86 
87 #endif //vil_geotiff_header_h_
88