Is there a way to use srtm Data, Geotiff format, altitude data

Hey there,

i am searching for a way to handle altitude data in openframeworks. This data can for example come from any api like OpenStreetMaps Goggle Elevation Services or the what for me sounds best the Shuttle Radar Topography Mission. From the last you can get data in Geotiff format which is an uncompress tiff format hooked up with additional meta information which gives altitude values from a specific terrain.
Thats how i understand it at this point. Anyone of you worked with any of the named?

I like to point a specific point on a map and then get the altitude of the point to work with it further. Does Openframeworks support Geotiff Images or a different way?

I have recently used a library that could load exif data from a jpeg, including lat, long and altitude. I don’t know though if this works for tiffs as well. If not maybe you could batch convert your images. because the library itself is rather easy to use.

Hey Underdoeg, thanks for the hint. I think its only for jpeg images. But i realised that freeimage which is used by OF also can handle Meta information. I also realized that it isnt done by getting the meta infos. They are quite complex in my view. So I discovered GDAL which can use the meta information in a way I need. I will now try to use it in OF. When I have success I will post an example here! Or maybe someone has experiences with GDAL and GeoTiff?

@rak_multi OpenSceneGraph use Gdal in some project (there is also an addon for OF) but look at Virtual Planet Builder that use masssively the GDAL lib VPB and in the particular look at this part of the code
I hope that this will help you!

Thanks Kalwalt,
I thought about using OSG for my needs. But i am allready there without it. I can now get some Elevation data out of the GeoTiff image. At the moment i am not sure what data this exactly is. I am a bit confused by the different bands the GeoTiff contains. Here is my Code so far:

  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];
    }
}

@rak_multi i think that a band is simply a channel (red, green, blue…) as described in the GDAL API if you want to catch other info (the Lat Long infos for example) you should use other methods probably this:

 const char * GDALDataset::GetProjectionRef	(	void 		 ) 	 

but if you look in the online API you should find what you need. Also i think in th OSG forum you will find more support on this side :wink:
Also will be nice an OF addon for this! something like ofxGDAL…

Read also this tut: http://www.gdal.org/ogr/osr_tutorial.html it will help you!

@kalwalt Yes you are right that bands are the RGB infos. This explains why I am getting integer values and no floats. And thanks for pointing me in the right direction with GDAL. GDAL as an addon would be great. Today I really think I should give OSG a chance since I like to have some more possibilities which OSG seems to have. Drawing a terrain would be awesome even if I only look at it from top.

Hey,

i had a tour through different possibilities for my needs but ended up for the moment at my first approach. I worked me into OpenSceneGraph and the VirtualPlanetBuiilder Extension and also into osgEarth which seems to have some more functions. Really nice libs which i will use in the future.
In the end i realised that the GeoTiff i am using has not the information in it like i needed it. So i searched for other SRTM data and got what i want here: http://srtm.csi.cgiar.org/SELECTION/inputCoord.asp
In this imagery i have an extra band with elevation data i can use. 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];
 }
 }

@rak_multi if you are interested in virtualplanetBuilder and osgEarth you can check my addons ofxVTerrain and

ofxOsgEarth, but not tested in OF 008.1…those was my experiments in previous OF versions…