0

I am trying iterate through the data(elevation) from .hgt file. I have attached the codes which i used to get the elevation from the file.

from gmalthgtparser import HgtParser    
hgt_file='N09E076.hgt'
with HgtParser(hgt_file) as parser:
    alt = parser.get_elevation((9.666673719181665,76.30757542014408))
    print(alt)

The output of the above code will be : (1200, 1108, 7)

So here the input is given by the user with exact longitude and latitude. I want it to iterate through all the coordinates under some range and print each coordinates elevation and it should be saved as an excel file.

closed as off-topic by user2856, whyzar, csk, Andre Silva, Erik Apr 23 at 9:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you edit your question to clarify what you mean by "iterate through all the coordinates under some range". – user2856 Apr 18 at 8:17
  • i mean i need to get the values by iterating through different longitudes and latitudes. Those values given in the parser.get_elevation is longitude and latitude respectively....so for different longitudes and latitudes i will get the elevation according to that – sreeramp96 Apr 18 at 16:51
  • Yes but what lon/lats do you want to iterate through? Where do you get them from? It's basically for lon, lat in [(lon, lat), (lon, lat), (etc...)]: – user2856 Apr 19 at 9:36
  • i am trying to give for loops for longitudes and latitudes so that for different location i get the height – sreeramp96 Apr 20 at 2:35
  • Yes I understand that. I'll ask again, what lon/lats do you want to iterate through and where do you get them from? As I said, it's just for lon, lat in [(a lon, a lat), (another lon, another lat), (etc...)]: then alt = parser.get_elevation((lon, lat)) – user2856 Apr 20 at 3:01
0
import random
from gmalthgtparser import HgtParser    

hgt_file='N09E076.hgt'
minlat, minlon = 9, 76

# 50 random samples
with HgtParser(hgt_file) as parser:
    for i in range(50):  # 50 samples
        lat = random.uniform(minlat, minlat+1)
        lon = random.uniform(minlon, minlon+1)
        alt = parser.get_elevation((lat,lon))
        print(lat, lon, alt)

# Iterate over all the elevation values inside a file.

with HgtParser(hgt_file) as parser:
   for alt in parser.get_value_iterator():
       print(alt)

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