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 have been able to import into QGIS a set of raster topographic maps and the associated DEM raster maps. It registered the two for me. From there I have calculated the associated slope raster map. Now I want to export the data to a CSV file (or similar format) for processing in a program that I am writing. Ideally the data would be structured in a way that would permit me to query for the slope and elevation data for any given point on the map. Is this possible? If so, then how do I do it?

Edit: There was a comment linking to another post but it seems to be gone now. Regardless it made me realize that I need to clarify my question. Specifically, I have been able to export the data (slope & DEM) to two different CSV files. However I would prefer the data in one file if possible.

share|improve this question
1  
You kind of need a two-band raster, it seems. –  elrobis Dec 5 '12 at 18:14
    
Hi @elrobis, what is a two-band raster? (I'm new to GIS.) –  DaemonMaker Dec 5 '12 at 18:16
1  
CSV can be awfully inefficient for large DEMs. Is there a strong reason you need this, or can your programming platform read other formats (such as BIP, BIL, etc)? Note, too, that "CSV" is ambiguous: do you need the output to include explicit coordinates or can it represent the coordinates implicitly (which is much more compact and efficient)? –  whuber Dec 5 '12 at 18:23
1  
A raster "band" corresponds to the value you can extract from any given position/cell in the dataset. The most common example of a multi-band raster is probably the three-band Red, Green, Blue (RGB) images we encounter all the time. In contrast, your DEM is only one band, and I think your slope is also one band. But you can have several bands, which is commonplace during an analysis. Here's a fancy word: data cube---all kinds of bands, maybe a hundred-plus. I don't think you need a data cube, though. :) –  elrobis Dec 5 '12 at 18:26
1  
Read webhelp.esri.com/arcgisdesktop/9.2/… . You can adapt these layouts to ASCII-based files if you want. It sounds like you want to focus on BIP. –  whuber Dec 5 '12 at 18:27

2 Answers 2

up vote 6 down vote accepted

If you really want a text-based raster..

whuber is quite right about a text-representation of raster data being inefficient. But at the same time, it can help to "see the data" when it's represented in text, especially while you're cutting your teeth on some concepts

So in the spirit of endorsing text-based-raster for some purposes, you might want to check out the Golden Surfur ASCII Grid (GSAG), which QGIS can export for you (Raster menu > Conversion > Translate).

Furthermore, the format of the GSAG file is described in this document, which you might find useful.


On banding..

If you want to make a two-banded image in QGIS, open Raster menu > Miscellaneous > Merge, and in this dialog you can create a multi-band image, probably alot like I'm doing, below. Note that QGIS implements the Geospatial Data Abstracion Library (GDAL) to accomplish alot of its functionality, so it's often a good idea to become familiar with what GDAL is doing behind the scenes. In this case, here is the documentation for the gdal_merge.py command line utility.

You can't tell in the screen grab, but two different raster files are selected in the Input files field. If you could see all of it, they're comma-separated, like this:

D:/GIS/01_tutorials/geene_dem/slope/slope.tif,D:/GIS/01_tutorials/geene_dem/slope/dem.tif

..and you can just CTRL-click them to do a multi-select in the UI. Also, I believe the bands are index 0-n according to the order that GDAL receives them, so band 1 (index 0) would correspond to the slope values. I hope someone shall correct me there if I am wrong. But the point is, you need to keep track of which band is which value.

enter image description here

Later, once you have the two-band image created, you can check out the Raster Calculator (Raster menu > Raster Calculator) for most any analysis you want to accomplish. In the Raster Calculator, notice how I created a simple expression to evaluate using my bands 1 (slope) and 2 (elevation) to create a new value---a value which I can export into a brand new raster, if I want.

enter image description here

share|improve this answer
1  
@DaemonMaker, it's worth mentioning that you don't need a 2 band image just to use the Raster Calculator. As you can see above, the original dem and slope rasters are available to the utility without being banded together. I think banding is usually reserved for scenarios where the dataset was created in the same instance (like a camera exposure, where all bands are created at once). In contrast, the slope is derived, so I wonder if it should even be banded with the original DEM, at all. In hindsight, I think the banding may not be appropriate---though it was fun to think about. :/ –  elrobis Dec 5 '12 at 20:35

You can export a two-band raster to a space-delimited text file using gdal2xyz.

gdal2xyz.py -band 1 -band 2 filename.tif filename.txt

The raster doesn't have to be a TIFF. I think QGIS still comes with gdal2xyz as part of the package.

Just to add, you have a DEM TIFF and a slope TIFF. It will possible to stack these together in one raster using gdal_merge from within QGIS. Raster -> Miscellaneous -> Merge, tick "Layer stack". Then use gdal2xyz on the resulting two-band raster.

Oops, elrobis got there before me, apologies to all.

N.

share|improve this answer
1  
Heh, NP, actually I up-voted you because I liked the command line spin on the answer. Out of curiosity can gdal2xyz.py be launched from a QGIS install, presumably using the OSGeo4W shell? I wonder this because I can call gdal2xyz.py in my OSGeo4W shell, but I don't know if my co-existing GDAL install and PATH variable are making that happen. –  elrobis Dec 5 '12 at 19:53

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.