Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to a store GeoTIFF file pixel by pixel in the database. I need to store pixel values along with the lat/lon of that pixel on the GeoTIFF image. Is it possible to do that?

share|improve this question
Is the goal to be able to query by Lat/Lon? You could accomplish this with GDAL using the geotransform attribute - I can provide a python example. The conversion could be pre-rendered into a 2 band geotiff (Band1 - LAT, Band2 - LON), but I wonder if it wouldn't be more efficient to do this on the fly. I guess a use case would help. – Jay Laura Mar 6 '13 at 15:54

In a generic sense, use the affine transform parameters, which should be available with any raster file format. With GDAL, this is available with GetGeoTransform(), or PostGIS' ST_GeoReference() function. After finding these six parameters, one only needs to determine which ones they are, then a function can be made to transform in linear space.

E.g., with Python:

from osgeo import gdal
ds = gdal.Open('myfile.tif')

# unravel GDAL affine transform parameters
c, a, b, f, d, e = ds.GetGeoTransform()

def pixel2coord(col, row):
    """Returns global coordinates to pixel center using base-0 raster index"""
    xp = a * col + b * row + a * 0.5 + b * 0.5 + c
    yp = d * col + e * row + d * 0.5 + e * 0.5 + f
    return(xp, yp)

For example, if there is a pixel at col=10, row=22, then the real-world coordinates to the pixel center are:

>>> pixel2coord(10, 22)
(2780000.0, 6162300.0)

Something similar can be cooked up for PostGIS with ST_Affine().

share|improve this answer

This may be a bit archaic: Convert the pixels to points, add lat and long fields, and populate with lat and long values.

share|improve this answer

The world file (.tfw) that accompanies a GeoTIFF contains:

  • pixel size in the x-direction (and y-direction) in map units/pixel and
  • x-coordinate (and y-coordinate) of the center of the upper left pixel. This is all you need to calculate position in Lat/Lon of every pixel.
share|improve this answer
In addition to what you describe, at a minimum you need to know the coordinate system! (A world file does not include such information.) – whuber Mar 6 '13 at 16:32
Also, not every GeoTIFF contains a world file. A true GeoTIFF has the coordinate information stored in the header, not in a separate file. However, the term "GeoTIFF" is often applied to TIFF images with a world file. The point is, there won't always be a TFW. – user3461 May 5 '13 at 22:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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