0

I am new to QGIS. My aim is to be able to get information of the height at any point on my vector line. My raster is a map with height information in the format geotiff. The vector layer is in the shape format.

I tried to intersect them but it wouldn't work, I guess because they are not the same format. I also tried to vectorize the raster layer and use the plugin refFunction and geomwithin but it wouldn't work either.

2

How about using the QGIS plugin Profile tool?

With this plugin you can get the exact elevation just by moving the cursor over the graph. You can also export a table with elevation data for your line.

Line on top of a DEM Profile tool

  • Do you know if there is any way to avoid moving the cursor over the map and instead using a vectorlayer to tell the program where I want to know the elevation? – Jule Kle Jan 28 at 10:51
  • I'm not sure if I understand you. Where along this line do you need your elevation info? Every vertex node? Or every xx kilometers? – oskarlin Jan 28 at 12:28
  • Basically every few metres along the line. – Jule Kle Jan 31 at 12:23
  • Then I'd recommend the answer by @csk, convert line to points! – oskarlin Feb 1 at 13:19
2

It depends on what you want to do with the elevation information.

If you want the elevation stored in the attribute table, you have to convert the line to points. QGIS can't store data "at any point on a vector line" because the line only has one entry in the attribute table.

First convert your line to points, using the extract vertices or points along geometry algorithm.

Use the GRASS algorithm v.sample or the QGIS algorithm Sample raster values to apply the raster data to the points as an attribute.

Note: all algorithms mentioned in the answer can be found in the Processing Toolbox.

If you want to find the elevation at a single point along the line, you can use the Identify tool in "Top Down" mode.

If you want to get the elevation in the expression builder, you can use the raster_value() function, for example:

raster_value('mypointlayer',1,$geometry)

Again it requires a point rather than a line as input. There are various ways to write a point into the equation, for example using the line_interpolate_point().

  • To be honest I already fail to convert the line to points. The only time this worked I got points somewhere near the line or even just at certain vertex. Could you explain me in a few steps how to convert the vector line into points every few meter? – Jule Kle Feb 8 at 12:10
  • The extract vertices tool does exactly what its name says: it extracts the vertices of the line. If your line doesn't have enough vertices, you can add them using the Densify by interval tool. – csk Feb 8 at 17:06
0

Just to add another method, in QGIS 3.4 you can save the height of the raster in the Z variable of each vertex of the geometries (points, lines or polygons) of a vector layer, with the Drape (set Z value from raster) tool.

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.