22import math
33import os
44from pathlib import Path
5- from typing import NamedTuple , Dict , Tuple , Generator
5+ from typing import NamedTuple , Dict , Tuple , Generator , List
66from zipfile import ZipFile
77
88HGT_DIR = Path (os .environ ["SRTM_DIR" ])
@@ -229,15 +229,35 @@ def get_elevation_profile(
229229 end_latitude : float ,
230230 end_longitude : float ,
231231 ):
232- # y = mx + c
233- pass
232+ # TODO: Remove magic number to setting
233+ def to_int (lat_lng : float ) -> int :
234+ return round (lat_lng * 1200 )
235+
236+ def to_float (lat_lng_int : int ) -> float :
237+ return lat_lng_int / 1200
238+
239+ points = points_on_line (
240+ x1 = to_int (start_latitude ),
241+ y1 = to_int (start_longitude ),
242+ x2 = to_int (end_latitude ),
243+ y2 = to_int (end_longitude ),
244+ )
245+ converted_points = [(to_float (x ), to_float (y )) for x , y in points ]
246+
247+ elevations = []
248+ for latitude , longitude in converted_points :
249+ elevations .append (self .get_height_for_latitude_and_longitude (
250+ latitude , longitude
251+ ))
252+ return elevations
234253
235254
236255def points_on_line (
237- x1 : float , y1 : float , x2 : float , y2 : float
238- ) -> Generator [Tuple [float , float ], None , None ]:
256+ x1 : int , y1 : int , x2 : int , y2 : int
257+ ) -> List [Tuple [int , int ]]:
258+ # Credit: https://stackoverflow.com/questions/25837544
239259 points = []
240- issteep = abs (y2 - y1 ) > abs (x2 - x1 )
260+ issteep = abs (y2 - y1 ) > abs (x2 - x1 )
241261 if issteep :
242262 x1 , y1 = y1 , x1
243263 x2 , y2 = y2 , x2
@@ -247,25 +267,25 @@ def points_on_line(
247267 y1 , y2 = y2 , y1
248268 rev = True
249269 deltax = x2 - x1
250- deltay = abs (y2 - y1 )
270+ deltay = abs (y2 - y1 )
251271 error = int (deltax / 2 )
252272 y = y1
253273 ystep = None
254274 if y1 < y2 :
255275 ystep = 1
256276 else :
257277 ystep = - 1
258-
259- x_range = range (x1 , x2 + 1 )
260- if rev :
261- x_range = reversed (x_range )
262-
263- for x in x_range :
278+ for x in range (x1 , x2 + 1 ):
264279 if issteep :
265- yield y , x
280+ points . append (( y , x ))
266281 else :
267- yield x , y
282+ points . append (( x , y ))
268283 error -= deltay
269284 if error < 0 :
270285 y += ystep
271286 error += deltax
287+ # Reverse the list if the coordinates were reversed
288+ if rev :
289+ points .reverse ()
290+ return points
291+
0 commit comments