I am writing my own application to use and present elevation data. So far, I've been easily using the three arc second SRTM data presented in ArcInfo ASCII format. But now I'm looking to use the higher resolution 1/3 arc second data. And I find them downloadable in three formats: arcgrid, gridfloat, and img. No ASCII format.

I looked into the arcgrid format, and it looks utterly opaque and complicated. So here's the question if anyone knows: which of these three would be easiest to code for, to read the elevation data into a C or C++ array in my program. And if anyone has any code snippets to share, I'd love to see them.

  • Have you looked into using gdal with C++? Those using it with python seem to prefer the IMG format. gis.stackexchange.com/questions/71128/… – Kirk Kuykendall Mar 22 '16 at 20:37
  • 2
    ASCII is huge so there's no surprise it's not available. The raw DTED format is ones-complement short integers (easy reading with a quirk). The Grid binaries are false choices (you can't read them), so only IMG is left. – Vince Mar 22 '16 at 20:43
  • DTED wasn't offered as a choice - gridfloat was the other one. Do you know how/where to get these files in DTED? I'd be fine with that. – Joymaker Mar 24 '16 at 17:11

This is very doable using C++. Some example code is below. You just need to use the correct driver. See here for driver formats. "HFA" is the code for the Erdas imagine (.img) format.

GDALDataset *pDS;
GDALDriver *pDriver;
pDriver = GDALGetDriverManager->getDriverByName("Name of you driver here");

//open the raster in read only mode   
pDS = (GDALDataset*) GDALOpen("Filepath here", GA_ReadOnly);

//create the array to hold the read data, I usually read rasters one row at at a time
float *rowData = (float*)CPLMalloc(sizeof(float)*pDS->GetRasterXSize);

//loop through all rows of the raster and read data into the array
for (int i=0; i<pDS->GetRasterYSize)
    pDS->GetRasterBand(1)->RasterIO(GF_Read, 0, i, pDS->GetRasterXSize, 1, rowData, pDS->GetRasterXSize, 1, 0, 0);
    //here's where you can do any operations on the row of data

//free the memory

//close the raster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.