Moved pixels_to_meters to Helper

This commit is contained in:
Chris Pham
2018-02-03 14:06:46 -08:00
parent 10c9dc8451
commit 4a66dbc0b5
2 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import PIL.Image
import math
class MapHelper(object):
@@ -13,3 +14,8 @@ class MapHelper(object):
@staticmethod
def pixels_to_degrees(pixels, zoom):
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)))

View File

@@ -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)