Now, I'm trying to calculate terrain slope(°) using pyqgis using below process.
- 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']
- 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))
- 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.
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.