I needed lat/long of each pixel of a GeoTiff file. I searched through internet to find a solution and ,thanks to Stack Overflow, found a piece of code that I modified. As usual, python and gdal were used. Just follow the instructions below.
First get the number of rows and columns of you image by using gdalinfo (although it can be automated as well but lets just go with it)
Now edit the python code below and set rows and columns according to your image (don’t forget to change the image name).
from osgeo import gdal # Open tif file ds = gdal.Open('raster.tif') # GDAL affine transform parameters, According to gdal documentation xoff/yoff are image left corner, a/e are pixel wight/height and b/d is rotation and is zero if image is north up. xoff, a, b, yoff, d, e = ds.GetGeoTransform() def pixel2coord(x, y): """Returns global coordinates from pixel x, y coords""" xp = a * x + b * y + xoff yp = d * x + e * y + yoff return(xp, yp) # get columns and rows of your image from gdalinfo rows = 36+1 colms = 34+1 if __name__ == "__main__": for row in range(0,rows): for col in range(0,colms): print pixel2coord(col,row)
Finally, execute this python script using following command (provided that you have named your file script.py)
Here is the output of my raster.tif
In my case, I converted output to csv and opened it in qGIS along with raster.tif (shown below).
and a closer look