经过一天的学习,终于对gdal库有所了解,下面是利用GDAL读取TIFF文件程序。
void CTestView::OnFileOpen()
{
// TODO: Add your command handler code here
char szFilter[] = "GeoTiff (*.tif)|*.tif|All Files (*.*)|*.*||";
CString filePath("");
CFileDialog fileOpenDlg(TRUE, "tif", NULL,OFN_HIDEREADONLY,szFilter);
if (fileOpenDlg.DoModal() == IDOK)
{
VERIFY(filePath = fileOpenDlg.GetPathName());
}
CString strFilePath(filePath);
GDALDataset *poDataset; //GDAL数据集
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen(strFilePath, GA_ReadOnly );
if( poDataset == NULL )
{
AfxMessageBox("文件打开