当前位置: 代码迷 >> GIS >> GDAL中怎么把处理好的多个波段数据写到一个tif文件中去啊
  详细解决方案

GDAL中怎么把处理好的多个波段数据写到一个tif文件中去啊

热度:448   发布时间:2016-05-05 06:40:31.0
GDAL中如何把处理好的多个波段数据写到一个tif文件中去啊?
GDAL中的create方法好像要自己往里写参数,如何获取源图像的参数并写入呢?
因为我只对tiff文件中的象素做处理,不处理那些参数。

------解决方案--------------------
倒!你真懒,
和读取是差不多的,就是把GF_Read改成GF_Write就差不多了
我这一阵心情不错,给你个例子吧。

建议你还是系统的看看GDAL的官方说明及示例。
C/C++ code
//第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([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock1,xSize,ySize,GDT_Byte,0,0);            poDstDS->GetRasterBand(2)->RasterIO([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock2,xSize,ySize,GDT_Byte,0,0);            poDstDS->GetRasterBand(3)->RasterIO([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock3,xSize,ySize,GDT_Byte,0,0);