L_WriteFileGeoKey

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_WriteFileGeoKey(pszFile, pSaveOptions)

L_TCHAR L_FAR * pszFile;

/* file name */

pSAVEFILEOPTION pSaveOptions;

/* pointer to optional extended save options */

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

Parameter

Description

pszFile

Character string that contains the filename in which to write the GeoKeys.

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 L_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 L_WriteFileMetaData 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.

Platforms

Windows 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

L_SetGeoKey, L_GetGeoKey, L_ReadFileGeoKey, L_EnumFileGeoKeys, L_SaveFile, L_SaveBitmap, L_WriteFileMetaData

Topics:

Implementing GeoKeys (GeoTIFF tags)

 

Implementing TIFF Comments and Tags

 

Raster Image Functions: Working with GeoKeys

Example

#define FILENAME "e:\\i\\GeoTIFF\\GeoTIFF.tif"
/* Displays a GeoKey */
static L_VOID DisplayKey(L_UINT16 uTag, L_UINT16 uType, L_UINT32 uCount, L_VOID L_FAR*pData)
{
   L_TCHAR s[500];

   wsprintf(s, "Key = %d, Type = %s, Count = %d", uTag, uType == TAG_ASCII ? "ASCII" : (uType == TAG_SHORT ? "SHORT" : "DOUBLE"), uCount);
   MessageBox(NULL, s, "Key Info", MB_OK);

   if(uType == TAG_ASCII)
   {
      /* 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
      */
      MessageBox(NULL, (LPSTR)pData, "Key Value", MB_OK);
   }
   else 
   {
      if(uType == TAG_SHORT)
         if(uCount == 1)
            wsprintf(s, "%d", *(L_UINT16 L_FAR*)pData);
         else
            wsprintf(s, "{%d, ...}", *(L_UINT16 L_FAR*)pData);
      else
         if(uCount == 1)
            sprintf(s, "%g", *(L_DOUBLE L_FAR*)pData);
         else
            sprintf(s, "{%g, ...}", *(L_DOUBLE L_FAR*)pData);
      MessageBox(NULL, s, "Key Value", MB_OK);
   }
}

/* This example sets the GTModelTypeGeoKey key (1024), writes it to an existing file and reads the key back */
L_INT TestReadFileGeoKey(HWND hWnd)
{
   L_INT    nRet;
   L_UINT16 uProjectCoordinationSystem = 1;

   L_UINT   uType;
   L_UINT   uCount;
   L_INT    nSize;
   L_VOID L_FAR*pData;

   // set the GTModelTypeGeoKey key
   L_SetGeoKey(1024, TAG_SHORT, 1, &uProjectCoordinationSystem);

   // write the GeoKey to an existing file 
   nRet = L_WriteFileGeoKey(FILENAME, NULL);
   if(nRet == SUCCESS)
   {
      nSize = L_ReadFileGeoKey(FILENAME, 1024, &uType, &uCount, NULL, NULL);
      if(nSize > 0)
      {
         pData = malloc(nSize);
         if(pData != NULL)
         {
            /* read the GeoKey */
            nRet = L_ReadFileGeoKey(FILENAME, 1024, &uType, &uCount, pData, NULL);
            DisplayKey(1024, uType, uCount, pData);
            free(pData);
         }
      }
   }

   return nRet;
}