17 m_gtif_driver = GetGDALDriverManager()->GetDriverByName(
"GTiff");
24 m_gtif_dataset = (GDALDataset *) GDALOpen(filename.c_str(), GA_ReadOnly);
31 std::cout <<
timestamp <<
"GeoTIFF dataset not initialized!" << std::endl;
35 uint16_t *rowBuff = (uint16_t *) CPLMalloc(
sizeof(uint16_t) *
m_cols);
36 for (
int row = 0; row <
m_rows; row++)
38 for (
int col = 0; col <
m_cols; col++)
40 rowBuff[col] = mat->at<uint16_t>(row, col);
43 GF_Write, 0, row, m_cols, 1, rowBuff, m_cols, 1, GDT_UInt16, 0, 0) != CPLE_None)
45 std::cout <<
timestamp <<
"An error occurred in GDAL while writing band " 46 << band <<
" in row " << row <<
"." << std::endl;
93 int nXSize = band->GetXSize();
94 int nYSize = band->GetYSize();
95 uint16_t *buf = (uint16_t *) CPLMalloc(
sizeof(uint16_t) * nXSize * nYSize);
97 CPLErr
error = band->RasterIO(GF_Read, 0, 0, nXSize, nYSize, buf, nXSize, nYSize, GDT_UInt16, 0, 0);
99 cv::Mat *mat =
new cv::Mat(nXSize, nYSize, CV_16UC1, buf);
105 std::cout <<
timestamp <<
"Error getting raster band" << std::endl;
114 GDALDestroyDriverManager();
static Timestamp timestamp
A global time stamp object for program runtime measurement.
GDALDataset * m_gtif_dataset
GeoTIFFIO(std::string filename, int cols, int rows, int bands)
GDALDriver * m_gtif_driver
int writeBand(cv::Mat *mat, int band)
Writing given band into open GeoTIFF file.
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
Error handler. All GPU functions from this subsystem call the function to report an error...
cv::Mat * readBand(int band_index)