I sure hope someone can give me some advice. I'm modestly experienced with GIS and spatial stuff, but I'm trying to do rasters in C++ for the first time. I've been cobbling experiments together, generally successfully, but have not consistently been able to get a raster read working, and I don't know C++ or GDAL deeply enough to understand what to do.
Code is snapshotted below. Using Windows, Visual Studio 2017. If I enable the 5 lines in the inner loop near the bottom, I get an Exception/Access Violation on the "inDS->GetRasterBand(etc)" statement. If I disable that section, and specifically that line, it runs to completion without problem. Can anyone suggest what I might try? Thanks for helping! ************************* #include "stdafx.h" #include <iostream> #include <gdal.h> #include <gdal_priv.h> #include "cpl_conv.h" using namespace std; int main() { GDALDataset *inDS; GDALAllRegister(); const char *input = "D:/Imagery/CDLClipped.tif"; inDS = (GDALDataset*) GDALOpen(input, GA_ReadOnly); if (inDS == NULL) { cout << "unable to open input" << endl; } int nRows, nCols; double transform[6]; double noData; nRows = inDS->GetRasterBand(1)->GetYSize(); nCols = inDS->GetRasterBand(1)->GetXSize(); noData = inDS->GetRasterBand(1)->GetNoDataValue(); inDS->GetGeoTransform(transform); cout << "nRows, nCols, noData = " << nRows << ", " << nCols << ", " << noData << endl; float *inDSRow = (float*)CPLMalloc(sizeof(float)*nCols); for (int i = 0; i < 5; i++) { inDS->GetRasterBand(1)->RasterIO(GF_Read, 0, i, nCols, 1, inDSRow, nCols, 1, GDT_CFloat32, 0, 0); for (int j = 0; j < 5 ; j++) { cout << inDSRow[j] << endl; } } cin.ignore(); }
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev