Cutting/ exporting multiple terrain profiles to CSV files with QGIS?

by Derek Eden   Last Updated August 13, 2019 20:22 PM - source

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.



Answers 1


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.

csk
csk
August 13, 2019 19:51 PM

Related Questions


Terrain profile across vector contours

Updated December 31, 2017 13:22 PM

QGIS Profile tool does not plot graph

Updated May 26, 2016 09:11 AM

QGIS Profile Tool shows no profile

Updated January 03, 2018 12:22 PM

how to convert DEM(TIF) files to terrain files

Updated April 28, 2019 12:22 PM

City Engine: Align Terrain to Shapes - Purpose?

Updated February 27, 2019 10:22 AM