I want to calculate the elevation of a particular feature. I have both DSM and DTM as input data, both with the same cell size and same number of columns and rows (same resolution). For the DSM, min = 532.807 and max = 541.081. For the DTM, min = 532.771 and max = 537.959.
I want to calculate the elevation (DSM - DTM) of each pixel and finally add all of them to calculate the final elevation of the .tif file representing the particular feature. I followed the procedure given below using GDAL in QGIS.
dtm = gdal.Open(r"C:\Task\Data\DTM.tif") dsm = gdal.Open(r"C:\Task\Data\DSM.tif") # taking pixel values into a numpy array dtm_nparray = np.array(dtm.GetRasterBand(1).ReadAsArray()) dsm_nparray = np.array(dsm.GetRasterBand(1).ReadAsArray()) # numpy array representing Height of each pixel height_nparray = np.subtract(dsm_nparray, dtm_nparray) # DSM - DTM = Elevation sum_elevation = np.sum(height_nparray)
Unfortunately, I got the value of sum_elevation as a negative value. This means that DSM - DTM = -ve value which is actually wrong.
What is the exact issue here ?