#include <gdal_priv.h>
#include <ctime>
using namespace std;
int main()
{
GDALAllRegister();
GDALDataset * ds;
ds = (GDALDataset *)GDALOpen("template.tif", GDALAccess::GA_Update);
GDALRasterBand * band = ds->GetRasterBand(1);
int xSize, ySize,N;
xSize = band->GetXSize();
ySize = band->GetYSize();
N = xSize * ySize;
int * pData = new int[N];
srand((unsigned)time(NULL));
for (int i = 0;i < N;i++)
{
pData[i] = rand() % 7;
}
band->RasterIO(GF_Write, 0, 0, xSize, ySize, pData, xSize, ySize, GDT_Int32, 0, 0, NULL);
printf("%s\n", "数据重写完成");
GDALClose(ds);
delete [] pData;
system("pause");
return 0;
}
GDAL读取栅格数据并修改
最新推荐文章于 2023-09-16 23:12:50 发布