Skip to content

Instantly share code, notes, and snippets.

@helxsz
Last active August 30, 2017 09:13
Show Gist options
  • Save helxsz/fcef67ec10a6bb694b52c2fa2df39405 to your computer and use it in GitHub Desktop.
Save helxsz/fcef67ec10a6bb694b52c2fa2df39405 to your computer and use it in GitHub Desktop.
google satellite map
53.380827, -2.975304
53.385516, -2.981218
53.385041, -2.980835
53.384792, -2.980543
53.384661, -2.982629
53.384059, -2.981964
53.383523, -2.981326
53.383448, -2.979853
53.383102, -2.979456
53.383349, -2.978617
53.384051, -2.977174
53.381798, -2.977485
53.382078, -2.976498
53.381800, -2.974765
53.381320, -2.974014
53.380949, -2.975428
53.380600, -2.974875
53.380368, -2.974358
53.379679, -2.972994
53.379479, -2.973431
53.379453, -2.971449
53.378737, -2.972560
53.378697, -2.971393
53.378156, -2.972031
53.377767, -2.971803
53.379889, -2.970801
53.394545, -2.973757
53.396004, -2.973620
53.396837, -2.974038
53.397293, -2.974079
53.397946, -2.974216
53.398397, -2.974060
53.399155, -2.971968
53.400001, -2.970892
53.404606, -2.965072
53.404280, -2.965134
53.404400, -2.966327
53.404419, -2.967041
53.406939, -2.964750
53.407268, -2.964342
53.407761, -2.965643
53.407599, -2.967317
53.408026, -2.967405
53.409594, -2.967354
53.409105, -2.968714
53.409214, -2.969848
53.409632, -2.969821
53.410662, -2.969339
53.410035, -2.968456
53.411353, -2.968628
53.411429, -2.967230
53.411501, -2.966377
53.411206, -2.966305
53.414037, -2.969480
53.414360, -2.969643
53.413900, -2.962092
53.413430, -2.961829
53.413244, -2.962124
53.414781, -2.960977
53.414966, -2.960395
53.409336, -2.960562
53.410031, -2.961984
53.409750, -2.961877
53.407822, -2.960333
53.407626, -2.960086
53.407626, -2.959638
53.407589, -2.959207
53.406965, -2.958654
53.405883, -2.960553
53.405891, -2.960161
53.405723, -2.959805
53.403487, -2.960215
53.403719, -2.959421
53.402760, -2.966704
53.401528, -2.980040
import requests
import shutil
import os
import json
project_root = '/home/xisizhe/Desktop/google_map_parking'
# http://maps.googleapis.com/maps/api/staticmap?center=55,-3&zoom=15&scale=false&size=600x300&maptype=roadmap&format=png&visual_refresh=true
# http://maps.googleapis.com/maps/api/staticmap?center=53.393156,-2.979223&zoom=20&scale=false&size=300x300&maptype=satellite&format=png&visual_refresh=true
def googleStaticMapAPI( coordinate, image_index , data_root ):
r = requests.get("http://maps.googleapis.com/maps/api/staticmap?center="+ coordinate +"&zoom=20&scale=true&size=600x600&maptype=satellite&format=png&visual_refresh=true&key=AIzaSyAIICzKZ6iuGOiAYwl8FmE2eihbiYf0aK0", stream=True)
if r.status_code == 200:
location = data_root+ '/' +str(image_index)+".png"
with open(location, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
#print 'download success' , location
else:
print 'download error', r.status_code
def downloadParking():
coordinatesfile = os.path.join( project_root, 'parking_url.txt')
data_root = os.path.join( project_root, 'data')
with open(coordinatesfile) as f:
index = 0
for line in f:
line = line.strip()
print line
coordinate = line
googleStaticMapAPI(coordinate, index, data_root)
index = index + 1
def googleSnapRoadAPI(begin , end):
arr = []
data_root = os.path.join( project_root, 'data2')
r = requests.get("https://roads.googleapis.com/v1/snapToRoads?path="+begin+"|"+end+"&interpolate=true&key=AIzaSyAIICzKZ6iuGOiAYwl8FmE2eihbiYf0aK0", stream=True)
if r.status_code == 200:
#print r.json()
#print r.json()['snappedPoints']
points = r.json()['snappedPoints']
index = 0
for i in points:
#print i
#print 'roadapi',i['location']['latitude'] , i['location']['longitude']
latitude = i['location']['latitude']
longitude = i['location']['longitude']
coordinate = str(latitude) + ','+ str(longitude)
arr.append(coordinate)
index = index + 1
return arr
def googleDirectionAPI(begin , end):
arr = []
r = requests.get("https://maps.googleapis.com/maps/api/directions/json?origin=53.409666,-2.982018&destination=53.405576,-2.967469&key=AIzaSyAIICzKZ6iuGOiAYwl8FmE2eihbiYf0aK0", stream=True,verify=False)
if r.status_code == 200:
#print r.json()
routes = r.json()['routes']
for route in routes:
legs = route['legs']
for leg in legs:
latitude = leg['start_location']['lat']
longitude = leg['start_location']['lng']
coordinate = str(latitude) + ','+ str(longitude)
arr.append(coordinate)
index = 0
for step in leg['steps']:
#print i
latitude = step['end_location']['lat']
longitude = step['end_location']['lng']
coordinate = str(latitude) + ','+ str(longitude)
arr.append(coordinate)
index = index + 1
#print coordinate
return arr
#googleSnapRoadAPI("53.407028,-2.978853" , "53.40678759999999,-2.9792905")
def getAllSnaps():
arr = googleDirectionAPI("","")
allarray = []
i = 0
for item in arr:
if i == 0:
start = item
i = i + 1
else:
end = item
mylist = googleSnapRoadAPI(start, end)
print "......",len(mylist)
allarray.extend(mylist)
start = end
#print item
return allarray
def getAllLittle(arr):
allarray = []
i = 0
for item in arr:
if i == 0:
start = item
i = i + 1
else:
end = item
distance = calculateDistanceAPI(start, end)
print 'distance ', distance
if(distance/5 >= 2):
section = distance/5
start = end
return allarray
def calculateDistanceAPI(start, end):
r = requests.get("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins="+start+"&destinations="+end+"&key=AIzaSyAIICzKZ6iuGOiAYwl8FmE2eihbiYf0aK0", stream=True,verify=False)
distance = 100000000000
if r.status_code == 200:
print r.json()
distance = r.json()['rows'][0]['elements'][0]['distance']['value']
return distance
'''''
def angleFromCoordinate(start, end):
arr1 = start.split(',')
arr2 = end.split(',')
lat1 = float(arr1[0])
lon1 = float(arr1[0])
lat2 = float(arr2[0])
lon2 = float(arr2[0])
dLon = (lon2 - lon1)
dLat = (lat2 - lat1)
y = math.sin(dLon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1)
* math.cos(lat2) * math.cos(dLon)
brng = math.atan2(y, x);
return brng
def arrayFromCoordinate(start, end, section):
arr1 = start.split(',')
arr2 = end.split(',')
lat1 = float(arr1[0])
lon1 = float(arr1[0])
lat2 = float(arr2[0])
lon2 = float(arr2[0])
dLon = (lon2 - lon1)
dLat = (lat2 - lat1)
dLon_difference = dLon/section
dLat_difference = dLat/section
arr = []
for i in section:
if i>=1:
next_Lon = lat1 + i*dLon_difference
next_Lat = lon2 + i*dLat_difference
'''''
def downloadRoutesImage():
data_root = os.path.join( project_root, 'data2')
allarray = getAllSnaps()
allarray = getAllLittle(allarray)
print len(allarray)
'''''
index = 0
for coordinate in allarray:
print "point in ", coordinate
googleStaticMapAPI(coordinate, index, data_root)
index = index + 1
'''''
downloadRoutesImage()
#downloadParking()
#calculateDistanceAPI()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment