L_EnumFileGeoKeys

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_EnumFileGeoKeys(pszFile, uFlags, pfnCallback, pUserData, pLoadOptions)

L_TCHAR L_FAR *pszFile;

/* input file name */

L_UINT uFlags;

/* reserved for future use. */

ENUMGEOKEYSCALLBACK pfnCallback;

/* callback function */

L_VOID L_FAR* pUserData;

/* pointer to more parameters for the callback */

pLOADFILEOPTION pLoadOptions;

/* pointer to optional extended load options */

This function will enumerate all the GeoKeys in a GeoTIFF file.

Parameter

Description

pszFile

Character string containing the name of the file in which to enumerate GeoKeys.

uFlags

Flags parameter reserved for future use. Pass 0.

pfnCallback

Callback function for enumerating each GeoKey. Use the function pointer as the value of this parameter.

L_EnumFileGeoKeys calls this callback function for each tag. The callback function must adhere to the function prototype described in the ENUMGEOKEYSCALLBACK Function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID L_FAR *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

pLoadOptions

Pointer to optional extended load options. Pass NULL to use the default load options.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

For multipage GeoTIFF files, you can enumerate the tags from a particular page. Specify the page number on which to enumerate the keys using the pLoadOptions parameter.

The callback is called for each GeoKey value stored in the three standard GeoTIFF tags (34735, 34736 and 34737). For enumerating the other standard GeoTIFF data stored as separate tags, you can use L_EnumFileTags. Or you can call L_ReadFileTag for each of these tags (since there are not that many of them to warrant the use of L_EnumFileTags).

For more information about GeoKeys tags, refer to Implementing GeoKeys (GeoTIFF tags).

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_WriteFileGeoKey, L_WriteFileMetaData, L_EnumFileGeoKeys, L_SaveFile, L_SaveBitmap, ENUMGEOKEYSCALLBACK

Topics:

Implementing GeoKeys (GeoTIFF tags)

 

Implementing TIFF Comments and Tags

 

Raster Image Functions: Working with GeoKeys

Example

/* This is an efficient way of reading all the GeoKeys in a file */
#define FILENAME "geotiff.tif" /* change this to point to a GeoTIFF file */

L_INT EXT_CALLBACK EnumGeoKeysCallback(L_UINT16 uTag, L_UINT16 uType, L_UINT32 uCount, L_VOID L_FAR*pData, L_VOID L_FAR*pUserData)
{
   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);
   }
   return SUCCESS;
}

L_VOID TestEnumFileGeoKeys(HWND hWnd)
{
   L_INT nRet = L_EnumFileGeoKeys(FILENAME, 0, EnumGeoKeysCallback, NULL, NULL);
   if(nRet != SUCCESS)
      MessageBox(hWnd, "Error enumerating GeoKeys", "ERROR", MB_OK);
   else
      MessageBox(hWnd, "Enumeration SUCCEEDED!", "ERROR", MB_OK);
}