Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
1  
You're kidding, right? Do you really plan on using Excel to manipulate over 57 million rows of values?? The file at the outset will be several gigabytes and grow from there; all operations will take a long time to complete; even gross errors will be difficult to detect (and easy to introduce); and anything meaningful you can possibly do in Excel can already be done far more easily and quickly using tools native to QGIS and ArcGIS. –  whuber May 22 '13 at 17:07
1  
You're totally right, now I figured it out. I will limit my quest as to include only those parts I'm interested into and then extract those as to (huggely) limit the space requirements. At least I found many ways to extract waht I wanted from the community's suggestions. –  user9518 May 23 '13 at 8:24
add comment

4 Answers

up vote 1 down vote accepted

If you have an ArcGIS Spatial Analyst license you can use the tool Sample (Spatial Analyst). This tool creates a ZXY-ascii file from your raster file.

share|improve this answer
    
Hi. It looks like what I was looking for, but it seems failing all the time due to an "unknown" error (it's not a typical one, seems like a sort of crash). I'm using the same raster as for the input to specify the location, don't know if this could cause the problem. I'm talking about an entire Landsat scene, which means 7000 and more raws and 7000 and more columns, therefore my laptop consistently slows down its performances when trying to execute the function. Not the first time I'm working on these kind of data though... –  user9518 May 22 '13 at 14:18
    
This is perfect, just one simple tool that does my job. Too much data to work with tables though, I will choose only some samples and extend to the whole image only when I'll have to (using powerful computers). Many thanks to You and to all the answers/comments, it was really helpful! –  user9518 May 23 '13 at 8:26
1  
Chances are that you don't need powerful computers. The vast majority of calculations done with raster data are most efficiently done by keeping those data in raster form and using the (very many) capabilities of a raster GIS to process them. "Sampling" and other forms of raster-to-vector conversion should be considered as last resorts, to be used for (a) highly complicated and specialized calculations (such as numerical models) or (b) exporting to other software that has limited import capabilities or (c) occasionally, cartographic purposes such as labeling every cell. –  whuber May 23 '13 at 12:25
add comment

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

share|improve this answer
add comment

Keep it simple, see qgis: Obtain all elevations points from a raster DEM:

Go to Raster menu,Conversion sub menu,convert, and choose (you have the list of all the possible formats in GDAL raster Format)

share|improve this answer
    
+1 This time your solution is ideal! –  whuber May 22 '13 at 17:03
add comment

In ArcGIS you can do this:

  1. Convert your raster to point vector file. ArcGIS tool Raster to Point (Conversion)
  2. Add x and y colum to point file and calculate x and y-coordinates. ArcGIS tool Add XY Coordinates (Data Management)
  3. the x and y coordinates are the coordinates of the pixel center. Use Field Calculator to calculate xllcorners and yllcorners (add/subtract half pixel size).
  4. Export attribute table to ascii file
share|improve this answer
    
I wonder how long the conversion of a 57 million cell grid to points would take ... . –  whuber May 22 '13 at 17:10
add comment

Your Answer

 
discard

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.