2

Now, I'm trying to calculate terrain slope(°) using pyqgis using below process.

  1. Along the specific lines which I want to know the terrain profile, I generated the points using 'qgis:pointsalonglines'.
line_lyr_1 = processing.run('native:pointsalonglines',{'INPUT':line_lyr_0,'DISTANCE':10, 'START_OFFSET':0, 'END_OFFSET':0, 'OUTPUT':'memory:'})['OUTPUT']
  1. Using generated points and DEM raster layer, I could get the elevation data for each points by below codes.
elevation = namedtuple('elevation', ['Place_Name','Line_ID','Distance', 'Elevation'])
elevation_datas = []

for feat in line_lyr_1.getFeatures():
    point = []
    tanada_ID = []
    line_ID = []
    distance = []
    elevation_point = []
    
    point = feat.geometry().asPoint()
    Place_ID = feat.attributes()[0]
    Line_ID =  feat.attributes()[1]
    Distance = feat.attributes()[2]
    Elevation = list(rst_lyr_1.dataProvider().identify(point, QgsRaster.IdentifyFormatValue).results().values())[0]
    
    elevation_datas.append(elevation(Place_ID, Line_ID, Distance, Elevation))
  1. After the exporting the elevation data, I made a terrain plots using exported data with the equation calculating slope degree atan(Elevation/Distance)*180/pi() in Excel.

enter image description here enter image description here

  1. However, using the profile tool plugin in QGIS, I got below results. enter image description here

Why did my result become different between two plots? Is the calculation method different in profile tool plugin?

I think the result of profile tool plugin is correct.

1 Answer 1

3

In Step 3, your description of the equation for calculating slope degree, is:

atan(Elevation/Distance)*180/pi()

In your example, it appears that you are using the absolute point elevations and distances. When calculating slope, you should be using the change (Δ) in elevations and distance (not the absolute elevations and distances). Once you calculate slope, you could plot the slope at absolute distances:

enter image description here

Also, be aware that you can select whether to plot Height, % Slope, or Slope Degrees in the Profile Tools Plugin:

enter image description here

1
  • Thank you for quick response !
    – Lc_decg
    Apr 29, 2021 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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