1

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 ?

  • Could potentially be related to the edge of the imagery behaving differently between the two data sets. Try writing it to a file instead of summing things up. – Mikkel Lydholm Rasmussen Oct 17 at 13:36
  • @MikkelLydholmRasmussen But what I need is the summed value of all the cells. If I write this numpy array height_nparray to a file (say, I created a .tif file), how can I find the summed value of the entire .tif file ? – Sreeraj Oct 17 at 14:10
  • It'll help you understand the source of the error. You may need to mask out the edge of the image and without looking at the data, it'll be challenging to identify which values to get rid of. – Mikkel Lydholm Rasmussen Oct 17 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.