Last active
July 28, 2017 10:58
-
-
Save talaj/ceeef8d3e3236e79f3904483e0d93ac8 to your computer and use it in GitHub Desktop.
gdal-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <iostream> | |
#include <gdal/gdal_priv.h> | |
main() | |
{ | |
GDALAllRegister(); | |
const char * dem = "/home/talaj/dev/gdal-leak/world_aster2_srtmgl1_gmerc_38m_dfs40a.tif"; | |
auto ds = GDALOpen(dem, GA_ReadOnly); | |
std::unique_ptr<GDALDataset, decltype(&GDALClose)> dataset( | |
static_cast<GDALDataset*>(ds), &GDALClose); | |
auto bands = dataset->GetRasterCount(); | |
auto width = dataset->GetRasterXSize(); | |
auto height = dataset->GetRasterYSize(); | |
std::clog << "B: " << bands << " W: " << width << " H: " << height << std::endl; | |
unsigned tile_w = 1000, tile_h = 1000; | |
std::unique_ptr<unsigned char []> buff(new unsigned char[tile_w * tile_h]); | |
GDALRasterBand * band1 = dataset->GetRasterBand(1); | |
GDALRasterBand * band2 = dataset->GetRasterBand(2); | |
unsigned div = 10000; | |
for (unsigned i = 0; i < div; i += 100) | |
{ | |
for (unsigned j = 0; j < div; j += 100) | |
{ | |
unsigned x_off = (width / div) * j; | |
unsigned y_off = (height / div) * i; | |
CPLErr raster_io_error = band1->RasterIO( | |
GF_Read, x_off, y_off, tile_w, tile_h, | |
buff.get(), tile_w, tile_h, | |
GDT_Byte, 0, 0); | |
raster_io_error = band2->RasterIO( | |
GF_Read, x_off, y_off, tile_w, tile_h, | |
buff.get(), tile_w, tile_h, | |
GDT_Byte, 0, 0); | |
//break; | |
} | |
//break; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment