[Geotiff] C API for unofficial private tags GDAL_NODATA and GDAL_METADATA

Even Rouault even.rouault at mines-paris.org
Sat Sep 28 07:32:22 PDT 2013


Le samedi 28 septembre 2013 16:22:13, Pierre Soille a écrit :
> Hello,
> 
> when writing GeoTIFF files from a C programme using libgeotiff API, I
> would like to include the unofficial private tags GDAL_NODATA and
> GDAL_METADATA.  However, so far I did not succeed doing this for it
> seems that they are not defined in the current header files associated
> with libgeotiff-1.4.0.   Any hint would be very much appreciated.
> 
> Best regards,

Pierre,

I'd suggest you to use the GDAL library that has abstraction for those 
details.

Otherwise, if you want to do it at hand, you can try the following code 
(copied & pasted from the GeoTIFF driver in GDAL)


#define TIFFTAG_GDAL_METADATA  42112
#define TIFFTAG_GDAL_NODATA    42113
#define TIFFTAG_RPCCOEFFICIENT 50844


/************************************************************************/
/*                          GTiffTagExtender()                          */
/*                                                                      */
/*      Install tags specially known to GDAL.                           */
/************************************************************************/

static TIFFExtendProc _ParentExtender = NULL;

static void GTiffTagExtender(TIFF *tif)

{
    static const TIFFFieldInfo xtiffFieldInfo[] = {
        { TIFFTAG_GDAL_METADATA,    -1,-1, TIFF_ASCII,	FIELD_CUSTOM,
          TRUE,	FALSE,	(char*) "GDALMetadata" },
        { TIFFTAG_GDAL_NODATA,	    -1,-1, TIFF_ASCII,	FIELD_CUSTOM,
          TRUE,	FALSE,	(char*) "GDALNoDataValue" },
        { TIFFTAG_RPCCOEFFICIENT,   -1,-1, TIFF_DOUBLE,	FIELD_CUSTOM,
          TRUE,	TRUE,	(char*) "RPCCoefficient" }
    };

    if (_ParentExtender) 
        (*_ParentExtender)(tif);

    TIFFMergeFieldInfo( tif, xtiffFieldInfo,
		        sizeof(xtiffFieldInfo) / sizeof(xtiffFieldInfo[0]) );
}

/* call it only once in the lifetime of the program before opening/creating a 
TIFF */
void InstallGDALTiffTags()
{
    _ParentExtender = TIFFSetTagExtender(GTiffTagExtender);
}

Best regards,

Even

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html



More information about the Geotiff mailing list