Is there a way to export all values from a raster to for example a cvs or other textfile or dbf or xls and later import (changed) values from that file back into the raster? For vector-files this is no problem but for raster-files I have not found anything like this. (Important here: the export-file should be a table, not a grid).

The idea is to process raster-data with some external program like excel of statistics-software, to add channels (=columns) based on the data already there or create a new channel by linking data with data from a table. All this can be easily done for vector-layers but apparently not for raster-layers.

THX, stn


As mentioned in the other topic, you could use gdal2xyz. For each pixel in a raster this will save an xyz triplet in a CSV text file. It's included with the GDAL that comes with QGIS, run it from an OSGeo4W command line window:

gdal2xyz -csv infile.asc outfile.csv

Under Linux you could try running it in a terminal. If this doesn't work 'locate' gdal2xyz.py and add its path to the command line. It will work with one-band rasters in all of the common formats, not just ASCs. Come back if you have rasters with more than one band, gdal2xyz can handle these too.

| improve this answer | |
  • Oops, forgot about that one :-) Yes, that solves part of the problem. Now I only have to get the data back in after external processing, along with the original coordinates, datum etc. One thing surprised me: Why does gdal2xyz handle only one band at a time? It could just as well output x and y and one addtional column for each band. – stn Apr 3 '12 at 18:54
  • 1
    OK, so gdal2xyz does handle multiple bands. You find that out after googling: gdal2xyz -band 1 -band 2 scrfile.tif – stn Apr 3 '12 at 19:24
  • Yup! It will even handle images. You have to drop the -csv if there is more than one band and then you get a space-delimited text file. – nhopton Apr 3 '12 at 19:54

Well, here is a nice twist :-)

The latest version of GDAL includes a program named "gdal_calc.py" that looks like it can do more on the commandline than the version that is in the QGIS-menu. Very cool !

With Ubuntu this tool does not show up unless you completely uninstall the "stable" version of QGIS and all its dependencies and then reinstall from the "unstable" repository.

| improve this answer | |

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.