added _pixels_to_lon helper

This commit is contained in:
Chris Pham
2018-01-18 13:00:53 -08:00
parent 6e540dfe06
commit f4622bc64b

View File

@@ -1,8 +1,11 @@
''' '''
Mapping.py: Objected Orientated Google Maps for Python Mapping.py: Objected Orientated Google Maps for Python
Written by Chris Pham
Copyright OSURC, orginal code from GooMPy by Alec Singer and Simon D. Levy Copyright OSURC, orginal code from GooMPy by Alec Singer and Simon D. Levy
This code is free software: you can redistribute it and/or modify This code is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
@@ -73,7 +76,7 @@ class GMapsStitcher(object):
def _pixels_to_degrees(self, pixels, zoom): def _pixels_to_degrees(self, pixels, zoom):
return pixels * 2 ** (21-zoom) return pixels * 2 ** (21-zoom)
def _grab_tile(self, sleeptime): def _grab_tile(self, sleeptime=0):
# Make the url string for polling # Make the url string for polling
# GET request header gets appended to the string # GET request header gets appended to the string
urlbase = 'https://maps.googleapis.com/maps/api/staticmap?' urlbase = 'https://maps.googleapis.com/maps/api/staticmap?'
@@ -99,6 +102,13 @@ class GMapsStitcher(object):
if not os.path.exists('Resources/Maps'): if not os.path.exists('Resources/Maps'):
os.mkdir('Resources/Maps') os.mkdir('Resources/Maps')
tile_object.save(filename) tile_object.save(filename)
#Added to prevent timeouts on Google Servers
time.sleep(sleeptime)
return tile_object return tile_object
def _pixels_to_lon(self, iterator, lon_pixels):
# Magic Lines, no idea
degrees = _pixels_to_degrees(((iterator) - self.num_tiles / 2) * _TILESIZE, self.zoom)
return math.degrees((lon_pixels + degrees - _EARTHPIX) / _pixrad)