-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadIMGfromCSVcoordinates.py
45 lines (40 loc) · 1.49 KB
/
DownloadIMGfromCSVcoordinates.py
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
import requests
import csv
import numpy as np
from pathlib import Path
from decimal import Decimal
Xcoord = np.zeros(3000)
Ycoord = np.zeros(3000)
kmlName = 'Zona San Donato.kml'
with open('data/Bologna gps data/' + kmlName) as kml:
reader = csv.DictReader(kml) # read rows into a dictionary format
i = 0
for row in reader: # read a row as {column1: value1, column2: value2,...}
for (k, v) in row.items(): # go over each column name and value
if k == ' Xcoord':
Xcoord[i] = Decimal(v)
if k == 'Ycoord':
Ycoord[i] = Decimal(v)
i += 1
coordNum = i
Xcoord = Xcoord[:coordNum]
Ycoord = Ycoord[:coordNum]
#print(Xcoord)
#print(Ycoord)
print('Total number of coordinates: ' + coordNum)
startnsize = 'https://maps.googleapis.com/maps/api/streetview'
size = '?size=300x300'
location = '&location='
heading = '&heading='
pitch = '&pitch=0'
APIkey = '&key=AIzaSyCKBuiVEKcPBJk3h29HQxXPOUwOb59F3Cc'
for i in range(coordNum+1):
for j in range(4):
image_url = startnsize + size + location + str(Xcoord[i-1]) + ',' + str(Ycoord[i-1]) \
+ heading + str(j * 90) + pitch + APIkey
fileName = 'data/San Donato/' + str(Xcoord[i-1]) + 'X_' + str(Ycoord[i-1]) + 'Y_' + str(j*90) + 'deg.jpg'
if not Path(fileName).exists():
img_data = requests.get(image_url).content
with open(fileName, 'wb') as handler:
handler.write(img_data)
print(str(int((i/coordNum)*100))+'%')