-
Notifications
You must be signed in to change notification settings - Fork 0
/
latitude_grid.cpp
37 lines (28 loc) · 978 Bytes
/
latitude_grid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include "gdal_priv.h"
using namespace std;
int main(void)
{
GDALAllRegister();
const char *pszFormat = "GTiff";
GDALDriver *driver = GetGDALDriverManager()->GetDriverByName(pszFormat);
GDALDataset *dataset = (GDALDataset *)GDALOpen("./model.tif", GA_Update);
GDALRasterBand *rasterband = dataset->GetRasterBand(1);
int xsize = dataset->GetRasterXSize();
int ysize = dataset->GetRasterYSize();
int *data = new int[xsize * ysize];
rasterband->RasterIO(GF_Read, 0, 0, xsize, ysize, data, xsize, ysize, GDT_Int32, 0, 0);
int basevalue = 2225;
for(int i = 0; i < xsize; i ++)
{
int value = basevalue - i / 1250 * 25;
for(int j = 0; j < ysize; j ++)
{
data[i * xsize + j] = value;
}
}
rasterband->RasterIO(GF_Write, 0, 0, xsize, ysize, data, xsize, ysize, GDT_Int32, 0, 0);
GDALClose((GDALDatasetH)dataset);
delete[] data;
return 0;
}