I am trying to make a code to read and retrieve geographical and raster data from a GeoTIFF file, but I'm having a hard time with the extended tags. I have no problem with the regular TIFF tags (like IMAGEWIDTH, using tiffgetfield()) or the geokeys (like ProjectedCSTypeGeoKey, using GTIFKeyGet() or taking it from the definition struct), but what's giving me problem are the extended tags provided by geotiff library.

I can see the information I need (pixel scale and tie point tags) using GTIFPrint(), but I don't know how to access the metadata file, and haven't been able to get the data I want using TIFFGetField() since I can't call the function properly.

This is how I was calling TIFFGetField

double* pixscl;
int* pixscalesize;

TIFFGetField(tif, GTIFF_TIEPOINTS, &pixscalesize);
printf("Model Pixel Scale Tag is:\n      %d\n", pixscalesize);

What I'm getting here is the number of elements in the tag, which is 3 for pixel scale, and 6 for tie point, but still have no access to the actual values.

Any ideas on how I can store the values of these tags to print or use in another function?

PS: I am using only libgeotiff, GDAL is out of discussion because all of its components, and I'm aiming to a light weight and simple application.

2 Answers 2


After two days of trying to answer this precise question, I finally found the solution of GTIFImageToPCS(). TIFFGetField() is not intended to do this, and GTIFKeyGet() only works on single-field keys.

  • Hi Denton, thanks for your answer. I think you might be confused because GTIFImageToPCS() is used to convert coordinates, not to handle keys/tags May 22, 2018 at 16:12
  • It extracts and converts some of the relevant tags and gives you access at least to the ModelTiepointTags. The basic problem is that any of the TIFF key handling was only designed to deal with individual keys. Initially the GeoTIFF designers stuck to that, but at some point, they added tags with multiple values. GTIFImageToPCS allowed me to solve at least part of this. To be honest, I didn't try to get PixScaleSize, so I overstated what I could do. Initially, I wrote a very cautious reply which was deleted right away, so then I got frustrated, since I think your basic problem is the same. May 23, 2018 at 19:11

Here is how to get the tie points using libgeotiff:

Include these (you may not need all of them):

#include <tiff.h>
#include <tiffio.h>
#include <geotiff/xtiffio.h>
#include <geotiff/geotiff.h>
#include <geotiff/geotiffio.h>

Open the file like this:

TIFF* tif = XTIFFOpen(filename.c_str(), "r");
GTIF* gtif = GTIFNew(tif);

And get the points like so:

unsigned short count;
double* tiePoints;
if(TIFFGetField(tif, TIFFTAG_GEOTIEPOINTS, &count, &tiePoints)==1) {
    printf("Tie Points: \n");
    for (int index = 0; index < count;) {
        printf("  X: %f",tiePoints[index]);
        printf("\t  Y: %f",tiePoints[index]);
        printf("\t  Lat: %f",tiePoints[index]);
        printf("\t  Lon: %f\n",tiePoints[index])l;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.