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.

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

4 Answers 4

up vote 9 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

You can go much further by combining DEM and raster colors, using GRASS with R (see Raster profile along arbitrary line segments, or http://www.portailsig.org/content/grass-gis-et-r-superposition-des-couleurs-d-un-raster-quelconque-sur-un-profil-topographique 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

Here screenshots for GRASS: alt text alt text

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

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.