I want to assign a specific long/lat position on a map to the elevation from SRTM3 data files, but have no idea how to find the specific value. So I want some example of how I can find in N50E14.hgt elevation to 50°24'58.888"N, 14°55'11.377"E.
Extract Elevation from .HGT File – Elevation Data Guide
elevationsrtm
Best Answer
Data format
I'll take it as a little exercise in how to program a data reader. Have a look at the documentation:
How to proceed
For your position, 50°24'58.888"N 14°55'11.377"E, you already found the correct tile, N50E14.hgt. Let's find out which pixel you are interested in. First latitude, 50°24'58.888"N:
arc seconds. Divided by three and rounded to the closest integer gives a grid row of 500. The same calculation for longitude results in grid column 1104.
The quickstart documentation lacks information about how rows and columns are organized in the file, but in the full documentation it is stated that
The first row in the file is very likely the northernmost one, i.e. if we are interested in row 500 from the lower edge, we actually have to look at row
from the start if the file. Our grid cell is number
from the start of the file (i.e. skip 700 rows, and in the 701st one take sample 1104). Two bytes per sample means we have to skip the first 1683606 bytes in the file and then read two bytes in order to get our grid cell. The data is big-endian, which means that you need to swap the two bytes on e.g. Intel platforms.
Sample program
A simplistic Python program to retrieve the right data would look like this (see the docs for use of the struct module):
Note that efficient data retrieval would have to look a little more sophisticated (e.g. not opening the file for each and every sample).
Alternatives
You could also use a program which can read the .hgt files out of the box. But that is boring.