
GDAL中怎么把处理好的多个波段数据写到一个tif文件中去
1个回答
展开全部
示例
//第1段 读取原来参数
GDALDataset *poDataset;
poDataset = (GDALDataset *)GDALOpen(path,GA_ReadOnly);
int nbandcount=poDataset->GetRasterCount();//波段数目
int imgWidth = poDataset->GetRasterXSize();//文件X方向像素宽度
int imgHeight = poDataset->GetRasterYSize();//Y方向宽度
double tifCoord[6];
poDataset->GetGeoTransform(tifCoord);//地理范围参数
....
//第2段 写文件
GDALDataset *poDstDS;
GDALDriver *poDriver ;
char **papszOptions2 = NULL;
const char *pszFormat = "GTiff";
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
...............此处添加自己的代码,比如设定路径,要建立的文件长度、宽度之类的
poDstDS = poDriver->Create( strFullPath, nPicWidth,nPicWidth,3, GDT_Byte,
&option );
............此处添加代码,获取数据内容
poDstDS->GetRasterBand(1)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock1,xSize,ySize,GDT_Byte,0,0);
poDstDS->GetRasterBand(2)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock2,xSize,ySize,GDT_Byte,0,0);
poDstDS->GetRasterBand(3)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock3,xSize,ySize,GDT_Byte,0,0);
//第1段 读取原来参数
GDALDataset *poDataset;
poDataset = (GDALDataset *)GDALOpen(path,GA_ReadOnly);
int nbandcount=poDataset->GetRasterCount();//波段数目
int imgWidth = poDataset->GetRasterXSize();//文件X方向像素宽度
int imgHeight = poDataset->GetRasterYSize();//Y方向宽度
double tifCoord[6];
poDataset->GetGeoTransform(tifCoord);//地理范围参数
....
//第2段 写文件
GDALDataset *poDstDS;
GDALDriver *poDriver ;
char **papszOptions2 = NULL;
const char *pszFormat = "GTiff";
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
...............此处添加自己的代码,比如设定路径,要建立的文件长度、宽度之类的
poDstDS = poDriver->Create( strFullPath, nPicWidth,nPicWidth,3, GDT_Byte,
&option );
............此处添加代码,获取数据内容
poDstDS->GetRasterBand(1)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock1,xSize,ySize,GDT_Byte,0,0);
poDstDS->GetRasterBand(2)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock2,xSize,ySize,GDT_Byte,0,0);
poDstDS->GetRasterBand(3)->RasterIO(GF_Write,xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock3,xSize,ySize,GDT_Byte,0,0);
本回答被网友采纳

你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询