forked from apwheele/Blog_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleDrawImages_StreetView.py
More file actions
71 lines (59 loc) · 2.9 KB
/
ExampleDrawImages_StreetView.py
File metadata and controls
71 lines (59 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#This code draws images running along a street in Google street view
#Need to submit lat-lon and orientation (can calculate those in a GIS from street centerline files)
#For grabbing sidewalk, found that 40 feet between photos was a good distance to prevent repeats
import urllib, os, json
#see https://andrewpwheeler.wordpress.com/2015/12/28/using-python-to-grab-google-street-view-imagery/
#key is a global for use in the functions
key = "&key=" + "!!!!!!!!!!!!!YourAPIHere!!!!!!!!!!!!!!!!"
DownLoc = r'!!!!!!!!!!!!!WhereYouWantTheImagesDownloaded!!!!!!!!!!!!!'
#set the path that you want to download the images into
def MetaParse(MetaUrl):
response = urllib.urlopen(MetaUrl)
jsonRaw = response.read()
jsonData = json.loads(jsonRaw)
#return jsonData
if jsonData['status'] == "OK":
if 'date' in jsonData:
return (jsonData['date'],jsonData['pano_id']) #sometimes it does not have a date!
else:
return (None,jsonData['pano_id'])
else:
return (None,None)
PrevImage = [] #Global list that has previous images sampled, memoization kindof
def GetStreetLL(Lat,Lon,Head,File,SaveLoc):
base = r"https://maps.googleapis.com/maps/api/streetview"
size = r"?size=1200x800&fov=60&location="
end = str(Lat) + "," + str(Lon) + "&heading=" + str(Head) + key
MyUrl = base + mid + end
fi = File + ".jpg"
MetaUrl = base + r"/metadata" + size + end
#print MyUrl, MetaUrl #can check out image in browser to adjust size, fov to needs
met_lis = list(MetaParse(MetaUrl)) #does not grab image if no date
if (met_lis[1],Head) not in PrevImage and met_lis[0] is not None: #PrevImage is global list
urllib.urlretrieve(MyUrl, os.path.join(SaveLoc,fi))
met_lis.append(fi)
PrevImage.append((met_lis[1],Head)) #append new Pano ID to list of images
else:
met_lis.append(None)
return met_lis
#Make an example list of tuples of lat,lon's and orientation
#Pointed toward the sidewalk - plus or minus 90 degrees to face forward/backward on street
DataList = [(40.7036043470179800,-74.0143908501053400,97.00),
(40.7037139540670900,-74.0143727485309500,97.00),
(40.7038235569946140,-74.0143546472568100,97.00),
(40.7039329592712600,-74.0143365794219800,97.00),
(40.7040422704154500,-74.0143185262956300,97.00),
(40.7041517813782500,-74.0143004403322000,97.00),
(40.7042611636045350,-74.0142823755611700,97.00),
(40.7043707615693800,-74.0142642750708300,97.00)]
image_list = [] #to stuff the resulting meta-data for images
ct = 0
for i in DataList:
ct += 1
fi = "Image_" + str(ct)
temp = GetStreetLL(Lat=i[0],Lon=i[1],Head=i[2],File=fi,SaveLoc=DownLoc)
if temp[2] is not None:
image_list.append(temp)
print image_list
#If you want to see what example images might look like
#See https://photos.app.goo.gl/ip9qPZJ0DZMnERus2