From 4a66dbc0b5954672d4377a1c9e07c53ccd1d7323 Mon Sep 17 00:00:00 2001 From: Chris Pham Date: Sat, 3 Feb 2018 14:06:46 -0800 Subject: [PATCH] Moved pixels_to_meters to Helper --- ground_station/resources/core/MapHelper.py | 8 +++++++- ground_station/resources/core/mapping.py | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ground_station/resources/core/MapHelper.py b/ground_station/resources/core/MapHelper.py index 86724fc..e9c3d98 100644 --- a/ground_station/resources/core/MapHelper.py +++ b/ground_station/resources/core/MapHelper.py @@ -1,4 +1,5 @@ import PIL.Image +import math class MapHelper(object): @@ -12,4 +13,9 @@ class MapHelper(object): @staticmethod def pixels_to_degrees(pixels, zoom): - return pixels * 2 ** (21-zoom) \ No newline at end of file + return pixels * 2 ** (21-zoom) + + @staticmethod + def pixels_to_meters(latitude, zoom): + # https://groups.google.com/forum/#!topic/google-maps-js-api-v3/hDRO4oHVSeM + return 2 ** zoom / (156543.03392 * math.cos(math.radians(latitude))) \ No newline at end of file diff --git a/ground_station/resources/core/mapping.py b/ground_station/resources/core/mapping.py index 4c44881..8aa6fc9 100644 --- a/ground_station/resources/core/mapping.py +++ b/ground_station/resources/core/mapping.py @@ -89,10 +89,6 @@ class GMapsStitcher(object): string_builder += "LatLong of Southeast Corner: %4f, %4f\n" % (self.southeast) return string_builder - def _pixels_to_meters(self): - # https://groups.google.com/forum/#!topic/google-maps-js-api-v3/hDRO4oHVSeM - return 2 ** self.zoom / (156543.03392 * math.cos(math.radians(self.latitude))) - def _grab_tile(self, longitude, latitude, sleeptime=0): # Make the url string for polling # GET request header gets appended to the string @@ -141,7 +137,7 @@ class GMapsStitcher(object): # number of tiles required to go from center latitude to desired radius in meters if self.radius_meters is not None: - self.num_tiles = int(round(2*self._pixels_to_meters() / (_TILESIZE / 2. / self.radius_meters))) + self.num_tiles = int(round(2*self.helper.pixels_to_meters(self.latitude, self.zoom) / (_TILESIZE / 2. / self.radius_meters))) lon_pixels = _EARTHPIX + self.longitude * math.radians(_PIXRAD)