forked from kkyyhh96/CollectGISData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect_baidu_streetview.py
executable file
·41 lines (35 loc) · 1.13 KB
/
collect_baidu_streetview.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
# coding:utf-8
# version:python3.5
# author:Yuhao Kang
# collect street view data from BaiduMap
import requests
# Baidu API request
class BaiduAPI(object):
def __init__(self):
# Your baidu api key
self.api_key = ""
# Each search request
def search_photo(self, longitude, latitude):
params = {
"ak": self.api_key,
"coordtype": "wgs84ll",
"location": "{0},{1}".format(longitude, latitude),
"fov": 360
}
try:
# Download pictures
r = requests.get("http://api.map.baidu.com/panorama/v2", params)
open("{0}_{1}.png".format(longitude, latitude), 'wb').write(r.content)
except Exception as e:
open("e:log.txt", 'a').writelines(e)
if __name__ == '__main__':
# Read data from csv
with open('data.csv', 'r') as data:
lines = data.readlines()
for line in lines:
# Get coordinates
longitude = line.split(',')[0]
latitude = line.split(',')[1]
# Get pictures
baidu = BaiduAPI()
baidu.search_photo(longitude, latitude)