1

I have a layer of polylines and I want the elevation difference (how many metres the line goes up and down) for each feature in the attribute table, using QGIS 3.2.

So far I tried the plugin "Profile Tool", but it shows only the minimum and maximum elevation point, so I have to manually calculate and enter the differences in the attribute table. I also tried the GRASS tool "r.profile", but I didn't make it work and I'm not sure if it achieves my goal.

So, is there a more automated way to get the elevation difference, than manually calculating it from the Profile Tool?

  • r.profile will do what you want; what do you mean "but I didn't make it work"? What was the problem? – Jon Aug 21 '18 at 13:46
  • I input a DEM raster layer, but where do I input the layer containing my polylines and in which format? Every other option besides "Input raster layer" is marked as optional, so I'm kind of confused how it actually works. – gHupf Aug 21 '18 at 13:59
  • Ah, it appears you are right. r.profile doesn't seem to take an input polyline, but a set of user-defined coordinates. That seems pretty useless. I am doing what you want using Python; I could give you the code but it sounds like you want a QGIS solution. The "Profile Tool" will work, but you have to hand-digitize your polyline. – Jon Aug 21 '18 at 14:11
  • You mean using the python console? I don't need to use a plugin for it, as long as the outcome is what I am looking for, so python code would be great too. – gHupf Aug 21 '18 at 14:29
  • I don't know if you could use the Python console--you might need to install some packages. I do this kind of analysis frequently in Python standalones. My basic script loads the shapefile into a geopandas dataframe, loops through each linestring to get the vertices, resamples them at the same resolution as the raster, then pulls the raster values for each resampled point. If that sounds like something you'd be interested in, I can post the code, but I think it might be a little tricky to get to work in the console (not sure). Someone else might post a better QGIS-only answer. – Jon Aug 21 '18 at 14:52

Your Answer

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

Browse other questions tagged or ask your own question.