L_WriteFileGeoKey

#include "l_bitmap.h"

L_LTFIL_API L_INT L_WriteFileGeoKey(pszFile, pSaveOptions)

L_TCHAR* 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.

Some restrictions apply to this function if you use an IFD to indicate to which page to write the GeoKeys. 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.

Platforms

Win32, x64.

See Also

Functions:

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

Topics:

Implementing GeoKeys (GeoTIFF tags)

 

Implementing TIFF Comments and Tags

 

Raster Image Functions: Working with GeoKeys

Example

#define FILENAME MAKE_IMAGE_PATH(TEXT("GeoTIFF.tif"))

/* Displays a GeoKey */
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);

   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, (LPTSTR)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);
   }
}

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

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

   // set the GTModelTypeGeoKey key
   nRet = L_SetGeoKey(1024, TAG_SHORT, 1, &uProjectCoordinationSystem);
   if(nRet != SUCCESS)
      return nRet;

   // 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);
            if(nRet < SUCCESS)
               return nRet;
            DisplayKey(1024, (L_UINT16)uType, uCount, pData);
            free(pData);
         }
      }
      else
         return nSize;
   }
   return SUCCESS;
}