I have downloaded a GeoTIFF data file, and I want to get the altitude information given the coordinates in degrees. So I want something like

get_elevation(lat, long):

and then when you do

get_elevation(45.833333, 6.867222)

it returns something like 4807. That is the altitude of the location of Mont Blanc.

How can I extract this information from a GeoTIFF data file in Python?

I tried an answer given HERE:

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("SRTM/srtm_37_09.tif") as dataset:
    band = dataset.read(band_of_interest)
    value_of_interest = band(row_of_interest, column_of_interest)

which just gives an error:

Traceback (most recent call last):
  File "tester.py", line 18, in <module>
    value_of_interest = band(row_of_interest, column_of_interest)
TypeError: 'numpy.ndarray' object is not callable

How to do it?

How can I easily get the elevation data and its associated coordinates?



Browse other questions tagged or ask your own question.