@@ -92,8 +92,8 @@ def retrieve_or_load_file_data(self, file_name):
92
92
data_file_name = file_name
93
93
zip_data_file_name = '{0}.zip' .format (file_name )
94
94
95
- if mod_path .exists (data_file_name ):
96
- return mod_path .file_handler .read (data_file_name )
95
+ if self . file_handler .exists (data_file_name ):
96
+ return self .file_handler .read (data_file_name )
97
97
elif self .file_handler .exists (zip_data_file_name ):
98
98
data = self .file_handler .read (zip_data_file_name )
99
99
return mod_utils .unzip (data )
@@ -259,22 +259,39 @@ def approximation(self, latitude, longitude):
259
259
d = 1. / self .square_side
260
260
d_meters = d * mod_utils .ONE_DEGREE
261
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
268
+
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 ]
273
+
262
274
# Since the less the distance => the more important should be the
263
275
# distance of the point, we'll use d-distance as importance coef
264
276
# here:
265
- importance_1 = d_meters - mod_utils .distance (latitude + d , longitude , latitude , longitude )
266
- elevation_1 = self .geo_elevation_data .get_elevation (latitude + d , longitude , approximate = False )
277
+ distance_1 = mod_utils .distance (point_1 [0 ], point_1 [1 ], latitude , longitude )
278
+ elevation_1 = self .geo_elevation_data .get_elevation (point_1 [0 ], point_1 [1 ], approximate = False )
279
+
280
+ distance_2 = mod_utils .distance (point_2 [0 ], point_2 [1 ], latitude , longitude )
281
+ elevation_2 = self .geo_elevation_data .get_elevation (point_2 [0 ], point_2 [1 ], approximate = False )
282
+
283
+ distance_3 = mod_utils .distance (point_3 [0 ], point_3 [1 ], latitude , longitude )
284
+ elevation_3 = self .geo_elevation_data .get_elevation (point_3 [0 ], point_3 [1 ], approximate = False )
267
285
268
- importance_2 = d_meters - mod_utils .distance (latitude - d , longitude , latitude , longitude )
269
- elevation_2 = self .geo_elevation_data .get_elevation (latitude - d , longitude , approximate = False )
286
+ distance_4 = mod_utils .distance (point_4 [ 0 ], point_4 [ 1 ] , latitude , longitude )
287
+ elevation_4 = self .geo_elevation_data .get_elevation (point_4 [ 0 ], point_4 [ 1 ] , approximate = False )
270
288
271
- importance_3 = d_meters - mod_utils .distance (latitude , longitude + d , latitude , longitude )
272
- elevation_3 = self .geo_elevation_data .get_elevation (latitude , longitude + d , approximate = False )
289
+ max_distance = max (distance_1 , distance_2 , distance_3 , distance_4 )
273
290
274
- importance_4 = d_meters - mod_utils . distance ( latitude , longitude - d , latitude , longitude )
275
- elevation_4 = self . geo_elevation_data . get_elevation ( latitude , longitude - d , approximate = False )
276
- # TODO(TK) Check if coordinates inside the same file, and only the decide if to xall
277
- # self.geo_elevation_data.get_elevation or just self.get_elevation
291
+ importance_1 = max_distance - distance_1
292
+ importance_2 = max_distance - distance_2
293
+ importance_3 = max_distance - distance_3
294
+ importance_4 = max_distance - distance_4
278
295
279
296
if elevation_1 == None or elevation_2 == None or elevation_3 == None or elevation_4 == None :
280
297
elevation = self .get_elevation (latitude , longitude , approximate = False )
0 commit comments