I need to get longitude, latitude and altitude info for each pixel in GeoTiff image. I have installed GDAL in my system. Since I am new to GDAL I don't know how to proceed further.

How can I get the information that I need using GDAL and C++?

2 Answers 2


I'm not sure what you mean by "for each pixel". look at the raster API tutorial: http://gdal.org/gdal_tutorial.html. specifically look at the section "Getting Dataset Information".

do you want to get the information that gets dumped by the gdalinfo tool? that is easy. the gdalinfo tool source code comes-with the source download. just get it and look at it. very easy to understand.

Now I see the "altitude" part. Duh.

The raster (pixels) are numbers which are the altitudes. if you know the pixel row/col, it is relatively easy to get the lat/lon/alt. look at the source for gdallocationinfo. it will show you how to take coordinates and look up the pixel. You'd do the same thing, but you don't need to convert from coordinates to pixel since you're starting with pixel coordinate. then you want to convert the pixel to coordinates in some SRS. look at gdaltransform for that.

Also the tutorials. The raster API tutorial (http://gdal.org/gdal_tutorial.html) will show you how to open the tif and read the altitude. Then you use the inverse of the geo transform to convert the pixel row/col to the coordinates in the TIF's SRS. The tutorial will also show you how to get the SRS for the tif.

The TIF SRS may not be geodetic coordinates, or not in the datum you wish. If that is the case, the OGR tutorial (http://gdal.org/gdal_tutorial.html) will show you how to convert coordinates from the TIF's SRS to the one you want (e.g. WGS84).

I cannot stress enough that the tutorials and source code for the GDAL raster utilities are your friend. All that you're asking to do has been implemented in those utilities, which are simple and very well written.


  • Actually I need to get longitude and latitude information from GeoTiff Image.
    – SUD2193
    Dec 7, 2016 at 14:02
  • You mean the extent? the coverage of the GeoTiff?? Look at gdalinfo. or, using the page to which I pointed you, get the transform and reverse it. put in (0,0) and (width-1,height-1) to translate back from pixel to geo. be aware that the transform will take you back to the SRS that the GeoTiff uses. So if the tiff is transverse mercator, you'll get a projected coordinate. also, gdalinfo code will show you how to get the extent, and also how to convert SRS.
    – Reilly
    Dec 7, 2016 at 14:23
  • Some people launch gdalinfo from their C program and then parse the output. Yuck. but you can do that too.
    – Reilly
    Dec 7, 2016 at 14:24
  • "need to get lon and lat info from GeoTiff". the raster doesn't contain the lat/lon. the raster is a 2D array of values, where each (in this case) is an altitude. you use array indices to get the alt. you use the TIF's inverse geo transform to convert the row/col array index to coordinates in the TIF's SRS. Then you can use OGR to convert from one SRS to another, because I've typically seen TIF SRSes as Transverse Mercator, and you mostly want geo coordinates.
    – Reilly
    Dec 9, 2016 at 11:50
  • Links are broken in answer above. You need gdal.org/tutorials/raster_api_tut.html Apr 28, 2020 at 13:28

Because you speak of altitude, I assume your GeoTIFF is an image of a Digital Elevation Model, where each pixel value is the elevation at that point.

gdallocationinfo is a command line tool you could use.

See http://www.gdal.org/gdallocationinfo.html .

The source code of that is here: https://svn.osgeo.org/gdal/trunk/gdal/apps/gdallocationinfo.cpp . You can probably lift something from there if you want pure C++. Otherwise, call gdallocationinfo in a shell loop.

  • He wants the lat/lon extents of the file. gdallocationinfo will look up the raster value of a specific point. That's not what he wants. gdalinfo will show what he's asking.
    – Reilly
    Dec 7, 2016 at 15:42
  • I'm not sure he wants the extents. Its not really clear what he wants to me. But yeah, if he wants extents you are right!
    – til_b
    Dec 7, 2016 at 20:02
  • I'm pretty sure that he doesn't want the extents. He wants to convert the raster into a giant point dataset.
    – mkennedy
    Dec 7, 2016 at 20:36
  • yeah I don't to load gdalinfo. If I give specific pixel value I need to display corresponding longitude and latitude information for that value.
    – SUD2193
    Dec 8, 2016 at 7:05
  • So you want the lat/lon of (for example) the pixel at (273,472)? And not the raster value (==altitude) of that pixel? (Because you speak of altitude, I assumed your GeoTIFF is a Digital Elevation Model.)
    – til_b
    Dec 8, 2016 at 8:20

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.