[GIS] Get pixel value from a raster in a xy table

arcgis-10.1asciiexcelqgisraster

I'm trying to find a way to convert a raster (in my case it's a Landsat satellite image) into a table with 3 columns which would represent: 1) x coordinates (the so called "xllcorners" in ASCII terms); 2) y coordinates (the so called "yllcorners"); 3) the relative pixel values.
As I'm working with 8-bit pixel-depth raster, my table should look like this at the end:

   X       Y      Pixel
493185  4989885     0
493185  4989915    127
   .       .        .
   .       .        .
   .       .        .

I tried to convert the raster into ASCII format and it gave me a grid with 7911 columns and 7211 rows. No problem so far, but since I want to organize the entire grid as it fits my 3 columns requirement, I haven't been able to import it to excel (where I'd like to do my calculations) properely (namely, it seems replacing and cutting off the spaces, inserting commas and so on didn't work so fine as there's always something different than in the "txt" ASCII grid, and it's not a squared grid neither, which complicates the things).
I'm using both ArcGIS 10.1 and QGIS 1.8 if it could be of interest.

Best Answer

GRASS GIS r.out.xyz tool

You can use the r.out.xyz tool in the GRASS toolbox in QGIS. The function exports a raster map as a list of x,y,z values into an ASCII text file, skipping x,y coordinates for raster cells containing a NULL value. For more information, see the r.out.xyz help file. The disadvantage is that you need first to create a GRASS database and import (or register) the raster layers.

GDAL gdal2xyz tool

Alternatively, you can use the gdal tool gdal2xyz.py, which is a command line tool that does basically the same as r.out.xyz. It should be included with the GDAL that comes with QGIS. See this similar question on gis.stackexchange, which tells you to run it from an OSGeo4W command line window as:

gdal2xyz -csv infile.asc outfile.csv

Related Question