2

I am trying to cut multiple terrain profiles and export them to CSVs (individual or combined).

I have a shapefile of the profile lines, and a DEM to cut the profiles from.

I can do this manually multiple ways (i.e. Profile Tool) and either copy the profile data or export it by clicking some buttons...but I am wondering if there is a way to automate this for MANY profiles.

I.e., run a script/plugin that cuts profiles at every line in the shapefile and exports them to a CSV file.

2

Use the Sample raster values or Add Raster Values to Points tool to extract raster values:

  1. Make sure each line has a unique attribute, eg "Line_ID".
  2. Convert the lines into points
    • Use the Extract vertices tool if the vertices are frequent enough, or
    • Use the Points along geometry tool if you want more frequent/evenly spaced sampling points
  3. Use the Sample raster values or Add Raster Values to Points tool to add elevation values to the point layer created in step 2.
  4. Export the output from step 3 as a CSV.
  5. Plot a separate profile graph for each unique "Line_ID" value.
    • If you used the extract vertices tool in step 2, the distance between points should be controlled by the "distance" attribute.
    • If you use the points along geometry tool in step 2, plot the points equally spaced.

If the profile lines are all in the same layer, you'll only need to run through this process once.

If you're doing this multiple times, consider putting this process into a Graphical Processing model.


Here's another method using the Drape tool:

  1. Make sure each line has a unique attribute, eg "Line_ID".
  2. Use the Drape (set Z-value from raster) tool to add elevation to the line vertices.
  3. Export the profile lines (now with Z values) to CSV. Under Layer Options, choose Geometry AS_XYZ

    enter image description here

  4. Plot a separate profile graph for each unique "Line_ID" value. Use the "distance" attribute to control the spacing of the points on the graph.

  • I am using QGIS 3.2 - the first approach worked, however I had to use the "Add Raster Values to Points" tool to sample the raster at the generated points along each profile..thanks – Derek Eden Aug 13 at 20:10
  • 1
    Thanks for mentioning another tool. It's good to have more than one way to achieve the same goal. – csk Aug 13 at 20:12

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.