I have two layers; one with elevation data (m), and the other with roads (derived from points via points to polyines). I want to run a spatial query that basically extracts the elevation data from the start and end nodes of each link. The core function sounds like a common scenario many users may face. Is there a way of doing this?

I have provided an image to help. The blue lines are roads, and the red lines is the elevation data.

enter image description here

  • 1
    You will likely have better luck using a raster data type, such as a DEM, as a source of your elevation data. Elevation contours represent the elevation only along the contour lines. – reevesii Nov 16 '18 at 16:17
  • Using GRASS GIS in QGIS' Processing you can upload raster values at positions of vector points to the attribute table, see grass.osgeo.org/grass74/manuals/v.what.rast.html (this requires a DEM derived from the contour lines). – markusN Nov 16 '18 at 21:40
  • 1
    Since qgis 3.4 there's a built in tool for "draping" vectors over a raster, setting the z value for coordinates to values sampled from the raster. If you converted your source vector to raster via interpolation you could the run this tool to update the z values of the destination layer. – ndawson Nov 17 '18 at 9:51

With the data you have, you can estimate elevation at the end of each road as follows:

  1. Select the start and end points in your point layer, and (optionally) save them as a separate layer.
  2. Install the refFunctions plugin.
  3. Add the elevation of the nearest contour line to the point layer's attribute table, by using this expression geomnearest('contourLayer','elevationField') in the Field Calculator.

    • substitute the name of your contour layer where the expression says 'contourLayer'
    • if the elevation is stored as an attribute table field, substitute the name of that attribute where the expression says 'elevationField'
    • if the elevation is stored as a Z value rather than as an attribute, use the expression $z

As reevesii suggested, you will have better accuracy using elevation in raster format. Contour lines only represent the elevation along the line, so if your roads don't end exactly on a contour line the elevation of the nearest contour line won't be accurate for that point.

To calculate more accurate elevation for the end of each road:

  1. Acquire a DEM (digital elevation model) raster for your area of interest. DEMs are available for free from many sources, such as Natural Earth and the United States Geological Survey.
  2. Select the road start and end points in your point layer.
  3. Use the Sample raster values tool to add elevation values from the DEM to the selected points.
  • Hi, thanks for everyone's input. The elevation data is a shapefile - which already has the elevation (m). The shapefile is 10m intervals - as we require a higher resolution in comparison to other free layers. – Ben Turner Nov 19 '18 at 11:52

You can execute the Feature Vertices to Points tool (requires Advanced license) and choose the option END for the Point Type parameter. This will give you a point feature class of the start/end point. Next, execute the Extract Values to Points tool (requires Spatial Analyst extension) to extract the elevation from the raster dataset.

  • This answer is for ArcGIS; the question is about QGIS. – csk Nov 16 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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