Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ab9b71

Browse files
committed
+ neighbour_points()
1 parent faf1a86 commit 4ab9b71

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

srtm/data.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ def get_row_and_column(self, latitude, longitude):
231231
return mod_math.floor((self.latitude + 1 - latitude) * float(self.square_side - 1)), \
232232
mod_math.floor((longitude - self.longitude) * float(self.square_side - 1))
233233

234+
def get_neighbour_points(self, latitude, longitude):
235+
d = 1. / self.square_side
236+
d_meters = d * mod_utils.ONE_DEGREE
237+
238+
row, column = self.get_row_and_column(latitude, longitude)
239+
240+
point_1 = self.latitude + 1 - row * d , self.longitude + column * d
241+
point_2 = self.latitude + 1 - (row + 1) * d, self.longitude + column * d
242+
point_3 = self.latitude + 1 - row * d , self.longitude + (column + 1) * d
243+
point_4 = self.latitude + 1 - (row + 1) * d, self.longitude + (column + 1) * d
244+
245+
assert latitude <= point_1[0] and point_1[1] <= longitude
246+
assert point_2[0] <= latitude and point_2[1] <= longitude
247+
assert latitude <= point_3[0] and longitude <= point_3[1]
248+
assert point_2[0] <= latitude and longitude <= point_4[1]
249+
250+
return point_1, point_2, point_3, point_4
251+
234252
def get_elevation(self, latitude, longitude, approximate=None):
235253
"""
236254
If approximate is True then only the points from SRTM grid will be
@@ -256,20 +274,8 @@ def approximation(self, latitude, longitude):
256274
Dummy approximation with nearest points. The nearest the neighbour the
257275
more important will be its elevation.
258276
"""
259-
d = 1. / self.square_side
260-
d_meters = d * mod_utils.ONE_DEGREE
261-
262-
row, column = self.get_row_and_column(latitude, longitude)
263-
264-
point_1 = self.latitude + 1 - row * d , self.longitude + column * d
265-
point_2 = self.latitude + 1 - (row + 1) * d, self.longitude + column * d
266-
point_3 = self.latitude + 1 - row * d , self.longitude + (column + 1) * d
267-
point_4 = self.latitude + 1 - (row + 1) * d, self.longitude + (column + 1) * d
268277

269-
assert latitude <= point_1[0] and point_1[1] <= longitude
270-
assert point_2[0] <= latitude and point_2[1] <= longitude
271-
assert latitude <= point_3[0] and longitude <= point_3[1]
272-
assert point_2[0] <= latitude and longitude <= point_4[1]
278+
point_1, point_2, point_3, point_4 = self.get_neighbour_points(latitude, longitude)
273279

274280
# Since the less the distance => the more important should be the
275281
# distance of the point, we'll use d-distance as importance coef

0 commit comments

Comments
 (0)