[GRASS-user] Calculating line length over terrain

Hamish hamish_b at yahoo.com
Thu Jun 11 07:48:31 EDT 2009

> Falk Grossmann wrote:
> > My objective is to calculate the length of a line (GPS tracklog) in a
> > very mountainous terrain. In this case I will need to take into
> > account the 3D aspect.

be aware this is very much a fractal problem with no true answer.

Markus M wrote:
> Can't you import the tracklog as 3D line with v.in.ogr -z?

gpsbabel has some filters for converting GPX points to GPX track lines,
the help pages aren't that wonderful, but I've done it and it works.

> The imported vector may contain both points and lines. Then v.to.db
> option=length?

(the vector library automatically takes into account the vertical dip
of 3D vector lines when calculating length, so all you have to do is
run d.what.vect or v.to.db)

beware when using this in a lat/lon location though, I'm not sure how
well the geodesic (great circle) code deals with this. (but I'd be
interested to hear about it)
probably better to work in a plainmetric map projection like UTM.

> > I see two ways of working this:
> >
> > 1) Converting the points to line vector

(GPX file -> gpsbabel -> GRASS's v.in.gpsbabel or v.in.ogr's GPX driver)

> > and than using a DEM to calculate the length.

a 2D line can be converted to a 3D line with v.drape. but only do that
if your DEM is much better than your GPS elevation (note vertical GPS
error is typically about an order of magnitude worse than horizontal
error, and is typically given as height above the geoid surface, not MSL)

> > In ESRI software I would convert the DEM rasta to a TIN and than
> > overlay the line vector to calculate length.

TINs make me shudder.

> > However, as DEM's in Africa are course

using SRTM?

> > (and in the process of weaning myself of ESRI) I would imagine I
> > would be better of using something along the lines described bellow
> > in GRASS:
> >
> > 2) Use of the converted point to line vector and than incorporate the
> > point vector (GPS tracklog) which contains x,y,z data points to
> > calculate the "3D" element which needs to be added to the length.
> > Maybe I need to segment the line, than "extract" the slope of the
> > line segments (from on GPS point to the next) and than use the map
> > calculator to get the length of each segment?

(already done for you by the vector lib if it knows it is a 3D line)

> > I wondering if there are any tools in GRASS which deal with this in
> > one go

typically grass is a collection of 500 little tools and models which you
string together to get your job done in a series of steps. don't expect
too many things to happen in "one go". the other side of that is that
grass is very very flexible and powerful.

> > (maybe in the hydro tools or terrain?) For method 2 I am
> > wondering how can calculate the slop of a line - since the
> > attributes are attached the the start and stop GPS points of that
> > segment.

v.to.db option=slope will do something like that for the entire line,
but again it should already be taken care of for you.



More information about the grass-user mailing list