-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelevation.py
More file actions
36 lines (31 loc) · 1.11 KB
/
elevation.py
File metadata and controls
36 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import necessary packages
import json
import requests
import pandas as pd
def find_elevation(lat, lng) ->str :
"""
Findig the elevation from the lat long
"""
url = f"https://api.open-elevation.com/api/v1/lookup?locations={lat},{lng}"
print(url)
value = {}
try:
response = requests.get(url, verify=False)
value = json.loads(response.content.decode('utf-8'))
print(value)
except Exception as e:
print(f"Some error occuered. Error is {e}")
value['result'][0]["elevation"] = 0
return value["results"][0]["elevation"]
def main():
"""
Main function
1. Read the input file from the folder
2. Pass each row of panda dataframe to find_elevation function
3. Create a new file containing elevated information
"""
data = pd.read_csv("data_set/Lat_Long_Data.csv") # My input file is in data_set folder
data["elevation"] = data.apply(lambda x : find_elevation(x["lat"], x["lng"]), axis=1)
data.to_csv("data_set/modified_Lat_Long_Data.csv", index=False) # my outpul will be in data_set folder
if __name__ == '__main__':
main()