1

I am understanding English not so well and I am not the best C++ Programmer so I decided to ask a question here to compensate this.

I am trying to get the elevation out of an GeoTiff image I downloaded from this page: http://terracolor.net/sample_imagery.html

I get some information out of the Image via GDAL lib but I am not sure what this exactly is. Is it the colour? Are this coordinates? What unity is that? I am also confused by the different bands I can read in. Maybe someone who used GDAL in the past can explain me what this is all about. What I like to have in the end is the altitude in for example meters at a given Pixel.

Here is my Code:

int ofApp::getAlt(int x,int y){ 
GDALDataset  *poDataset;

GDALAllRegister();

poDataset = (GDALDataset *) GDALOpen( "data/test.tif", GA_ReadOnly );
if( poDataset == NULL )
{
    cout << "no" << endl;
}else{
    GDALRasterBand  *poBand;
    int             nBlockXSize, nBlockYSize;
    int             bGotMin, bGotMax;
    double          adfMinMax[2];

    //printf( "Size is %dx%dx%d\n", poDataset->GetRasterXSize(), poDataset->GetRasterYSize(), poDataset->GetRasterCount() );

    poBand = poDataset->GetRasterBand( 3 );
    poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );

    adfMinMax[0] = poBand->GetMinimum( &bGotMin );
    adfMinMax[1] = poBand->GetMaximum( &bGotMax );
    if( ! (bGotMin && bGotMax) )
        GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);

    float *pafScanline;
    int   nXSize = poBand->GetXSize();

    pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);
    poBand->RasterIO( GF_Read, x, y, 1, 1, 
                      pafScanline, nXSize, 1, GDT_Float32, 
                      0, 0 );

    //cout << "vvv" << pafScanline[0] << endl;
    //printf( "value %f \n", pafScanline[0]);
    return pafScanline[0];
 }
 }
mixed_farmer
  • 85
  • 2
  • 7

2 Answers2

0

These GeoTIFF files provided by Terracolor seem to contain color information, not elevation. The files have pixel colors in RGB space, there are three bands (1: red, 2: green, 3: blue). You can process the GeoTIFF files with code similar to your example, but you'll need to read in the three bands. The data type is Byte, not GDT_Float32. Before processing them with GDAL I would suggest to check with the data provider or to open some of these raster layers with a GIS software (like QGIS). The .tif files seem to come with metadata in .txt files.

fedemp
  • 210
  • 1
  • 4
0

You are right. What simple mistake. These imagery i used had no such elevation data as a band in in it. I now used images from http://srtm.csi.cgiar.org/SELECTION/inputCoord.asp which serve the needed data with in a band how I needed it. I can then use my function to read it out.

mixed_farmer
  • 85
  • 2
  • 7