0

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) print(value_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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Alex
  • 101
  • 2
    What in the many existing answers to this did not work for you? https://stackoverflow.com/questions/60127026/python-how-do-i-get-the-pixel-values-from-an-geotiff-map-by-coordinate , https://gis.stackexchange.com/questions/299787/finding-pixel-location-in-raster-using-coordinates , https://gis.stackexchange.com/questions/190423/getting-pixel-values-at-single-point-using-rasterio for a start. – bugmenot123 Jan 08 '22 at 09:37
  • IndexError: index 0 is out of bounds for axis 0 with size 0 – Alex Jan 08 '22 at 09:41
  • I get a negative index for a pixel! Either the code (first answer) is not working, or I am doing something else wrong. But it is not working! – Alex Jan 08 '22 at 09:45
  • Maybe you can point me to a webpage where I can select a region and download the selected elevation data? – Alex Jan 08 '22 at 09:46
  • Please use the [edit] button beneath your question to revise it with any requested clarifications. – PolyGeo Jan 08 '22 at 10:34
  • https://gis.stackexchange.com/q/190423/2856 https://gis.stackexchange.com/q/411359/2856 https://gis.stackexchange.com/a/228968/2856 – user2856 Jan 08 '22 at 12:03

0 Answers0