GDAL常用函数及示例

GDAL常用函数应用及示例

本文主要介绍:GDAL常用函数的应用,其中包含图像数据的读取、写入,地理坐标与行列坐标的相互转化,颜色表的读取和设置。

一、图像的读取与写入

	//初始化GDAL库注册表
	GDALAllRegister();
	CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");

	//打开图像
	CString inPath("C:\\Users\\Administrator\\Desktop\\GF1.tif");
	GDALDataset * pInDataset = (GDALDataset * )GDALOpen(inPath,GA_ReadOnly);
	if(pInDataset==NULL)
	{
		AfxMessageBox("读取图像失败!");
		return FALSE;
	}

	int Width = pInDataset->GetRasterXSize(); //获取图像宽
	int Height = pInDataset->GetRasterYSize(); //获取图像高
	int Count = pInDataset->GetRasterCount(); //波段数

	//读取数据
	GDALRasterBand  *pInRasterBand = pInDataset->GetRasterBand(1);
	float *inBuf;
	inBuf = new float[Width*Height];
	ZeroMemory(inBuf,sizeof(float)*Width*Height);
	CPLErr err;
	err=pInRasterBand->RasterIO(GF_Read,0,0,Width,Height,inBuf,Width,Height,GDT_Float32,0,0);
				
	if(err==CE_Failure)
	{
		AfxMessageBox("读取输入图像数据失败!");
		return FALSE;
	}



	//创建输出图像、写图像
	CString outPath("C:\\Users\\Administrator\\Desktop\\GF1000.tif");
	GDALDriver *poDriver =GetGDALDriverManager()->GetDriverByName("GTiff");
	if( poDriver==NULL)
	{
		AfxMessageBox("获取创建输出图像指针poDriver失败!");
		return FALSE;
	}
	
	CString OutFilename = CString(outPath);
	Ou
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值