LFile::WriteGeoKey

#include "ltwrappr.h"

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.

Some restrictions apply to this function if you use an IFD to indicate to which page to write the geokey. See the Loading and Saving Large TIFF Files topic for more information.

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::Save, 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 *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, (LPCWSTR)pData, TEXT("Key Value"), MB_OK); 
   else 
   {
      if(uType == TAG_SHORT) 
      {
         if(uCount == 1) 
            wsprintf(s, TEXT("%d"), *(L_UINT16 *)pData); 
         else 
            wsprintf(s, TEXT("{%d, ...}"), *(L_UINT16 *)pData); 
      }
      else
      {
         if(uCount == 1) 
            wsprintf(s, TEXT("%g"), *(L_DOUBLE *)pData); 
         else
            wsprintf(s, TEXT("{%g, ...}"), *(L_DOUBLE *)pData); 
      }
      MessageBox(NULL, s, TEXT("Key Value"), MB_OK); 
   }
}
#define FILENAME "%UserProfile%\\My Documents\\LEADTOOLS Images\\GeoTIFF.tif"
/* This example sets the GTModelTypeGeoKey key (1024), writes it to an existing file and reads the key back */
L_INT LFile__WriteGeoKeyExample(LFile& file)
{
   L_INT nRet;
   /* This example sets the GTModelTypeGeoKey key, 
   saves a GeoTIFF file and reads the key back */
   L_VOID *pData;
   L_UINT uType;
   L_UINT uCount;
   L_INT nSize = 0;
   L_UINT16 uProjectCoordinationSystem = 95;
   file.SetFileName(TEXT(FILENAME));
   // set the GTModelTypeGeoKey key
   nRet = file.SetGeoKey(1024, TAG_SHORT, 1, &uProjectCoordinationSystem);
   if(nRet != SUCCESS)
      return nRet;
   // write the GeoKey to an existing file 
   nRet = file.WriteGeoKey(NULL);
   if(nRet != SUCCESS)
      return nRet;
   if(nRet == SUCCESS)
   {
      nRet = file.ReadGeoKey(1024, &uType, &uCount, NULL, NULL);
      if(nRet != SUCCESS)
         return nRet;
      if(nSize > 0)
      {
         pData = malloc(nSize);
         if(pData != NULL)
         {
            /* read the GeoKey */
            nRet = file.ReadGeoKey(1024, &uType, &uCount, pData, NULL);
            if(nRet != SUCCESS)
               return nRet;
            DisplayKey(1024, (L_UINT16) uType, uCount, pData);
            free(pData);
         }
      }
   }
   return SUCCESS;
}