Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a DEM (Digital Elevation Model) and a line (x1,y1) --> (x2,y2) (paired coordinates (x,y)), how can one calculate the elevation profile or cross-section projected on that line?

I am looking for an open source code that I can use in my project or pseudo-code that I can use as a guide.

share|improve this question
up vote 11 down vote accepted

The GRASS command r.profile performs this (documentation, source) and should provide a good basis for implementing a cross section, and is available under the GPL.

share|improve this answer

Maybe QGIS "Profile" plugin source code can be a start.

alt text

share|improve this answer
This would be nice thing to have built into QGIS. Maybe under the raster menu. Also have multiple lines the GRASS example would be cool. – Nathan W Sep 28 '11 at 0:34

Here screenshots for GRASS: alt text alt text

share|improve this answer
Are these pictures derived from the tool specified in scw's answer (r.profile), or are they from another tool (a GUI tool, for example)? Perhaps the answer could be improved if you specify the name of the tool, some reference for its documentation and where it can be accessed within the software. – Andre Silva Jul 16 at 15:07

You can go much further by combining DEM and raster colors, using GRASS with R. See:

See some examples below:

With elevation colors (GRASS GIS and R):

enter image description here

With colors of a Geological Map (Python with GRASS raster):

enter image description here

And using the Python script in the Python console of QGIS:

enter image description here

share|improve this answer

Your Answer


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.