这几天尝试用GDAL读入多波段遥感影像,代码如下:
GDALAllRegister(); //注册文件格式
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
GDALDriver *pDriver;
const char* pInFile = "H:\\Group_code\\testdata\\wh_tiff_sub.tif";
const char* pOutFile = "H:\\Group_code\\result\\wh_test\\wh_temp_20.tif";
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
GDALDriver *pDriver;
const char* pInFile = "H:\\Group_code\\testdata\\wh_tiff_sub.tif";
const char* pOutFile = "H:\\Group_code\\result\\wh_test\\wh_temp_20.tif";
GDALDataset *pDataSet;
GDALDataset *pOutDataSet;
pDataSet = (GDALDataset*)GDALOpen(pInFile, GA_ReadOnly);
if (pDataSet == NULL)
{
printf("文件无法打开!\n");
return 0;
}
GDALDataset *pOutDataSet;
pDataSet = (GDALDataset*)GDALOpen(pInFile, GA_ReadOnly);
if (pDataSet == NULL)
{
printf("文件无法打开!\n");
return 0;
}
GDALDataType Datatype;
int nHeight, nWidth, nBands;
Datatype = pDataSet->GetRasterBand(1)->GetRasterDataType(); //GetRasterBand()是从1开始计数
nWidth = pDataSet->GetRasterXSize();
nHeight = pDataSet->GetRasterYSize();
int nHeight, nWidth, nBands;
Datatype = pDataSet->GetRasterBand(1)->GetRasterDataType(); //GetRasterBand()是从1开始计数
nWidth = pDataSet->GetRasterXSize();
nHeight = pDataSet->GetRasterYSize();