my problem is apparently quite simple, but I cannot really find an easy answer: in QGIS I've created a raster layer by merging different GeoTiff images from the ASTER 30m DEM dataset.

The merging is ok: by moving the cursor I can see that the coordinates make sense and so the elevation.

What I'd like now is to extract the longitude and latitude informations from each pixel (generating a matrix the size of the layer with Lat values and one with Lon values), but I really don't know how to do it.

I also tried to import the image in MATLAB using the geotiffread function, but I cannot extract such information...

Thanks to all!

1 Answer 1


I suggest not to create such a matrix, which could be quite inefficient, but if you really need this, you create an ascii file with Long, lat, and value as columns, (which you can import in Matlab.)

gdal_translate -of XYZ input.tif output.asc

gdal is also available from qgis as a plugin (with a GUI), but you can use it directly as a command line.

Note that you can find your coordinates directly based on the row and column number. The easiest case is a starting from a matrix that is already in long/lat, in other words a regular grid in Lat/long coordinate system.

so you need to extract the upper left corner coordiantes, and the lat/long can be computed based on the index of you element

lat = upperLeftLat - Ysize*row

long = upperLeftLong + XSize*column

If you are not in this ideal case, you need to account for the rotation of the matrix and, potentially, the projection. But this can also be done "on the fly" without creating a new matrix (although if you need to reproject your data, it is better to do it first).

  • Hi radouxju and thanks for the answer! The data should be already on a non-rotated non projected matrix (EPSG:4326 - WGS84). I would need the matrix because I need to do external calculations and I explicitly need in clear all the lat-lon-elevation values. I'm not very familiar with QGIS, how should I do to run that command? From the OSGEOW shell?
    – Mutewinter
    Commented Apr 15, 2014 at 14:06
  • from the osgeo shell you can launch gdal_translate command directly if gdal has been installed with OSGEO4W. I mentioned the QGIS plugin because you used the QGIS tag
    – radouxju
    Commented Apr 15, 2014 at 14:15
  • Yes, I'm working in QGIS, but I'm still incredibly noob. You were right, though, the ascii file was bigger than 5 GB and impossible to handle. I still can probably CREATE a simple Lat-Lon matrix (for example in MATLAB): i could initialize a matrix of zeroes and then make a nested loop over rows and column and go like lat(m,n)=upperLeftLat - Ysize*m. But just to be clear, this meanst that, for example for latitude, I will have identical columns?
    – Mutewinter
    Commented Apr 15, 2014 at 14:24
  • Well, all the columns at the same row will have the same latitude. That's why it is not efficient to store. Are you sure that you can't use the row and column indices directly in you matlab code to have the lat/long ?
    – radouxju
    Commented Apr 15, 2014 at 14:45
  • Actually, yes! Thanks to your suggestion that's exactly what I did: using the corner information I've created a column vector as big as the y dimension of the geotiff with one latitude value per each row as well as a row vector as big as the x dimension of the geotiff with one longitude value per column. Then I tiled those with repmat obtaining two matrices the size of the tiff: one for longitude (with identical rows) and one for latitude (with identical columns).
    – Mutewinter
    Commented Apr 16, 2014 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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