-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathelevation_data.py
More file actions
65 lines (48 loc) · 1.95 KB
/
Copy pathelevation_data.py
File metadata and controls
65 lines (48 loc) · 1.95 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import matplotlib.pyplot as plt
import requests
import json
# API_KEY = os.getenv("ELEVATION_API_KEY")
def get_sample_airmap_data():
""" Gets a grid of elevation data centered at a predefined point
Returns
-------
stats : indexable object in format {'max':649, 'min':453, 'avg':536.7581735159818}
Contains the maximum, minimum and average elevations in the region.
carpet : 2D array of integers
Represents the elevation values between the two predefined points,
with a spatial resolution of 1 arc second.
"""
url = "https://api.airmap.com/elevation/v1/ele/carpet?points=49.9960329253738,14.128741875966284,49.97503584462879,14.145005515530571"
response = requests.get(url)
response = response.json()
stats = response['data']['stats']
carpet = response['data']['carpet']
return stats, carpet
def get_airmap_data(lat, lng):
""" Gets a grid of elevation data centered around a target point
Parameters
----------
lat :
Latitude of the target point. Limited to between 56 degrees South
and 60 degrees North.
lng :
Longitude of the target point.
Returns
-------
stats : indexable object in format {'max':649, 'min':453, 'avg':536.7581735159818}
Contains the maximum, minimum and average elevations in the region.
carpet : 2D array of integers
Represents the elevation values in a square around the specified point
with a spatial resolution of 1 arc second.
"""
url = "https://api.airmap.com/elevation/v1/ele/carpet?points={},{},{},{}".format(lat+0.01, lng+0.01, lat-0.01, lng-0.01)
response = requests.get(url)
response = response.json()
stats = response['data']['stats']
carpet = response['data']['carpet']
return stats, carpet
if __name__ == "__main__":
stats, carpet = get_airmap_data(47.6062, 122.3321)
plt.imshow(carpet)
plt.show()