WriteGeoKey Example for Visual C++
/* Displays a GeoKey */
void DisplayKey(long uTag, long uType, long uCount, ILEADRasterVariant * pData)
{
CString csBuffer;
csBuffer.Format(TEXT("Key = %d\nType %s\nCount = %d\n"), uTag, (uType == TAG_ASCII) ? TEXT("ASCII") : (uType == TAG_SHORT) ? TEXT("SHORT") : TEXT("DOUBLE"), uCount);
MessageBox(NULL, csBuffer, TEXT("Key Data"), MB_OK);
if (uType == TAG_SHORT)
{
if (uCount == 1)
csBuffer.Format(TEXT("Key Value = %d"), pData->ShortValue);
else
csBuffer.Format(TEXT("Key Value = %d"), pData->ShortItemValue [0]);
}
else
{
if (uType == TAG_DOUBLE)
if (uCount == 1)
csBuffer.Format(TEXT("Key Value = %d"), pData->DoubleValue);
else
csBuffer.Format(TEXT("Key Value = %d"), pData->DoubleItemValue [0]);
}
MessageBox(NULL, csBuffer, TEXT("Data"), MB_OK);
}
/* This example sets the GTModelTypeGeoKey key (1024), writes it to an existing file and reads the key back */
ILEADRasterVariant * pRasVar = NULL;
void TestReadFileGeoKey(ILEADRasterIO * pRasterIO)
{
pRasVar->Type = VALUE_SHORT;
pRasVar->ShortValue = 1;
pRasterIO->put_GeoKeyType (TAG_SHORT);
pRasterIO->put_GeoKeyCount (1);
pRasterIO->put_GeoKeyData (pRasVar);
// set the GTModelTypeGeoKey key
pRasterIO->SetGeoKey (1024);
// write the GeoKey to an existing file
short nRet = pRasterIO->WriteFileGeoKey (TEXT("GeoTIFF.tif"), 0, SAVE_OVERWRITE);
if (nRet == 0)
{
nRet = pRasterIO->ReadFileGeoKey (TEXT("GeoTIFF.tif"), 1024);
if (nRet == 0)
{
long uType, uCount;
pRasterIO->get_GeoKeyType (&uType);
pRasterIO->get_GeoKeyCount (&uCount);
pRasterIO->get_GeoKeyData (&pRasVar);
DisplayKey(1024, uType, uCount, pRasVar);
}
}
}