#include// Open the output driver for writing GDALDriver* pDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); GDALDataset* pDataset = pDriver->Create("output.tif", 512, 512, 1, GDT_Byte, NULL); // Do some processing... // Close and cleanup the dataset GDALClose(pDataset);
#includeIn this example, we are opening an existing GeoTIFF dataset named "input.tif" in read-only mode. We also show how to check for errors and release the opened dataset. The GDALDriver class is part of the GDAL C++ API library, which is included as part of the GDAL package.#include int main() { GDALAllRegister(); // Open the input dataset for reading GDALDataset* pDataset = (GDALDataset*)GDALOpen("input.tif", GA_ReadOnly); if (pDataset == NULL) { std::cerr << "Error: unable to open input dataset" << std::endl; return 1; } // Do some processing... // Close and cleanup the dataset GDALClose(pDataset); return 0; }