LFile::WriteGeoKey

#include "ltwrappr.h"

virtual L_INT LFile::WriteGeoKey(pSaveOptions)

pSAVEFILEOPTION pSaveOptions;

/* pointer to optional extended save options */

Writes GeoKeys to a file or changes the existing GeoKeys in a file.

Parameter

Description

pSaveOptions

Pointer to a structure that contains optional extended save options. Pass NULL to use the default save options. pSaveOptions.PageNumber indicates the page on which to write the tags. Note that an error code will be returned if the page does not exist.

Returns

SUCCESS

The function was successful.

ERROR_NOTHING_TO_DO

No GeoKeys have been set before calling this function.

< 1

An error occurred. Refer to Return Codes.

Comments

This function writes to or changes the GeoKeys in an existing file.

This function will write all the GeoKeys that have been set using LFile::SetGeoKey. There must be at least one GeoKey set for this function to work. If no GeoKeys have been set, an error will be returned by this function.

This function works only with TIFF files.

If you also want to write the other TIFF tags and comments, use LFile::WriteMetaData instead of this function.

Note:

Use this function carefully. LEADTOOLS will not restrict the GeoKeys that you write. If you write bad GeoKeys, the file might become corrupted. Consult the GeoTIFF specification documentation for a list of GeoKeys.

Required DLLs and Libraries

LTFIL

LFTIF

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LFile::SetGeoKey, LFile::GetGeoKey, LFile::ReadGeoKey, LFile::EnumGeoKeys, LFile::SaveFile, LFile::SaveBitmap, LFile::WriteMetaData

Topics:

Implementing GeoKeys (GeoTIFF tags)

 

Implementing TIFF Comments and Tags

 

Raster Image Functions: Working with GeoKeys

Example

/* Displays a GeoKey in a message box*/
static L_VOID DisplayKey(L_UINT16 uTag,L_UINT16 uType,L_UINT32 uCount,L_VOID L_FAR*pData)
{
   L_TCHAR s[500];
   wsprintf(s, TEXT("Key = %d, Type = %s, Count = %d"), uTag,
   uType == TAG_ASCII ? TEXT("ASCII") : (uType == TAG_SHORT ? TEXT("SHORT") : TEXT("DOUBLE")),uCount);
   MessageBox(NULL, s, TEXT("Key Info"), MB_OK);
   /* LEADTOOLS makes the string null-terminated, so it is OK to pass it to MessageBox. Note
   that for Unicode builds you will need to convert this array of bytes to array of WCHAR*/
   if(uType == TAG_ASCII)
      MessageBox(NULL, (LPSTR)pData, TEXT("Key Value"), MB_OK);
   else
   {
      if(uType == TAG_SHORT)
      {
         if(uCount == 1)
            wsprintf(s, TEXT("%d"), *(L_UINT16 L_FAR*)pData);
         else
            wsprintf(s, TEXT("{%d, ...}"), *(L_UINT16 L_FAR*)pData);
      }
      else
      {
         if(uCount == 1)
            sprintf(s, TEXT("%g"), *(L_DOUBLE L_FAR*)pData);
         else
            sprintf(s, TEXT("{%g, ...}"), *(L_DOUBLE L_FAR*)pData);
      }
      MessageBox(NULL, s, TEXT("Key Value"), MB_OK);
   }
}

#define FILENAME "C:\\GeoTIFF.tif"
/* This example sets the GTModelTypeGeoKey key (1024), writes it to an existing file and reads the key back */
L_VOID WriteGeoKeyExample(LFile& file)
{
   /* This example sets the GTModelTypeGeoKey key,
   saves a GeoTIFF file and reads the key back */
   L_VOID L_FAR*pData;
   L_INT nRet;
   L_UINT uType;
   L_UINT uCount;
   L_INT nSize;
   L_UINT16 uProjectCoordinationSystem = 95;

   file.SetFileName(TEXT(FILENAME));

   // set the GTModelTypeGeoKey key
   nRet = file.SetGeoKey(1024, TAG_SHORT, 1, &uProjectCoordinationSystem);

   // write the GeoKey to an existing file
   nRet = file.WriteGeoKey(NULL);

   if(nRet == SUCCESS)
   {
      nSize = file.ReadGeoKey(1024, &uType, &uCount, NULL, NULL);
      if(nSize > 0)
      {
         pData = malloc(nSize);
         if(pData != NULL)
         {
            /* read the GeoKey */
            nRet = file.ReadGeoKey(1024, &uType, &uCount, pData, NULL);
            DisplayKey(1024, uType, uCount, pData);
            free(pData);
         }
      }
   }
   return ;
}