I've a shapefile of roads data. It contains information about terrain of road segments, i.e., hilly, flat, undulating, etc. I want to determine gradient of every road segment. I know this might require corresponding raster data and a lot of image processing. I also understand that I can use GRASS for this kind of analysis. But I've never attempted a task like this before.

For those who have, is GRASS my best bet? And, must I get the corresponding raster data? Is there a way I can do this without having to get my hands dirty with image processing algorithms. In case I must get the corresponding raster data, is there a source I can get reliable raster data that is not more than 4 years old?

Your contribution will be highly appreciated.

UPDATE: There will be a need to split a road segment that has both ascending and descending gradients. Overlaying the roads vector onto a raster layer is one of the options I think can work. But I don't have the raster data. Any idea where I can get raster data with sufficient accuracy and resolution will be appreciated. Can GRASS accomplish the splitting, and the analysis. I'd prefer open source tools for now as I'm still experimenting.

UPDATE: The purpose of the analysis is to come up with an algorithm that calculates economic well being of a point on a map, taking into account its accessibility (distance from the road, terrain, among other factors). Also, the algorithm is to also aid in decision making in relief food distribution.

UPDATE: I've got some material here on terrain analysis. Any advice is still welcome.

  • What happens when a road segment spans both an uphill and downhill stretch? What would you want do in that scenario, average or split the road segment? The latter would be quite complicated. You also didn't specify where your study area is.
    – nagytech
    Commented Aug 31, 2012 at 7:47
  • @Geoist, I've just got the problem definition. I'm trying to come up with an algorithm that would help determine economic state of a geographical area given its accessibility, among other factors. I also want to construct an algorithm that gives an efficient route to a point. The algorithm should not only consider distance, but also terrain (if the terrain is a hill, I would like to know its gradient). Other factors like whether the road is murram or tarmacked are also to be taken into account.
    – okello
    Commented Aug 31, 2012 at 10:08

4 Answers 4


Heres what i would do:

  1. Overlay the roads layer with a dtm layer, this way, all the vertices of the segments would get a Z coordinate
  2. Calculate the gradient based on the segment length and height difference between the start and end point of the segment
  3. Classify the segments based on the gradient value as required

Tools i would use: FME

PS: When you say road segments, you probably think of them as segments in network topology, ie, one segment may be a polyline, not a simple line. Its up to you to decide wheter you want the gradient calculated for such a segment or perhaps for a single line

  • Thanks a lot, @U2ros. I was thinking of the same thing; I've to overlay the road layer onto a raster layer. There will be a need to split a segment that has both ascending and descending gradients. As for the tool, I was thinking of GRASS, but I can give FME a try. Lemme check it out.
    – okello
    Commented Aug 31, 2012 at 10:12
  • Okay, about the splitting part. You probably want the polyline split at local maximums and minimums. You could first split it with a very dense interval, like 5m, then you could identify which of these new vertices represent actual extremes by comparing previous/next vertex z values. Im not familiar with GRASS myself, so im not sure. What i described would still be doable in FME. I also think theres an actuall spatial analysis you can perform in arcGIS, cant remember which one it is, that could find such extremes along a path for you
    – U2ros
    Commented Aug 31, 2012 at 11:20
  • 1
    Okay, read your updates. What you are doing is COST analysis :) For that you could rasterize the roads onto the DTM itself, giving it a very low cost value - just an idea
    – U2ros
    Commented Aug 31, 2012 at 11:23

look. I had to do the same task for my Master research, so i think i can help you. I'm gonna show you the steps using Arcgis, but you cand do with Qgis or Grass, if you get the general idea.

  • The first thing you need are the nodes. Nodes are the points of intersects between each segment of road (link). Each ling should have an ID, id of the first node (idnodea) and id of the second node (idnodeb). You need that each road segment be a line, so if you a vector polyline, you must divide it. You can use the QGIS function Simple Part to Multi Part: Vector-> Geometry Tools -> Multipart To Single Parts. Then you Extract the nodes of your new multipart shapefile, also with QGIS: Vector-> Geometry Tools -> Extract nodes
  • Get a Digital Elevation Map oof you zone of study. Use ASTER.
  • Extract the elevation Z coordenate for each node. (Look this example using Arcgis in spanish)
  • Add the elevation coordenate to each node of your road map. You cand do this with Join function
  • Calculate the gradiend (slope) between for each road segment Slope = (z2 - z1) / ([(y2-y1)^2 + (x2-x1)^2]^0.5)*100 this will give tou the slope as percentge.

Look this example, also in spanish using Arcgis.

Take into account that you must consider that negative and positive slope will give you the order , if your line is nodea-nobeb, or nodeb-nodea. Road slope for Santiago


I have FME in similiar use. LAS/contours/raster data & line vectors -> SurfaceDraper = Line which follows surface, easy, fast and costs.

My QGIS 1.8 sextante toolbox gives me GRASS command "v.drape", wich needs raster data for elevation, So it should be "easy" to do in QGIS or GRASS

  • Thanks @simplexio. Now, I need to get raster data for Kenya for this exercise. I'll search around for that but if you know where I can look, I'll appreciate an advice.
    – okello
    Commented Aug 31, 2012 at 11:47

In GRASS GIS, first use v.split to add sufficiently vertices, then v.to.db to upload the slopes for each segment (parameter "slope": slope steepness of vector line or boundary).

For elevation datasets, see http://grass.osgeo.org/wiki/Global_datasets

  • Thanks @markusN. I'll try these suggestions this weekend, and let you guys in on my findings.
    – okello
    Commented Aug 31, 2012 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.