Added _pixels_to_lat

This commit is contained in:
Chris Pham
2018-01-18 13:21:38 -08:00
parent a35691bf59
commit 3a960d44f7

View File

@@ -1,11 +1,9 @@
''' '''
Mapping.py: Objected Orientated Google Maps for Python Mapping.py: Objected Orientated Google Maps for Python
ReWritten by Chris Pham
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
@@ -25,10 +23,10 @@ along with this code. If not, see <http://www.gnu.org/licenses/>.
# Python native imports # Python native imports
import math import math
import urllib2 import urllib2
import PIL.Image
from io import StringIO, BytesIO from io import StringIO, BytesIO
import os import os
import time import time
import PIL.Image
##################################### #####################################
# Constants # Constants
@@ -67,7 +65,7 @@ class GMapsStitcher(object):
self.maptype = maptype self.maptype = maptype
self.radius_meters = radius_meters self.radius_meters = radius_meters
self.num_tiles = num_tiles self.num_tiles = num_tiles
def _new_image(self): def _new_image(self):
return PIL.Image.new('RGB', (self.width, self.height)) return PIL.Image.new('RGB', (self.width, self.height))
@@ -83,7 +81,7 @@ class GMapsStitcher(object):
urlbase = 'https://maps.googleapis.com/maps/api/staticmap?' urlbase = 'https://maps.googleapis.com/maps/api/staticmap?'
urlbase += 'center=%f%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s' urlbase += 'center=%f%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s'
# Fill the formatting # Fill the formatting
specs = self.latitude, self.longitude, self.zoom, self.maptype, _TILESIZE, _KEY specs = self.latitude, self.longitude, self.zoom, self.maptype, _TILESIZE, _KEY
filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s' % specs) + '.jpg' filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s' % specs) + '.jpg'
@@ -92,7 +90,7 @@ class GMapsStitcher(object):
if os.path.isfile(filename): if os.path.isfile(filename):
tile_object = PIL.Image.open(filename) tile_object = PIL.Image.open(filename)
# If file on filesystem # If file on filesystem
else: else:
# make the url # make the url
@@ -113,3 +111,7 @@ class GMapsStitcher(object):
degrees = self._pixels_to_degrees(((iterator) - self.num_tiles / 2) * _TILESIZE, self.zoom) degrees = self._pixels_to_degrees(((iterator) - self.num_tiles / 2) * _TILESIZE, self.zoom)
return math.degrees((lon_pixels + degrees - _EARTHPIX) / _pixrad) return math.degrees((lon_pixels + degrees - _EARTHPIX) / _pixrad)
def _pixels_to_lat(self, iterator, lat_pixels):
# Magic Lines
degree = self._pixels_to_degrees((iterator - self.num_tiles / 2) * _TILESIZE, self.zoom)
return math.degrees(math.pi / 2 - 2 * math.atan(math.exp(((lat_pixels + degree) - _EARTHPIX) / _pixrad)))