This question already has an answer here:

I have a DEM(.tiff) file and I need to know the altitude of certain points(coordinates).

I opened it like this:

import tifffile as tiff
import matplotlib.pyplot as plt
import rasterio

tfile = tiff.imread('ms.tif')

Then I've got this image:

enter image description here

I just need some function to get altitude to my points, not the full code.

marked as duplicate by user2856, TomazicM, Fran Raga, neogeomat, xunilk Oct 1 at 23:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


That's a easy task with rasterio. For each band the data is accessible as a kind of array.


import rasterio

# Which band are you interested. 
# 1 if there is only one band
band_of_interest = 1

# Row and Columns of the raster you want to know
# the value
row_of_interest = 30
column_of_interest = 50

# open the raster and close it automatically
# See https://stackoverflow.com/questions/1369526
with rasterio.open('example.tif') as dataset:
    band = dataset.read(band_of_interest)
    value_of_interest = band(row_of_interest, column_of_interest)
  • The row and column of interest is going to be the lat/long? – Felipe Andrioli Oct 9 at 18:47

I think you need to create a points dataset from the coordinates then use the Extract Values To Points tool, if using ArcGIS Desktop or ArcPro.

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