-
Notifications
You must be signed in to change notification settings - Fork 34
/
ez_poi.py
94 lines (79 loc) · 3.97 KB
/
ez_poi.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __file__: ez_poi
import codecs
import json
import pymongo
import requests
ch = [
['重庆市', (105.317233, 32.20341, 110.15890399999999, 28.164785)],
['吉林省', (121.70807099999999, 46.289086, 131.29691499999998, 40.866085999999996)],
['山东省', (114.819496, 38.264081, 122.58095, 34.382439)],
['云南省', (97.531201, 29.224128999999998, 106.193344, 21.143404999999998)],
['青海省', (89.42535, 39.196225, 102.967585, 31.698498999999998)],
['广东省', (109.67578599999999, 25.521082, 117.189439, 20.240069)],
['台湾省', (120.03159, 25.92869, 123.68842599999999, 22.033913)],
['河北省', (113.49011999999999, 42.615044, 119.847155, 36.086891)],
['辽宁省', (118.840222, 43.480922, 125.77733099999999, 38.723813)],
['新疆维吾尔自治区', (73.490083, 49.171015, 96.38755499999999, 34.334315)],
['四川省', (97.349425, 34.314332, 108.540736, 26.071161)],
['西藏自治区', (78.3945, 36.481302, 99.112703, 26.854162)],
['上海市', (120.878948, 31.882906, 121.97232, 30.690742999999998)],
['北京市', (115.422051, 40.978643, 117.383319, 39.455766)],
['山西省', (110.233774, 40.744949, 114.55133699999999, 34.605824)],
['贵州省', (103.709509, 29.210865, 109.515198, 24.663422999999998)],
['安徽省', (114.902723, 34.643266, 119.618952, 29.397806)],
['福建省', (115.851227, 28.291657999999998, 120.432521, 23.619619999999998)],
['天津市', (116.702361, 40.231457, 118.02968899999999, 38.555353)],
['黑龙江省', (121.373582, 53.559993999999996, 134.775093, 43.423055)],
['澳门', (113.529631, 22.216908, 113.59847699999999, 22.109875)],
['甘肃省', (92.337831, 42.794543, 108.70577499999999, 32.596171999999996)],
['江西省', (113.575677, 30.060626, 118.462119, 24.507299)],
['广西壮族自治区', (104.519247, 26.327282999999998, 112.052286, 21.403121)],
['内蒙古自治区', (97.171763, 53.333676, 126.03392799999999, 37.406219)],
['江苏省', (116.36721, 35.084147, 121.924607, 30.760343)],
['湖北省', (108.40990099999999, 33.273344, 116.131316, 29.050396)],
['香港', (113.817101, 22.5683, 114.50240199999999, 22.136699)],
['河南省', (110.375715, 36.355849, 116.645169, 31.407335)],
['宁夏回族自治区', (104.28448499999999, 39.374607999999995, 107.645308, 35.251515999999995)],
['海南省', (108.612764, 21.120027, 117.841697, 3.832541)],
['湖南省', (108.88338499999999, 30.12277, 114.24835999999999, 24.648723999999998)],
['陕西省', (105.49529899999999, 39.558169, 111.215559, 31.712722)],
['浙江省', (118.02819799999999, 31.171412, 122.340047, 27.168632)]
]
client = pymongo.MongoClient(host='localhost', port=27017)
db = client.lvyou
collection = db.tianditu_poi
def poi_download(key, mapBound, sheng):
print("start download", key, sheng)
param = {
'postStr': str(
{'keyWord': key, 'level': '20', 'mapBound': mapBound, 'queryType': '7',
'count': '20000', 'start': '0'}),
'type': 'query',
'tk': 'a4ee5c551598a1889adfabff55a5fc27'
}
url = 'http://api.tianditu.gov.cn/search'
r = requests.get(url=url, params=param)
data = json.loads(r.text)
data = data.get('pois')
if data:
for i in data:
i['sheng'] = sheng
i['queryType'] = '纯POI搜索'
i['keyWord'] = key
collection.insert(data)
def tianditu_poi_download():
path = 'poi_type.txt'
keys = []
with codecs.open(path, 'r', encoding='utf-8') as f:
for i in f.readlines():
s = i.strip()
keys.append(s)
for sheng in ch:
mapBound = ','.join([str(_) for _ in sheng[1]])
for key in keys:
poi_download(key=key, mapBound=mapBound, sheng=str(sheng[0]))
print("download end !!!")
if __name__ == '__main__':
tianditu_poi_download()