EnumGeoKeys Example for Visual C++
/* This is an efficient way of reading all the GeoKeys in a file */
ILEADRasterIO * pRasterIO = NULL;
void TestEnumFileGeoKeys()
{
short nRet = pRasterIO->EnumFileGeoKeys (TEXT("GeoTif.tif"), 0, 0);
if (nRet == 0)
MessageBox(NULL, TEXT("Enumeration SUCCEEDED!"), TEXT("Notice"), MB_OK);
else
MessageBox(NULL, TEXT("Error enumerating GeoKeys"), TEXT("Error"), MB_OK);
}
void OnEnumGeoKeys(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 Info"), MB_OK);
pRasterIO->get_GeoKeyData (&pData);
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);
pRasterIO->StopFireEnumGeoKeys = FALSE;
}