For the future users' convinience, when you provide lat lon in get_elevation function, it gives the elevation. elevation_file = 'Dem.tif' def get_elevation(lat, lon): coords = ((lat,lon), (lat,lon)) with rasterio.open(elevation_file) as src: vals = src.sample(coords) for val in vals: elevation=val[0] return elevation get_elevation(34, 36)