Error in write tiff from grid data with GDAL

0

I'm trying to transform a set of points (defined as vectors) to a tif. I found a code to create a grid but I do not know how to save the grid as tif on disk. I use GDALGrid but the following error appears:

Exception thrown at 0x00007FF845FF6BAF (gdal202.dll) in Prueba open.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

GDALAllRegister();
int nWidth = 1981;
int nHeight = 1842;
double *pGridData = new double[nWidth*nHeight];
memset(pGridData, 0, sizeof(double)*nWidth*nHeight);

// Vector data
double dfX[] = {3646.4312434374951,3165.9293659374962,3198.8404534375004,2323.4055259374945,2112.7745659374996,2876.3117959374940,2112.7745659374996,2112.7745659374996,3646.4312434374951,3646.4312434374951};
double dfY[] = {2429.1661706250161,2889.9213956250169,3929.9117606249929,3311.1833156249777,2343.5973431250022,1981.5753806249995,1981.5753806249995,3929.9117606249929,1981.5753806249995,3929.9117606249929};
double dfZ[] = {26.009000778198242,70.081001281738281,81.489997863769531,91.760002136230469,227.47500610351562,44.508998870849609,73.625880031847814,435.36212516732496,195.52794381616283,59.967212370570905};


std::vector<double> padfX(dfX, dfX + 10);
std::vector<double> padfY(dfY, dfY + 10);
std::vector<double> padfZ(dfZ, dfZ + 10);

std::vector<double>::iterator it = std::min_element(padfX.begin(), padfX.end());
double  dfXMin = *it;
it = std::max_element(padfX.begin(), padfX.end());
double  dfXMax = *it;
it = std::min_element(padfY.begin(), padfY.end());
double  dfYMin = *it;
it = std::max_element(padfY.begin(), padfY.end());
double  dfYMax = *it;

// Create Grid
memset(pGridData, 0, sizeof(double)*nWidth*nHeight);

GDALGridLinearOptions  *poOptions = new GDALGridLinearOptions();
poOptions->dfNoDataValue = 0;
poOptions->dfRadius = 0;


GDALGridCreate(GGA_Linear, poOptions, padfX.size(), &(padfX[0]), &(padfY[0]), &(padfZ[0]), \
dfXMin, dfXMax, dfYMin, dfYMax, nWidth, nHeight, GDT_Float64, pGridData, NULL, NULL);

// Save Grid
char *tiffFile = "test.tif";
GDALGrid(tiffFile, pGridData, NULL, NULL);
c++
visual-studio-2015
gdal
point-clouds
asked on Stack Overflow Sep 23, 2019 by jbalado • edited Sep 23, 2019 by GBouffard

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0