mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 18:21:15 +00:00
Add testing file with updated gitignore for jpgs
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -89,4 +89,7 @@ ENV/
|
|||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
# Google API Key
|
# Google API Key
|
||||||
ground_station/resources/core/key
|
ground_station/resources/core/key
|
||||||
|
|
||||||
|
# Map Images
|
||||||
|
*.jpg
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ ReWritten 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
|
||||||
License, or (at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
This code is distributed in the hope that it will be useful,
|
This code is distributed in the hope that it will be useful,
|
||||||
@@ -27,21 +27,17 @@ from io import StringIO, BytesIO
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
import signing
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# Constants
|
# Constants
|
||||||
#####################################
|
#####################################
|
||||||
<<<<<<< 1bd9af00f206c528febfe9b024e50b8bd4ee73fb
|
|
||||||
<<<<<<< 666f522bf5947794d802e8cbbf221ac004fc4eed
|
|
||||||
=======
|
|
||||||
=======
|
|
||||||
_KEYS = []
|
_KEYS = []
|
||||||
>>>>>>> Fixed to fit PEP
|
|
||||||
file_pointer = open('key', 'w')
|
file_pointer = open('key', 'w')
|
||||||
for i in file_pointer:
|
for i in file_pointer:
|
||||||
_KEYS.append(file_pointer.readline().rstrip())
|
_KEYS.append(file_pointer.readline().rstrip())
|
||||||
file_pointer.close()
|
file_pointer.close()
|
||||||
>>>>>>> fixed fp naming conventions
|
|
||||||
|
|
||||||
# Number of pixels in half the earth's circumference at zoom = 21
|
# Number of pixels in half the earth's circumference at zoom = 21
|
||||||
_EARTHPIX = 268435456
|
_EARTHPIX = 268435456
|
||||||
@@ -54,6 +50,13 @@ _GRABRATE = 4
|
|||||||
# Pixel Radius of Earth for calculations
|
# Pixel Radius of Earth for calculations
|
||||||
_PIXRAD = _EARTHPIX / math.pi
|
_PIXRAD = _EARTHPIX / math.pi
|
||||||
|
|
||||||
|
file_pointer = open('key', 'r')
|
||||||
|
for i in file_pointer:
|
||||||
|
_KEYS.append(i.rstrip())
|
||||||
|
file_pointer.close()
|
||||||
|
|
||||||
|
print _KEYS
|
||||||
|
|
||||||
|
|
||||||
class GMapsStitcher(object):
|
class GMapsStitcher(object):
|
||||||
def __init__(self, width, height,
|
def __init__(self, width, height,
|
||||||
@@ -85,11 +88,11 @@ class GMapsStitcher(object):
|
|||||||
# 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?'
|
||||||
urlbase += 'center=%f%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s&signature=%s'
|
urlbase += 'center=%f,%f&zoom=%d&maptype=%s&size=%dx%d&format=jpg&key=%s'
|
||||||
|
|
||||||
# Fill the formatting
|
# Fill the formatting
|
||||||
specs = latitude, longitude, self.zoom, self.maptype, _TILESIZE, _KEYS[0], _KEYS[1]
|
specs = latitude, longitude, self.zoom, self.maptype, _TILESIZE, _TILESIZE, _KEYS[0]
|
||||||
filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s_%s' % specs) + '.jpg'
|
filename = 'Resources/Maps/' + ('%f_%f_%d_%s_%d_%d_%s' % specs) + '.jpg'
|
||||||
|
|
||||||
# Tile Image object
|
# Tile Image object
|
||||||
tile_object = None
|
tile_object = None
|
||||||
@@ -101,8 +104,10 @@ class GMapsStitcher(object):
|
|||||||
else:
|
else:
|
||||||
# make the url
|
# make the url
|
||||||
url = urlbase % specs
|
url = urlbase % specs
|
||||||
|
print url
|
||||||
result = urllib2.Request(url).read()
|
url = signing.sign_url(url, _KEYS[1])
|
||||||
|
print url
|
||||||
|
result = urllib2.urlopen(urllib2.Request(url)).read()
|
||||||
tile_object = PIL.Image.open(BytesIO(result))
|
tile_object = PIL.Image.open(BytesIO(result))
|
||||||
if not os.path.exists('Resources/Maps'):
|
if not os.path.exists('Resources/Maps'):
|
||||||
os.mkdir('Resources/Maps')
|
os.mkdir('Resources/Maps')
|
||||||
@@ -123,14 +128,14 @@ class GMapsStitcher(object):
|
|||||||
temp = math.atan(math.exp(((lat_pixels + degree) - _EARTHPIX))/ _PIXRAD)
|
temp = math.atan(math.exp(((lat_pixels + degree) - _EARTHPIX))/ _PIXRAD)
|
||||||
return math.degrees(math.pi / 2 - 2 * temp)
|
return math.degrees(math.pi / 2 - 2 * temp)
|
||||||
|
|
||||||
def fetch_tiles(self,):
|
def fetch_tiles(self):
|
||||||
# cap floats to precision amount
|
# cap floats to precision amount
|
||||||
self.latitude = self._fast_round(self.latitude, _DEGREE_PRECISION)
|
self.latitude = self._fast_round(self.latitude, _DEGREE_PRECISION)
|
||||||
self.longitude = self._fast_round(self.longitude, _DEGREE_PRECISION)
|
self.longitude = self._fast_round(self.longitude, _DEGREE_PRECISION)
|
||||||
|
|
||||||
# number of tiles required to go from center latitude to desired radius in meters
|
# number of tiles required to go from center latitude to desired radius in meters
|
||||||
if self.radius_meters is not None:
|
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._pixels_to_meters() / (_TILESIZE / 2. / self.radius_meters)))
|
||||||
|
|
||||||
lon_pixels = _EARTHPIX + self.longitude * math.radians(_PIXRAD)
|
lon_pixels = _EARTHPIX + self.longitude * math.radians(_PIXRAD)
|
||||||
|
|
||||||
|
|||||||
5
ground_station/resources/core/mappingtest.py
Normal file
5
ground_station/resources/core/mappingtest.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import mapping
|
||||||
|
|
||||||
|
obj = mapping.GMapsStitcher(10000, 10000, 44.57078, -123.275998, 21, 'terrain', 200)
|
||||||
|
|
||||||
|
obj.fetch_tiles()
|
||||||
53
ground_station/resources/core/signing.py
Normal file
53
ground_station/resources/core/signing.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
""" Signs a URL using a URL signing secret """
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
|
import base64
|
||||||
|
import urlparse
|
||||||
|
|
||||||
|
def sign_url(input_url=None, secret=None):
|
||||||
|
""" Sign a request URL with a URL signing secret.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
from urlsigner import sign_url
|
||||||
|
|
||||||
|
signed_url = sign_url(input_url=my_url, secret=SECRET)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_url - The URL to sign
|
||||||
|
secret - Your URL signing secret
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The signed request URL
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not input_url or not secret:
|
||||||
|
raise Exception("Both input_url and secret are required")
|
||||||
|
|
||||||
|
url = urlparse.urlparse(input_url)
|
||||||
|
|
||||||
|
# We only need to sign the path+query part of the string
|
||||||
|
url_to_sign = url.path + "?" + url.query
|
||||||
|
|
||||||
|
# Decode the private key into its binary format
|
||||||
|
# We need to decode the URL-encoded private key
|
||||||
|
decoded_key = base64.urlsafe_b64decode(secret)
|
||||||
|
|
||||||
|
# Create a signature using the private key and the URL-encoded
|
||||||
|
# string using HMAC SHA1. This signature will be binary.
|
||||||
|
signature = hmac.new(decoded_key, url_to_sign, hashlib.sha1)
|
||||||
|
|
||||||
|
# Encode the binary signature into base64 for use within a URL
|
||||||
|
encoded_signature = base64.urlsafe_b64encode(signature.digest())
|
||||||
|
|
||||||
|
original_url = url.scheme + "://" + url.netloc + url.path + "?" + url.query
|
||||||
|
|
||||||
|
# Return signed URL
|
||||||
|
return original_url + "&signature=" + encoded_signature
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
input_url = raw_input("URL to Sign: ")
|
||||||
|
secret = raw_input("URL signing secret: ")
|
||||||
|
print "Signed URL: " + sign_url(input_url, secret)
|
||||||
Reference in New Issue
Block a user