Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.24
LEADTOOLS Raster imaging C++ Class library help

LFile::WriteGeoKey

Show in webframe

#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.

Platforms

Win32, x64.

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

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
/* 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 MAKE_IMAGE_PATH(TEXT("clean.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(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)
   {
      // Call the ReadGeoKey function first time to determine the required size of the buffer 
      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);
            if(nRet < 1)
               return nRet;
            DisplayKey(1024, (L_UINT16) uType, uCount, pData);
            free(pData);
         }
      }
      else 
         return nSize;
   }
   return SUCCESS;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.