6

I have a .tif file that contains all the elevation of a country.

How can I convert that to a CSV file that contains x,y,z values where x and y are the latitude longitude respectively and the z column is the elevation using QGIS?

1
  • I think this question, although technically a duplicate, does have merit because it highlights a 'gotcha' in the operation of the QGIS UI. Feb 21, 2014 at 13:19

2 Answers 2

4

Go Raster->Conversion->Translate and then set the output to ASCII XYZ from the drop-down menu when you specify the output file.

An alternative ASCII format you may care to consider is the ESRI ASC format, which is smaller because it only lists the height (Z) and has a header which sets the raster origin and resolution. The Xand Y fields are now superfluous as a raster is a regular grid.

ASCII is a poor way of storing rasters though and you'd be better off with a GeoTif or JPEG.

EDIT: Working around a 'gotcha' in the QGIS translate dialog:
The Translate tool in QGIS has a major 'gotcha'. It doesn't automatically change the output format in the command line parameters, so changing the type in the output file doesn't automatically do anything other than change the extension of the output file name. The actual output encoding remains as the default GTiff. So, you must manually edit the command line parameters. To do this, set up the translation as normal and then click the little yellow pencil at the bottom of the dialog box (1). Then edit the command line so that the -of parameter reads XYZ (in this case) instead of GTiff (2).

enter image description here

5
  • I already tried this but when I viewed the results using a text editor, I got a text file that I don't understand. THe outputs are only numbers and letters probably a machine readable text. I didn't get the xyz columns. Any help? Feb 21, 2014 at 12:01
  • 1
    You've been caught out by a 'gotcha' in the dialog box so your output is actually still encoded as a GeoTiff. Please see my edit to see what to do to coerce it to an XYZ. Feb 21, 2014 at 13:17
  • Thank you very much for the help.. I'll try this.. Sorry I am just a newbie in QGIS Feb 21, 2014 at 13:50
  • You've got to start somewhere! Also, this gotcha, still catches me out - I should probably file it as a bug! Feb 21, 2014 at 14:08
  • I just tried it out and discovered that once you choose .xyz as the output format of your choice the value after -of automatically changes to.xyz. This is particularly useful in QGIS3.X where it's difficult (or impossible) to edit the GDAL/OGR console directly. Nov 16, 2020 at 21:50
2

That's an easy task using gdal_translate or gdal2xyz.

I not sure of how to do it exactly with qgis. Probably with the GDAL Tools Plugin is possible.

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