Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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) say in 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 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 10 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

You can go much further by combining DEM and raster colors, using GRASS with R (see Raster profile along arbitrary line segments, or and with Python (Python: utilisation des couches vectorielles et matricielles dans une perspective géologique, sans logiciel SIG , in french, but the scripts are universal...)

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.