├── baidu ├── data │ ├── 不用管.txt │ ├── bmap-poi-商场.csv │ └── result.txt ├── 百度POI分类表.xlsx ├── boundary │ ├── __pycache__ │ │ ├── app.cpython-36.pyc │ │ └── transCoordinateSystem.cpython-36.pyc │ ├── README.md │ ├── data │ │ ├── bmap-poi--park-shanghai.csv │ │ ├── temp-8f47895fc081480287a5cca46574a09f.csv │ │ └── result-d2e0a56d1e76441b99526c6fcc15ac4a.csv │ ├── transCoordinateSystem.py │ └── app.py ├── __pycache__ │ ├── transCoordinateSystem.cpython-36.pyc │ └── transCoordinateSystem.cpython-37.pyc ├── ~$百度POI分类表.xlsx ├── transCoordinateSystem.py └── app.py ├── gaode ├── poi-city │ ├── data │ │ └── 不用管.txt │ ├── __pycache__ │ │ ├── shp.cpython-36.pyc │ │ ├── transCoordinateSystem.cpython-36.pyc │ │ └── transCoordinateSystem.cpython-37.pyc │ ├── shp.py │ ├── transCoordinateSystem.py │ └── app.py ├── poi-pology │ ├── data │ │ └── 不用管.txt │ ├── __pycache__ │ │ ├── app.cpython-36.pyc │ │ ├── shp.cpython-36.pyc │ │ ├── city_grid.cpython-36.pyc │ │ ├── city_grid.cpython-37.pyc │ │ ├── area_boundary.cpython-36.pyc │ │ ├── area_boundary.cpython-37.pyc │ │ ├── transCoordinateSystem.cpython-36.pyc │ │ └── transCoordinateSystem.cpython-37.pyc │ ├── city_grid.py │ ├── area_boundary.py │ ├── transCoordinateSystem.py │ ├── shp.py │ └── app.py ├── poi-province │ ├── data │ │ └── 不用管.txt │ ├── __pycache__ │ │ └── transCoordinateSystem.cpython-37.pyc │ ├── transCoordinateSystem.py │ ├── shp.py │ └── app.py ├── 高德地图城市编码表.xlsx ├── 高德地图POI分类编码表.xlsx └── README.md ├── .idea ├── .gitignore ├── misc.xml ├── vcs.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── poi.iml └── README.md /baidu/data/不用管.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gaode/poi-city/data/不用管.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gaode/poi-pology/data/不用管.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gaode/poi-province/data/不用管.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /baidu/百度POI分类表.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/baidu/百度POI分类表.xlsx -------------------------------------------------------------------------------- /gaode/高德地图城市编码表.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/高德地图城市编码表.xlsx -------------------------------------------------------------------------------- /gaode/高德地图POI分类编码表.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/高德地图POI分类编码表.xlsx -------------------------------------------------------------------------------- /baidu/boundary/__pycache__/app.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/baidu/boundary/__pycache__/app.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-city/__pycache__/shp.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-city/__pycache__/shp.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/app.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/app.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/shp.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/shp.cpython-36.pyc -------------------------------------------------------------------------------- /baidu/__pycache__/transCoordinateSystem.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/baidu/__pycache__/transCoordinateSystem.cpython-36.pyc -------------------------------------------------------------------------------- /baidu/__pycache__/transCoordinateSystem.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/baidu/__pycache__/transCoordinateSystem.cpython-37.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/city_grid.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/city_grid.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/city_grid.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/city_grid.cpython-37.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/area_boundary.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/area_boundary.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/area_boundary.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/area_boundary.cpython-37.pyc -------------------------------------------------------------------------------- /baidu/boundary/__pycache__/transCoordinateSystem.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/baidu/boundary/__pycache__/transCoordinateSystem.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/README.md: -------------------------------------------------------------------------------- 1 | - POI分类编码表更新于2017年8月10日,用于查询不同POI类型对应的编码。仅供查询使用,建议通过地址解析等线上服务实时获取最新编码。 2 | - 城市编码表,更新于2019年5月27日.该表用于查询不同城市对应的编码。仅供查询使用,建议通过地址解析等线上服务实时获取最新编码。暂时不支持台湾省的行政区域编码查询 -------------------------------------------------------------------------------- /gaode/poi-city/__pycache__/transCoordinateSystem.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-city/__pycache__/transCoordinateSystem.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-city/__pycache__/transCoordinateSystem.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-city/__pycache__/transCoordinateSystem.cpython-37.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/transCoordinateSystem.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/transCoordinateSystem.cpython-36.pyc -------------------------------------------------------------------------------- /gaode/poi-pology/__pycache__/transCoordinateSystem.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-pology/__pycache__/transCoordinateSystem.cpython-37.pyc -------------------------------------------------------------------------------- /baidu/~$百度POI分类表.xlsx: -------------------------------------------------------------------------------- 1 | hgvgh hgvgh -------------------------------------------------------------------------------- /gaode/poi-province/__pycache__/transCoordinateSystem.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liujiao111/poi/HEAD/gaode/poi-province/__pycache__/transCoordinateSystem.cpython-37.pyc -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/poi.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /baidu/boundary/README.md: -------------------------------------------------------------------------------- 1 | 爬取百度POI边界数据的代码 2 | 3 | ## 代码结构 4 | - `app.py` 主程序运行文件,里面需要修改处理的POI文件地址,以及百度密钥 5 | - `data` 存放结果文件的目录 6 | - `transCoordinateSystem.py` 坐标转换代码(不用管) 7 | 8 | ## 操作步骤 9 | - 百度地图开放平台注册并申请开发者认证,然后申请web服务密钥 10 | - 打开 `app.py` ,修改需要处理的数据文件所在路径以及密钥 11 | - 运行 `app.py` 12 | - 正常运行没报错的话结果数据存在在data目录中,以 `reusult-` 开头,( `temp-` 那个文件不用管) -------------------------------------------------------------------------------- /baidu/boundary/data/bmap-poi--park-shanghai.csv: -------------------------------------------------------------------------------- 1 | address,area,city,lat,lng,name,province,uid 2 | 区间路与振港路交叉口西南150米,平湖市,嘉兴市,30.689427,121.224853,花海优胜主题公园,浙江省,b4850126c1da0f46fa42b214 3 | 新仓镇政府旁,平湖市,嘉兴市,30.727379,121.194814,芦川公园,浙江省,61085211d40b96dfc41b7589 4 | 浙江省嘉兴市平湖市眉家路,平湖市,嘉兴市,30.741369,121.191401,莲塘公园,浙江省,5e9227c946d2597cddee8b7e 5 | 老卫清路与飞虹村路交叉口西北150米,金山区,上海市,30.731494,121.323462,飞虹公园,上海市,101bc61b1676c1a0c42ba16f 6 | 上海市金山区新城路16号,金山区,上海市,30.713079,121.352215,滨海公园,上海市,8fde79ccaa9975be95ca0731 7 | 上海市金山区金涛路1369号,金山区,上海市,30.713372,121.34408,鹦鹉洲生态湿地公园,上海市,bc012fcd7a85b905c2f1cff2 8 | 大堤路208,金山区,上海市,30.716183,121.346123,荟萃园,上海市,414b01aa07846efe400245c5 9 | 复旦大学附属金山医院对面,金山区,上海市,30.719005,121.34209,小公园,上海市,d52831f9d768dca42efaa76f 10 | 上海市金山区卫零路东礁二村(龙胜大楼西南100米),金山区,上海市,30.729243,121.348039,东礁公园,上海市,2c8cbd8a10010e735e17c3c1 11 | 上海市金山区新城路16号滨海公园内,金山区,上海市,30.711684,121.351175,滨海公园动物园,上海市,ab92e842548f9270c51b75af 12 | 上海市金山区海芙路,金山区,上海市,30.762819,121.348895,新城公园,上海市,fa7e7352f533dc6642d63efb 13 | 上海市金山区海汇街500弄光明都乐汇物业旁,金山区,上海市,30.758546,121.344182,ParkBox公园盒子(光明都乐汇店),上海市,1083c1486667d6bc43afe660 14 | 上海市金山区中甸路,金山区,上海市,30.776839,121.347268,马棚先锋公园,上海市,2879bbd6f6a1ab606d20b9db 15 | 上海市金山区漕廊公路9133号,金山区,上海市,30.790792,121.165243,廊下生态园,上海市,bee6a5d41f859f9bd72ce2ec 16 | 上海市金山区漕廊公路,金山区,上海市,30.792624,121.164841,上海廊下郊野公园,上海市,ef51cd18ee9a34900a5cb373 -------------------------------------------------------------------------------- /gaode/poi-pology/city_grid.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | def generate_grids(start_long,start_lat,end_long,end_lat,resolution): 5 | """ 6 | 根据起始的经纬度和分辨率,生成需要需要的网格. 7 | 方向为左上,右下,所以resolution应为 负数,否则未空 8 | :param start_long: 9 | :param start_lat: 10 | :param end_long: 11 | :param end_lat: 12 | :param resolution: 13 | :return: 14 | """ 15 | assert start_long < end_long,'需要从左上到右下设置经度,start的经度应小于end的经度' 16 | assert start_lat > end_lat,'需要从左上到右下设置纬度,start的纬度应大于end的纬度' 17 | assert resolution>0,'resolution应大于0' 18 | 19 | 20 | grids_lib=[] 21 | longs = np.arange(start_long,end_long,resolution) 22 | if longs[-1] != end_long: 23 | longs = np.append(longs,end_long) 24 | 25 | lats = np.arange(start_lat,end_lat,-resolution) 26 | if lats[-1] != end_lat: 27 | lats = np.append(lats,end_lat) 28 | for i in range(len(longs)-1): 29 | for j in range(len(lats)-1): 30 | grids_lib.append([round(float(longs[i]),6),round(float(lats[j]),6),round(float(longs[i+1]),6),round(float(lats[j+1]),6)]) 31 | #yield [round(float(longs[i]),6),round(float(lats[j]),6),round(float(longs[i+1]),6),round(float(lats[j+1]),6)] 32 | return grids_lib 33 | 34 | 35 | 36 | #grids_lib = generate_grids(112.958507, 23.932988, 114.059957, 22.51436,0.1) 37 | #print(grids_lib) -------------------------------------------------------------------------------- /gaode/poi-pology/area_boundary.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # 第一行必须有,否则报中文字符非ascii码错误 3 | import urllib.request 4 | from urllib.parse import quote 5 | import json 6 | 7 | 8 | url = 'http://restapi.amap.com/v3/config/district?' 9 | def getlnglat(address, key): 10 | 11 | uri = url + 'keywords=' + quote(address) + '&key=' + key + '&subdistrict=1' + '&extensions=all' 12 | 13 | print(uri) 14 | 15 | # 访问链接后,api会回传给一个json格式的数据 16 | temp = urllib.request.urlopen(uri) 17 | 18 | temp = json.loads(temp.read()) 19 | 20 | 21 | # polyline是坐标,name是区域的名字 22 | Data = temp["districts"][0]['polyline'] 23 | 24 | lngs = [] 25 | lats = [] 26 | points = [] 27 | for line in str(Data).split(";"): 28 | if len(line.split("|")) > 1: 29 | for uu in line.split("|"): 30 | if float(uu.split(",")[0]) != None: 31 | lngs.append(float(uu.split(",")[0])) 32 | lats.append(float(uu.split(",")[1])) 33 | points.append([float(uu.split(",")[0]), float(uu.split(",")[1])]) 34 | else: 35 | if float(line.split(",")[0]) != None: 36 | lngs.append(float(line.split(",")[0])) 37 | lats.append(float(line.split(",")[1])) 38 | points.append([float(line.split(",")[0]), float(line.split(",")[1])]) 39 | 40 | print(points) 41 | print(max(lngs), min(lngs), max(lats), min(lats)) 42 | return max(lngs), min(lngs), max(lats), min(lats) 43 | 44 | 45 | 46 | ''' 47 | num = 0 48 | #ad = getSubName(addr_name) # 得到福州下属区域的城市代码 49 | add = getlnglat(addr_name) # 得到福州整个的边界数据 50 | 51 | while num < len(ad): 52 | add = pd.concat([add, getlnglat(ad[num].encode("utf-8"))]) # 得到福州下属的全部区域的边界数据 53 | num += 1 54 | add.to_csv('{0}.csv'.format(addr_name), encoding='gbk') 55 | ''' 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 这是一个爬取互联网开放的POI数据以及POI边界坐标代码集,包括高德和百度地图,可以爬取指定经纬度范围或者指定城市/省份的POI数据以及POI边界坐标(目前仅限百度)。 2 | 3 | ## 相关网站 4 | - 百度地图开放平台:http://lbsyun.baidu.com/ 5 | - 百度地图开放平台-POI地点检索接口文档:http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-placeapi 6 | - 高德地图开放平台:https://lbs.amap.com/ 7 | - 高德地图开放平台-POI地点检索接口文档:https://lbs.amap.com/api/webservice/guide/api/search 8 | - Uber小姐姐开发的一个超级炫酷的地图可视化平台:https://kepler.gl/ (也欢迎访问我的网站上的地址:http://www.mapboxx.cn:8080/ ,功能一样的) 9 | - 开放路网地图:https://www.openstreetmap.org/ 10 | 11 | ## 代码目录介绍 12 | #### baidu 13 | 百度地图POI数据爬取(WGS84坐标系) 14 | 15 | - app.py 程序入口文件 16 | - data 存放爬取的POI数据目录 17 | - boundary 百度POI边界坐标爬取目录 18 | - POI边界爬取结果存放目录 19 | 20 | #### gaode 21 | 高德地图POI数据爬取 22 | 23 | - poi-city 划分行政区划来爬取指定城市范围内的POI数据 24 | - poi-pology 划分矩形网格来爬取指定城市的POI数据 25 | - poi-province 爬取指定省份内的POI数据 26 | - 高德地图POI分类编码表.xlsx 27 | - 高德地图城市编码表.xlsx 28 | 29 | 30 | ## 公共约定 31 | - app.py均为程序入口文件,修改配置以及执行都只需要关注该文件即可 32 | - transCoordinateSystem.py 为坐标转换代码,支持高德、百度、WGS84三种坐标系互转 33 | - POI分类可以用编码,也可以用对应的中文关键字 34 | 35 | ## 运行步骤 36 | 37 | ##### 运行环境安装 38 | 39 | - 开发语言:python 3+ 推荐安装anaconda,集成了许多常用的第三方库 40 | - 开发工具:pycharm,其他的开发工具也行,看自己爱好 41 | - 一些可能需要安装的第三方库: 42 | - pandas 43 | - urllib 44 | - xpinyin 45 | - requests 46 | 47 | 具体可以先运行看缺少哪些库,然后使用pip install进行安装。 48 | 49 | 50 | 51 | 52 | ##### 修改配置 53 | 在各个目录下的app.py中修改爬取参数配置,需要修改的地方均以TODO 标识,各个参数在代码前的注释均有介绍,最主要是需要设置需要爬取的POI类型、爬取的范围(城市/省/经纬度范围)、对应的AK密钥。 其中AK密钥可在百度开放平台( 54 | http://lbsyun.baidu.com/)或者高德地图开放平台( 55 | https://lbs.amap.com/)上申请。 56 | 57 | 58 | 59 | ##### 启动 60 | 执行命令`python app.py` 即可开始爬取数据,不过由于范围大小、以及POI数量多少不一样,爬取花费的时间也不一样,范围越大,POI数量越多,花费的时间越长。比如爬取省的花费时间比爬一个城市花费的要长,爬取餐厅比爬图书馆花费的时间长。 61 | 62 | 63 | 64 | #### 常见问题以及解决措施: 65 | - 启动后报错:"no module named xxxxx",这是因为你的Python环境里面没有相应的第三方模块,可以使用命令"pip install XXX"安装相应的模块,安装成功后重启即可,特别需要注意的是在`gaode/poi-province`中的代码需要安装`shapefile`模块,其安装命令名为`pip install pyshp`,如果仍然不懂,可以把报错信息粘贴到百度搜索。 66 | - 运行后控制台报错,可以查看打印的数据(高德或百度POI爬取返回的数据),例如:`{"status":"0","info":"INVALID_USER_KEY","infocode":"10001"}`,重点查看`info`的内容,此处`INVALID_USER_KEY0`表示该密钥无效,需要去高德开放平台检查账号是否被封禁,以及申请的密钥是否是web服务类型(这个很重要,如果是其他类型,则没法使用该功能)。 67 | 68 | 69 | ##### 附录 70 | 有什么优化建议或者发现问题欢迎向我提问,POI,宜出行都可以,qq:917961898 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /gaode/poi-city/shp.py: -------------------------------------------------------------------------------- 1 | #-*-coding:utf-8-*- 2 | import shapefile as shp 3 | import csv 4 | import codecs 5 | import os 6 | 7 | def trans_point_to_shp(folder, fn, idlng, idlat, delimiter=','): 8 | 9 | w = shp.Writer(folder) 10 | w.field('lon', 'F', 10, 8) 11 | w.field('lat', 'F', 10, 8) 12 | w.field('name', 'C', 100) 13 | w.field('pname', 'C', 10, 8) # float 14 | w.field('cityname', 'C', 10, 8) # float 15 | w.field('business_area', 'C', 100) # string, max-length 16 | w.field('type', 'C', 100) # string, max-length 17 | 18 | with codecs.open(folder + fn, 'rb', 'utf-8') as csvfile: 19 | reader = csv.reader(csvfile, delimiter=delimiter) 20 | # skip the header 21 | next(reader, None) 22 | # loop through each of the rows and assign the attributes to variables 23 | for row in reader: 24 | name = row[2] 25 | address = row[3] 26 | pname = row[4] 27 | cityname = row[5] 28 | business_area = row[6] 29 | type = row[7] 30 | lng = float(row[idlng]) 31 | lat = float(row[idlat]) 32 | w.point(lng, lat) 33 | w.record(lng, lat, name, address, pname, cityname, business_area, type) 34 | 35 | w.close() 36 | 37 | 38 | if __name__ == '__main__': 39 | folder = 'C:\\study\\python\\studyws\\poi-根据分类编码爬取-20191005\\data' + os.sep 40 | fn = 'poi-重庆市-160600.csv' 41 | idlng = 0 42 | idlat = 1 43 | trans_point_to_shp(folder, fn, idlng, idlat) 44 | 45 | idlng = 0 46 | idlat = 1 47 | 48 | # trans_point_to_shp(folder, fn, idlng, idlat) 49 | 50 | ''' 51 | path = folder + fn.split(".")[0] + os.sep 52 | print(path) 53 | 54 | delimiter = ',' 55 | 56 | w = shp.Writer(path) 57 | w.field('lon', 'F', 10, 8) 58 | w.field('lat', 'F', 10, 8) 59 | w.field('name', 'C', 100) 60 | w.field('pname', 'C', 10, 8) # float 61 | w.field('cityname', 'C', 10, 8) # float 62 | w.field('business_area', 'C', 100) # string, max-length 63 | w.field('type', 'C', 100) # string, max-length 64 | 65 | with codecs.open(folder + fn.split(".")[0] + os.sep + fn, 'rb', 'gbk') as csvfile: 66 | reader = csv.reader(csvfile, delimiter=delimiter) 67 | # skip the header 68 | next(reader, None) 69 | #loop through each of the rows and assign the attributes to variables 70 | for row in reader: 71 | name = row[2] 72 | address = row[3] 73 | pname = row[4] 74 | cityname = row[5] 75 | business_area = row[6] 76 | type = row[7] 77 | lng = float(row[idlng]) 78 | lat = float(row[idlat]) 79 | w.point(lng, lat) 80 | w.record(lng, lat, name, address, pname, cityname, business_area, type) 81 | 82 | w.close() 83 | ''' 84 | 85 | -------------------------------------------------------------------------------- /baidu/boundary/data/temp-8f47895fc081480287a5cca46574a09f.csv: -------------------------------------------------------------------------------- 1 | boundary,uid 2 | ,b4850126c1da0f46fa42b214 3 | "121.19482057667139,30.728513905896495;121.19572220681007,30.728558404808958;121.19586675584459,30.72847884265915;121.1963056571371,30.728478157777115;121.1964691792823,30.728399703712093;121.19648946391902,30.727739733578858;121.19637460118669,30.7276006043387;121.19479316218384,30.727040245296195;121.19458684206921,30.72714099946645;121.19447426732101,30.727245771608636;121.19482057667139,30.728513905896495",61085211d40b96dfc41b7589 4 | ,5e9227c946d2597cddee8b7e 5 | "121.32287122710048,30.73218503653891;121.32338289113929,30.73227673145889;121.32345562603814,30.73205989579203;121.32366068852504,30.731249280797478;121.32365566520063,30.731221260114488;121.32289424078932,30.731192875689455;121.32266212223878,30.731877204273623;121.32281503449761,30.73193377629182;121.32287122710048,30.73218503653891",101bc61b1676c1a0c42ba16f 6 | "121.35040529349025,30.713905510884764;121.35090169711506,30.711470420402552;121.35151002960642,30.71113385577296;121.3547845328514,30.714166775669987;121.35436682078925,30.71446909989319;121.3531560846229,30.714287006907032;121.35202664510521,30.71413836723422;121.35064002072001,30.713934850816056;121.35040529349025,30.713905510884764",8fde79ccaa9975be95ca0731 7 | ,bc012fcd7a85b905c2f1cff2 8 | "121.34810335328193,30.7173297902329;121.3449155248407,30.714427536462306;121.34404249674947,30.71488806558401;121.34731743746923,30.717860296237355;121.34809141929324,30.71746002731113;121.34811144881118,30.717396667496086;121.34810335328193,30.7173297902329",414b01aa07846efe400245c5 9 | ,d52831f9d768dca42efaa76f 10 | "121.34693822588294,30.72943574292975;121.34697645866375,30.72950712474462;121.34699755716527,30.7295157749633;121.34875753708313,30.729854805520564;121.34884593214191,30.729857262601254;121.34890016284557,30.729847311427953;121.3489292715373,30.729825796116533;121.34898648641185,30.72978578279914;121.34906176171866,30.729724445429483;121.34908082645651,30.7297041051233;121.34909068176624,30.72951388059628;121.34906440004195,30.729348297485455;121.34872627155985,30.72872304427199;121.34869108313642,30.728690648692016;121.34863782350104,30.728666569299072;121.34857051077425,30.728651735519563;121.34690854227567,30.728876086060737;121.34686036165964,30.728899894087842;121.34683830107294,30.72893226957426;121.3468303250183,30.728990417821347;121.34693822588294,30.72943574292975",2c8cbd8a10010e735e17c3c1 11 | ,ab92e842548f9270c51b75af 12 | ,fa7e7352f533dc6642d63efb 13 | ,1083c1486667d6bc43afe660 14 | ,2879bbd6f6a1ab606d20b9db 15 | "121.16374198987494,30.79308154262058;121.16659410986911,30.793011588486312;121.16660003868549,30.792828714797103;121.16655503357944,30.79234872785768;121.16668097601193,30.79036671059321;121.16682901675998,30.78964566363294;121.16695495919247,30.789036682210916;121.16695495919247,30.78890072339668;121.16570002639503,30.788490519043513;121.16530602959836,30.788280723923783;121.16382400516798,30.787698724247335;121.16374198987494,30.79308154262058",bee6a5d41f859f9bd72ce2ec 16 | ,ef51cd18ee9a34900a5cb373 17 | -------------------------------------------------------------------------------- /baidu/data/bmap-poi-商场.csv: -------------------------------------------------------------------------------- 1 | address,area,city,lat,lng,name,province,uid 2 | 呼和浩特市回民区中山西路1号,回民区,呼和浩特市,40.81561176087527,111.66235209612209,维多利购物中心,内蒙古自治区,844a750e0f107ea062685846 3 | 内蒙古自治区呼和浩特市回民区中山西路和锡林郭勒南路交汇处,回民区,呼和浩特市,40.81313044791466,111.66152296765503,海亮广场,内蒙古自治区,373cf757b73e6f774354d728 4 | 呼和浩特市赛罕区鄂尔多斯大街26号,赛罕区,呼和浩特市,40.79601671226304,111.67475524954409,凯德MALL(鄂尔多斯大街店),内蒙古自治区,23e8cf0c4a8775221c38946e 5 | 内蒙古自治区呼和浩特市回民区石羊桥路与大学西街交汇处西北角,回民区,呼和浩特市,40.802106019964185,111.6565086991105,七彩城购物中心,内蒙古自治区,e9d6cea37cd8face51e5c572 6 | 内蒙古自治区呼和浩特市新城区昭乌达路66号,新城区,呼和浩特市,40.82172903930926,111.68356175533485,劝业场(昭乌达路店),内蒙古自治区,0f956ce0c2462541a80dd852 7 | 呼和浩特市回民区中山西路86号,回民区,呼和浩特市,40.81147388009001,111.65983777474082,王府井奥莱(中山西路店),内蒙古自治区,91ea5d4dceaf0377c7f50d29 8 | 呼和浩特市回民区中山西路7号,回民区,呼和浩特市,40.81290837422566,111.6594486950472,内蒙古民族商场,内蒙古自治区,504d6113fd846aaa465726c5 9 | 内蒙古自治区呼和浩特市赛罕区鄂尔多斯大街26号,赛罕区,呼和浩特市,40.79607611223027,111.67461574492087,嘉茂购物中心,内蒙古自治区,1142e79a820969ad3b221c0f 10 | 大学西街与锡林郭勒南路交叉口东南角,赛罕区,呼和浩特市,40.804801223096874,111.66931600675238,GOMEET,内蒙古自治区,c3e8661a1d096f00d23ce3d2 11 | 呼和浩特市回民区中山西路39号,回民区,呼和浩特市,40.814479898704086,111.66121283526938,维多利商厦,内蒙古自治区,971f6d42a338c5bced74f895 12 | 呼和浩特市回民区贝尔路西巷27号,回民区,呼和浩特市,40.8139972369196,111.65847547978318,宝马商城,内蒙古自治区,fa01e937d57ecf4a774ff118 13 | 内蒙古自治区呼和浩特市回民区中山西路1号,回民区,呼和浩特市,40.81354171874745,111.6631410984202,时代城,内蒙古自治区,b9e5d0b828634dc181a12e43 14 | 呼和浩特市新城区新城西街48号,新城区,呼和浩特市,40.82188573458821,111.67318879224516,凯德新世纪,内蒙古自治区,d991e11667dc36551f389418 15 | 内蒙古自治区呼和浩特市回民区锡林郭勒南路73号,回民区,呼和浩特市,40.81072939384681,111.66525236109463,五四商城,内蒙古自治区,34e48508c16913e2d8d89118 16 | 内蒙古自治区呼和浩特市回民区中山西路9号,回民区,呼和浩特市,40.81187387039837,111.65885401178313,星悦荟商厦,内蒙古自治区,ea637d93d06a512826e0a09c 17 | 内蒙古自治区呼和浩特市赛罕区昭乌达路与包头大街交汇处西南角,赛罕区,呼和浩特市,40.78087472166593,111.7001323542082,凯元广场,内蒙古自治区,c8b6e1e65771a70cea56fa79 18 | 鄂尔多斯东街21号附近,赛罕区,呼和浩特市,40.80660714300883,111.73191838857049,邻里荟购物中心,内蒙古自治区,8ae8346f9f632ed1c61b75fb 19 | 呼和浩特市回民区阿拉善北路与成吉思汗西街交汇处,回民区,呼和浩特市,40.83044675735071,111.60187094756705,万达广场(呼市回民区店),内蒙古自治区,7f8e917cde2024abfb2d61e5 20 | 呼和浩特市新城区成吉思汗大街16号,新城区,呼和浩特市,40.85569820974605,111.67155010540421,滨海商业广场,内蒙古自治区,45306fb10a9f09807c29bde6 21 | 呼和浩特市新城区成吉思汗大街16号,新城区,呼和浩特市,40.85575618136523,111.67055162206107,滨海玖禾奥莱,内蒙古自治区,5584d2a191d8650c9e82eaac 22 | 成吉思汗大街16号,新城区,呼和浩特市,40.85560109978923,111.6707509823549,滨海商业广场C区(滨海商业广场店),内蒙古自治区,3ad5683414920762c056acb9 23 | 哲里木路与成吉思汗大街交叉口东南100米,新城区,呼和浩特市,40.855728806239284,111.67169651894731,滨海商业广场E区(滨海商业广场店),内蒙古自治区,cd68e0a735e592ffeee4a55d 24 | 内蒙古自治区呼和浩特市新城区滨海商业广场A区(成吉思汗广场东),新城区,呼和浩特市,40.85324604366525,111.67138266218815,滨海商业广场-A区,内蒙古自治区,7ba687b62a64cfbfe5e96511 25 | 呼和浩特市赛罕区新华东街26号呼和浩特万达广场1层,赛罕区,呼和浩特市,40.83428454749821,111.72705178228095,苏宁易购广场(呼和浩特店),内蒙古自治区,db871c1572190943b8bd63c1 26 | 呼和浩特市赛罕区新华东街62号,赛罕区,呼和浩特市,40.82799784385105,111.7034109899395,维多利·摩尔城,内蒙古自治区,8d4bf05d412778579e95de36 27 | 呼和浩特市赛罕区新华东街66号,赛罕区,呼和浩特市,40.82824079007486,111.70171146681709,长乐宫购物中心,内蒙古自治区,3810c8794c89128b9c09f718 28 | 呼和浩特市新城区兴安北路,新城区,呼和浩特市,40.86346347215748,111.68497692708053,维多利喜悦汇,内蒙古自治区,6dce5c43745aa14d95f08c86 29 | 呼和浩特市赛罕区新华东街26号,赛罕区,呼和浩特市,40.834514398341526,111.72775714154231,万达广场(呼和浩特店),内蒙古自治区,cfe44457f72b3ca2ce04efae 30 | 兴安北路169号,新城区,呼和浩特市,40.83727122300655,111.68709822252137,天宇百货商城,内蒙古自治区,4de06d866af2026388b9880c 31 | 内蒙古自治区呼和浩特市新城区新华东街8号,新城区,呼和浩特市,40.82632338789472,111.69136475998431,维多利国际广场,内蒙古自治区,6deee30870104f1729fc4847 32 | 成吉思汗东街附近,新城区,呼和浩特市,40.8564996211689,111.72013509812788,融城百汇购物中心,内蒙古自治区,c81b4720e13578cff7eafcb7 33 | 内蒙古自治区呼和浩特市新城区新华东街587号,新城区,呼和浩特市,40.83308862959933,111.71553574912576,瑞富祥商场(新华东街店),内蒙古自治区,43b7e88958c87a6a58f6be14 34 | 新华大街11号附近,新城区,呼和浩特市,40.826777041844224,111.68848609415598,维多利国际广场-三期,内蒙古自治区,e03361f7bc9ad8d36fc02cae 35 | 新华大街东风路祥泰小区1号楼,新城区,呼和浩特市,40.830122606534,111.70297422099989,金叶商厦,内蒙古自治区,0fedf77dc09768bc1811d58f 36 | 呼和浩特市赛罕区东影南街74号,赛罕区,呼和浩特市,40.82578188093295,111.7027105043429,天美商场,内蒙古自治区,cac5fc7695bb80ea2cb96d18 37 | -------------------------------------------------------------------------------- /baidu/transCoordinateSystem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __author = "Brady_Hu" 5 | 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | 13 | 14 | def gcj02_to_bd09(lng, lat): 15 | """ 16 | 火星坐标系(GCJ-02)转百度坐标系(BD-09) 17 | 谷歌、高德——>百度 18 | :param lng:火星坐标经度 19 | :param lat:火星坐标纬度 20 | :return: 21 | """ 22 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 23 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 24 | bd_lng = z * math.cos(theta) + 0.0065 25 | bd_lat = z * math.sin(theta) + 0.006 26 | return [bd_lng, bd_lat] 27 | 28 | 29 | def bd09_to_gcj02(bd_lon, bd_lat): 30 | """ 31 | 百度坐标系(BD-09)转火星坐标系(GCJ-02) 32 | 百度——>谷歌、高德 33 | :param bd_lat:百度坐标纬度 34 | :param bd_lon:百度坐标经度 35 | :return:转换后的坐标列表形式 36 | """ 37 | x = bd_lon - 0.0065 38 | y = bd_lat - 0.006 39 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 40 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 41 | gg_lng = z * math.cos(theta) 42 | gg_lat = z * math.sin(theta) 43 | return [gg_lng, gg_lat] 44 | 45 | 46 | def wgs84_to_gcj02(lng, lat): 47 | """ 48 | WGS84转GCJ02(火星坐标系) 49 | :param lng:WGS84坐标系的经度 50 | :param lat:WGS84坐标系的纬度 51 | :return: 52 | """ 53 | if out_of_china(lng, lat): # 判断是否在国内 54 | return lng, lat 55 | dlat = _transformlat(lng - 105.0, lat - 35.0) 56 | dlng = _transformlng(lng - 105.0, lat - 35.0) 57 | radlat = lat / 180.0 * pi 58 | magic = math.sin(radlat) 59 | magic = 1 - ee * magic * magic 60 | sqrtmagic = math.sqrt(magic) 61 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 62 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 63 | mglat = lat + dlat 64 | mglng = lng + dlng 65 | return [mglng, mglat] 66 | 67 | 68 | def gcj02_to_wgs84(lng, lat): 69 | """ 70 | GCJ02(火星坐标系)转GPS84 71 | :param lng:火星坐标系的经度 72 | :param lat:火星坐标系纬度 73 | :return: 74 | """ 75 | if out_of_china(lng, lat): 76 | return lng, lat 77 | dlat = _transformlat(lng - 105.0, lat - 35.0) 78 | dlng = _transformlng(lng - 105.0, lat - 35.0) 79 | radlat = lat / 180.0 * pi 80 | magic = math.sin(radlat) 81 | magic = 1 - ee * magic * magic 82 | sqrtmagic = math.sqrt(magic) 83 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 84 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 85 | mglat = lat + dlat 86 | mglng = lng + dlng 87 | return [lng * 2 - mglng, lat * 2 - mglat] 88 | 89 | 90 | def bd09_to_wgs84(bd_lon, bd_lat): 91 | lon, lat = bd09_to_gcj02(bd_lon, bd_lat) 92 | return gcj02_to_wgs84(lon, lat) 93 | 94 | 95 | def wgs84_to_bd09(lon, lat): 96 | lon, lat = wgs84_to_gcj02(lon, lat) 97 | return gcj02_to_bd09(lon, lat) 98 | 99 | 100 | def _transformlat(lng, lat): 101 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \ 102 | 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 103 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 104 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 105 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 106 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 107 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 108 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 109 | return ret 110 | 111 | 112 | def _transformlng(lng, lat): 113 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \ 114 | 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 115 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 116 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 117 | ret += (20.0 * math.sin(lng * pi) + 40.0 * 118 | math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 119 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * 120 | math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 121 | return ret 122 | 123 | 124 | def out_of_china(lng, lat): 125 | """ 126 | 判断是否在国内,不在国内不做偏移 127 | :param lng: 128 | :param lat: 129 | :return: 130 | """ 131 | return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55) 132 | 133 | if __name__ == '__main__': 134 | lng = 113.224367 135 | lat = 25.69346 136 | #result1 = gcj02_to_bd09(lng, lat) 137 | #result2 = bd09_to_gcj02(lng, lat) 138 | #result3 = wgs84_to_gcj02(lng, lat) 139 | #result4 = gcj02_to_wgs84(lng, lat) 140 | result5 = bd09_to_wgs84(lng, lat) 141 | #result6 = wgs84_to_bd09(lng, lat) 142 | 143 | print(result5) 144 | 145 | -------------------------------------------------------------------------------- /baidu/boundary/transCoordinateSystem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __author = "Brady_Hu" 5 | 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | 13 | 14 | def gcj02_to_bd09(lng, lat): 15 | """ 16 | 火星坐标系(GCJ-02)转百度坐标系(BD-09) 17 | 谷歌、高德——>百度 18 | :param lng:火星坐标经度 19 | :param lat:火星坐标纬度 20 | :return: 21 | """ 22 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 23 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 24 | bd_lng = z * math.cos(theta) + 0.0065 25 | bd_lat = z * math.sin(theta) + 0.006 26 | return [bd_lng, bd_lat] 27 | 28 | 29 | def bd09_to_gcj02(bd_lon, bd_lat): 30 | """ 31 | 百度坐标系(BD-09)转火星坐标系(GCJ-02) 32 | 百度——>谷歌、高德 33 | :param bd_lat:百度坐标纬度 34 | :param bd_lon:百度坐标经度 35 | :return:转换后的坐标列表形式 36 | """ 37 | x = bd_lon - 0.0065 38 | y = bd_lat - 0.006 39 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 40 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 41 | gg_lng = z * math.cos(theta) 42 | gg_lat = z * math.sin(theta) 43 | return [gg_lng, gg_lat] 44 | 45 | 46 | def wgs84_to_gcj02(lng, lat): 47 | """ 48 | WGS84转GCJ02(火星坐标系) 49 | :param lng:WGS84坐标系的经度 50 | :param lat:WGS84坐标系的纬度 51 | :return: 52 | """ 53 | if out_of_china(lng, lat): # 判断是否在国内 54 | return lng, lat 55 | dlat = _transformlat(lng - 105.0, lat - 35.0) 56 | dlng = _transformlng(lng - 105.0, lat - 35.0) 57 | radlat = lat / 180.0 * pi 58 | magic = math.sin(radlat) 59 | magic = 1 - ee * magic * magic 60 | sqrtmagic = math.sqrt(magic) 61 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 62 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 63 | mglat = lat + dlat 64 | mglng = lng + dlng 65 | return [mglng, mglat] 66 | 67 | 68 | def gcj02_to_wgs84(lng, lat): 69 | """ 70 | GCJ02(火星坐标系)转GPS84 71 | :param lng:火星坐标系的经度 72 | :param lat:火星坐标系纬度 73 | :return: 74 | """ 75 | if out_of_china(lng, lat): 76 | return lng, lat 77 | dlat = _transformlat(lng - 105.0, lat - 35.0) 78 | dlng = _transformlng(lng - 105.0, lat - 35.0) 79 | radlat = lat / 180.0 * pi 80 | magic = math.sin(radlat) 81 | magic = 1 - ee * magic * magic 82 | sqrtmagic = math.sqrt(magic) 83 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 84 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 85 | mglat = lat + dlat 86 | mglng = lng + dlng 87 | return [lng * 2 - mglng, lat * 2 - mglat] 88 | 89 | 90 | def bd09_to_wgs84(bd_lon, bd_lat): 91 | lon, lat = bd09_to_gcj02(bd_lon, bd_lat) 92 | return gcj02_to_wgs84(lon, lat) 93 | 94 | 95 | def wgs84_to_bd09(lon, lat): 96 | lon, lat = wgs84_to_gcj02(lon, lat) 97 | return gcj02_to_bd09(lon, lat) 98 | 99 | 100 | def _transformlat(lng, lat): 101 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \ 102 | 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 103 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 104 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 105 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 106 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 107 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 108 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 109 | return ret 110 | 111 | 112 | def _transformlng(lng, lat): 113 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \ 114 | 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 115 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 116 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 117 | ret += (20.0 * math.sin(lng * pi) + 40.0 * 118 | math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 119 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * 120 | math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 121 | return ret 122 | 123 | 124 | def out_of_china(lng, lat): 125 | """ 126 | 判断是否在国内,不在国内不做偏移 127 | :param lng: 128 | :param lat: 129 | :return: 130 | """ 131 | return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55) 132 | 133 | if __name__ == '__main__': 134 | lng = 113.224367 135 | lat = 25.69346 136 | #result1 = gcj02_to_bd09(lng, lat) 137 | #result2 = bd09_to_gcj02(lng, lat) 138 | #result3 = wgs84_to_gcj02(lng, lat) 139 | #result4 = gcj02_to_wgs84(lng, lat) 140 | result5 = bd09_to_wgs84(lng, lat) 141 | #result6 = wgs84_to_bd09(lng, lat) 142 | 143 | print(result5) 144 | 145 | -------------------------------------------------------------------------------- /gaode/poi-city/transCoordinateSystem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __author = "Brady_Hu" 5 | 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | 13 | 14 | def gcj02_to_bd09(lng, lat): 15 | """ 16 | 火星坐标系(GCJ-02)转百度坐标系(BD-09) 17 | 谷歌、高德——>百度 18 | :param lng:火星坐标经度 19 | :param lat:火星坐标纬度 20 | :return: 21 | """ 22 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 23 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 24 | bd_lng = z * math.cos(theta) + 0.0065 25 | bd_lat = z * math.sin(theta) + 0.006 26 | return [bd_lng, bd_lat] 27 | 28 | 29 | def bd09_to_gcj02(bd_lon, bd_lat): 30 | """ 31 | 百度坐标系(BD-09)转火星坐标系(GCJ-02) 32 | 百度——>谷歌、高德 33 | :param bd_lat:百度坐标纬度 34 | :param bd_lon:百度坐标经度 35 | :return:转换后的坐标列表形式 36 | """ 37 | x = bd_lon - 0.0065 38 | y = bd_lat - 0.006 39 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 40 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 41 | gg_lng = z * math.cos(theta) 42 | gg_lat = z * math.sin(theta) 43 | return [gg_lng, gg_lat] 44 | 45 | 46 | def wgs84_to_gcj02(lng, lat): 47 | """ 48 | WGS84转GCJ02(火星坐标系) 49 | :param lng:WGS84坐标系的经度 50 | :param lat:WGS84坐标系的纬度 51 | :return: 52 | """ 53 | if out_of_china(lng, lat): # 判断是否在国内 54 | return lng, lat 55 | dlat = _transformlat(lng - 105.0, lat - 35.0) 56 | dlng = _transformlng(lng - 105.0, lat - 35.0) 57 | radlat = lat / 180.0 * pi 58 | magic = math.sin(radlat) 59 | magic = 1 - ee * magic * magic 60 | sqrtmagic = math.sqrt(magic) 61 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 62 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 63 | mglat = lat + dlat 64 | mglng = lng + dlng 65 | return [mglng, mglat] 66 | 67 | 68 | def gcj02_to_wgs84(lng, lat): 69 | """ 70 | GCJ02(火星坐标系)转GPS84 71 | :param lng:火星坐标系的经度 72 | :param lat:火星坐标系纬度 73 | :return: 74 | """ 75 | if out_of_china(lng, lat): 76 | return lng, lat 77 | dlat = _transformlat(lng - 105.0, lat - 35.0) 78 | dlng = _transformlng(lng - 105.0, lat - 35.0) 79 | radlat = lat / 180.0 * pi 80 | magic = math.sin(radlat) 81 | magic = 1 - ee * magic * magic 82 | sqrtmagic = math.sqrt(magic) 83 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 84 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 85 | mglat = lat + dlat 86 | mglng = lng + dlng 87 | return [lng * 2 - mglng, lat * 2 - mglat] 88 | 89 | 90 | def bd09_to_wgs84(bd_lon, bd_lat): 91 | lon, lat = bd09_to_gcj02(bd_lon, bd_lat) 92 | return gcj02_to_wgs84(lon, lat) 93 | 94 | 95 | def wgs84_to_bd09(lon, lat): 96 | lon, lat = wgs84_to_gcj02(lon, lat) 97 | return gcj02_to_bd09(lon, lat) 98 | 99 | 100 | def _transformlat(lng, lat): 101 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \ 102 | 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 103 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 104 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 105 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 106 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 107 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 108 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 109 | return ret 110 | 111 | 112 | def _transformlng(lng, lat): 113 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \ 114 | 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 115 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 116 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 117 | ret += (20.0 * math.sin(lng * pi) + 40.0 * 118 | math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 119 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * 120 | math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 121 | return ret 122 | 123 | 124 | def out_of_china(lng, lat): 125 | """ 126 | 判断是否在国内,不在国内不做偏移 127 | :param lng: 128 | :param lat: 129 | :return: 130 | """ 131 | return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55) 132 | 133 | if __name__ == '__main__': 134 | lng = 113.224367 135 | lat = 25.69346 136 | #result1 = gcj02_to_bd09(lng, lat) 137 | #result2 = bd09_to_gcj02(lng, lat) 138 | #result3 = wgs84_to_gcj02(lng, lat) 139 | #result4 = gcj02_to_wgs84(lng, lat) 140 | result5 = bd09_to_wgs84(lng, lat) 141 | #result6 = wgs84_to_bd09(lng, lat) 142 | 143 | print(result5) 144 | 145 | -------------------------------------------------------------------------------- /gaode/poi-pology/transCoordinateSystem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __author = "Brady_Hu" 5 | 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | 13 | 14 | def gcj02_to_bd09(lng, lat): 15 | """ 16 | 火星坐标系(GCJ-02)转百度坐标系(BD-09) 17 | 谷歌、高德——>百度 18 | :param lng:火星坐标经度 19 | :param lat:火星坐标纬度 20 | :return: 21 | """ 22 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 23 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 24 | bd_lng = z * math.cos(theta) + 0.0065 25 | bd_lat = z * math.sin(theta) + 0.006 26 | return [bd_lng, bd_lat] 27 | 28 | 29 | def bd09_to_gcj02(bd_lon, bd_lat): 30 | """ 31 | 百度坐标系(BD-09)转火星坐标系(GCJ-02) 32 | 百度——>谷歌、高德 33 | :param bd_lat:百度坐标纬度 34 | :param bd_lon:百度坐标经度 35 | :return:转换后的坐标列表形式 36 | """ 37 | x = bd_lon - 0.0065 38 | y = bd_lat - 0.006 39 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 40 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 41 | gg_lng = z * math.cos(theta) 42 | gg_lat = z * math.sin(theta) 43 | return [gg_lng, gg_lat] 44 | 45 | 46 | def wgs84_to_gcj02(lng, lat): 47 | """ 48 | WGS84转GCJ02(火星坐标系) 49 | :param lng:WGS84坐标系的经度 50 | :param lat:WGS84坐标系的纬度 51 | :return: 52 | """ 53 | if out_of_china(lng, lat): # 判断是否在国内 54 | return lng, lat 55 | dlat = _transformlat(lng - 105.0, lat - 35.0) 56 | dlng = _transformlng(lng - 105.0, lat - 35.0) 57 | radlat = lat / 180.0 * pi 58 | magic = math.sin(radlat) 59 | magic = 1 - ee * magic * magic 60 | sqrtmagic = math.sqrt(magic) 61 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 62 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 63 | mglat = lat + dlat 64 | mglng = lng + dlng 65 | return [mglng, mglat] 66 | 67 | 68 | def gcj02_to_wgs84(lng, lat): 69 | """ 70 | GCJ02(火星坐标系)转GPS84 71 | :param lng:火星坐标系的经度 72 | :param lat:火星坐标系纬度 73 | :return: 74 | """ 75 | if out_of_china(lng, lat): 76 | return lng, lat 77 | dlat = _transformlat(lng - 105.0, lat - 35.0) 78 | dlng = _transformlng(lng - 105.0, lat - 35.0) 79 | radlat = lat / 180.0 * pi 80 | magic = math.sin(radlat) 81 | magic = 1 - ee * magic * magic 82 | sqrtmagic = math.sqrt(magic) 83 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 84 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 85 | mglat = lat + dlat 86 | mglng = lng + dlng 87 | return [lng * 2 - mglng, lat * 2 - mglat] 88 | 89 | 90 | def bd09_to_wgs84(bd_lon, bd_lat): 91 | lon, lat = bd09_to_gcj02(bd_lon, bd_lat) 92 | return gcj02_to_wgs84(lon, lat) 93 | 94 | 95 | def wgs84_to_bd09(lon, lat): 96 | lon, lat = wgs84_to_gcj02(lon, lat) 97 | return gcj02_to_bd09(lon, lat) 98 | 99 | 100 | def _transformlat(lng, lat): 101 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \ 102 | 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 103 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 104 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 105 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 106 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 107 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 108 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 109 | return ret 110 | 111 | 112 | def _transformlng(lng, lat): 113 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \ 114 | 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 115 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 116 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 117 | ret += (20.0 * math.sin(lng * pi) + 40.0 * 118 | math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 119 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * 120 | math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 121 | return ret 122 | 123 | 124 | def out_of_china(lng, lat): 125 | """ 126 | 判断是否在国内,不在国内不做偏移 127 | :param lng: 128 | :param lat: 129 | :return: 130 | """ 131 | return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55) 132 | 133 | if __name__ == '__main__': 134 | lng = 113.224367 135 | lat = 25.69346 136 | #result1 = gcj02_to_bd09(lng, lat) 137 | #result2 = bd09_to_gcj02(lng, lat) 138 | #result3 = wgs84_to_gcj02(lng, lat) 139 | #result4 = gcj02_to_wgs84(lng, lat) 140 | result5 = bd09_to_wgs84(lng, lat) 141 | #result6 = wgs84_to_bd09(lng, lat) 142 | 143 | print(result5) 144 | 145 | -------------------------------------------------------------------------------- /gaode/poi-province/transCoordinateSystem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding:utf-8 -*- 3 | 4 | __author = "Brady_Hu" 5 | 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | 13 | 14 | def gcj02_to_bd09(lng, lat): 15 | """ 16 | 火星坐标系(GCJ-02)转百度坐标系(BD-09) 17 | 谷歌、高德——>百度 18 | :param lng:火星坐标经度 19 | :param lat:火星坐标纬度 20 | :return: 21 | """ 22 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 23 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 24 | bd_lng = z * math.cos(theta) + 0.0065 25 | bd_lat = z * math.sin(theta) + 0.006 26 | return [bd_lng, bd_lat] 27 | 28 | 29 | def bd09_to_gcj02(bd_lon, bd_lat): 30 | """ 31 | 百度坐标系(BD-09)转火星坐标系(GCJ-02) 32 | 百度——>谷歌、高德 33 | :param bd_lat:百度坐标纬度 34 | :param bd_lon:百度坐标经度 35 | :return:转换后的坐标列表形式 36 | """ 37 | x = bd_lon - 0.0065 38 | y = bd_lat - 0.006 39 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 40 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 41 | gg_lng = z * math.cos(theta) 42 | gg_lat = z * math.sin(theta) 43 | return [gg_lng, gg_lat] 44 | 45 | 46 | def wgs84_to_gcj02(lng, lat): 47 | """ 48 | WGS84转GCJ02(火星坐标系) 49 | :param lng:WGS84坐标系的经度 50 | :param lat:WGS84坐标系的纬度 51 | :return: 52 | """ 53 | if out_of_china(lng, lat): # 判断是否在国内 54 | return lng, lat 55 | dlat = _transformlat(lng - 105.0, lat - 35.0) 56 | dlng = _transformlng(lng - 105.0, lat - 35.0) 57 | radlat = lat / 180.0 * pi 58 | magic = math.sin(radlat) 59 | magic = 1 - ee * magic * magic 60 | sqrtmagic = math.sqrt(magic) 61 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 62 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 63 | mglat = lat + dlat 64 | mglng = lng + dlng 65 | return [mglng, mglat] 66 | 67 | 68 | def gcj02_to_wgs84(lng, lat): 69 | """ 70 | GCJ02(火星坐标系)转GPS84 71 | :param lng:火星坐标系的经度 72 | :param lat:火星坐标系纬度 73 | :return: 74 | """ 75 | if out_of_china(lng, lat): 76 | return lng, lat 77 | dlat = _transformlat(lng - 105.0, lat - 35.0) 78 | dlng = _transformlng(lng - 105.0, lat - 35.0) 79 | radlat = lat / 180.0 * pi 80 | magic = math.sin(radlat) 81 | magic = 1 - ee * magic * magic 82 | sqrtmagic = math.sqrt(magic) 83 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 84 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 85 | mglat = lat + dlat 86 | mglng = lng + dlng 87 | return [lng * 2 - mglng, lat * 2 - mglat] 88 | 89 | 90 | def bd09_to_wgs84(bd_lon, bd_lat): 91 | lon, lat = bd09_to_gcj02(bd_lon, bd_lat) 92 | return gcj02_to_wgs84(lon, lat) 93 | 94 | 95 | def wgs84_to_bd09(lon, lat): 96 | lon, lat = wgs84_to_gcj02(lon, lat) 97 | return gcj02_to_bd09(lon, lat) 98 | 99 | 100 | def _transformlat(lng, lat): 101 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \ 102 | 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 103 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 104 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 105 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 106 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 107 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 108 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 109 | return ret 110 | 111 | 112 | def _transformlng(lng, lat): 113 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \ 114 | 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 115 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * 116 | math.sin(2.0 * lng * pi)) * 2.0 / 3.0 117 | ret += (20.0 * math.sin(lng * pi) + 40.0 * 118 | math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 119 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * 120 | math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 121 | return ret 122 | 123 | 124 | def out_of_china(lng, lat): 125 | """ 126 | 判断是否在国内,不在国内不做偏移 127 | :param lng: 128 | :param lat: 129 | :return: 130 | """ 131 | return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55) 132 | 133 | if __name__ == '__main__': 134 | lng = 113.224367 135 | lat = 25.69346 136 | #result1 = gcj02_to_bd09(lng, lat) 137 | #result2 = bd09_to_gcj02(lng, lat) 138 | #result3 = wgs84_to_gcj02(lng, lat) 139 | #result4 = gcj02_to_wgs84(lng, lat) 140 | result5 = bd09_to_wgs84(lng, lat) 141 | #result6 = wgs84_to_bd09(lng, lat) 142 | 143 | print(result5) 144 | 145 | -------------------------------------------------------------------------------- /baidu/boundary/data/result-d2e0a56d1e76441b99526c6fcc15ac4a.csv: -------------------------------------------------------------------------------- 1 | number,uid,x,y 2 | 1,61085211d40b96dfc41b7589,121.18394562252428,30.724457511364673 3 | 2,61085211d40b96dfc41b7589,121.18485134737129,30.724494064037692 4 | 3,61085211d40b96dfc41b7589,121.1849966301442,30.724413355862684 5 | 4,61085211d40b96dfc41b7589,121.18543746735595,30.72440911512941 6 | 5,61085211d40b96dfc41b7589,121.18560178452108,30.72432943707202 7 | 6,61085211d40b96dfc41b7589,121.18562287743862,30.723669810767916 8 | 7,61085211d40b96dfc41b7589,121.18550766975596,30.72353168457286 9 | 8,61085211d40b96dfc41b7589,121.18391969078816,30.722985221677842 10 | 9,61085211d40b96dfc41b7589,121.1837122853438,30.723087806855432 11 | 10,61085211d40b96dfc41b7589,121.18359905988204,30.723193554489963 12 | 11,61085211d40b96dfc41b7589,121.18394562252428,30.724457511364673 13 | 12,101bc61b1676c1a0c42ba16f,121.31198169953439,30.728055501055657 14 | 13,101bc61b1676c1a0c42ba16f,121.31249256715628,30.728144459559275 15 | 14,101bc61b1676c1a0c42ba16f,121.31256542278933,30.727927427404175 16 | 15,101bc61b1676c1a0c42ba16f,121.31277103256515,30.72711643658512 17 | 16,101bc61b1676c1a0c42ba16f,121.31276604640682,30.727088460516903 18 | 17,101bc61b1676c1a0c42ba16f,121.31200572422557,30.727063957820747 19 | 18,101bc61b1676c1a0c42ba16f,121.31177318310512,30.727749062539726 20 | 19,101bc61b1676c1a0c42ba16f,121.31192584198907,30.72780473719903 21 | 20,101bc61b1676c1a0c42ba16f,121.31198169953439,30.728055501055657 22 | 21,8fde79ccaa9975be95ca0731,121.33941192549848,30.709980735100466 23 | 22,8fde79ccaa9975be95ca0731,121.33990708528938,30.707555437493124 24 | 23,8fde79ccaa9975be95ca0731,121.34051158119196,30.707229152474184 25 | 24,8fde79ccaa9975be95ca0731,121.34376112304491,30.710315544869747 26 | 25,8fde79ccaa9975be95ca0731,121.343345999136,30.71061047006152 27 | 26,8fde79ccaa9975be95ca0731,121.34214371926842,30.710407811619113 28 | 27,8fde79ccaa9975be95ca0731,121.3410221136209,30.710240219569453 29 | 28,8fde79ccaa9975be95ca0731,121.33964504966725,30.710013885079277 30 | 29,8fde79ccaa9975be95ca0731,121.33941192549848,30.709980735100466 31 | 30,414b01aa07846efe400245c5,121.33712198333086,30.713366061727392 32 | 31,414b01aa07846efe400245c5,121.33395719209422,30.710419232084476 33 | 32,414b01aa07846efe400245c5,121.33308906792506,30.710867626253282 34 | 33,414b01aa07846efe400245c5,121.33634063729954,30.713884214977803 35 | 34,414b01aa07846efe400245c5,121.3371099976163,30.713496020689544 36 | 35,414b01aa07846efe400245c5,121.33712995949925,30.71343301528899 37 | 36,414b01aa07846efe400245c5,121.33712198333086,30.713366061727392 38 | 37,2c8cbd8a10010e735e17c3c1,121.33595144156823,30.72544532504792 39 | 38,2c8cbd8a10010e735e17c3c1,121.33598935208894,30.72551722168788 40 | 39,2c8cbd8a10010e735e17c3c1,121.33601030587278,30.725526179508897 41 | 40,2c8cbd8a10010e735e17c3c1,121.33775846885663,30.725891878751433 42 | 41,2c8cbd8a10010e735e17c3c1,121.33784627851195,30.725895721463527 43 | 42,2c8cbd8a10010e735e17c3c1,121.3379001620692,30.725886630570145 44 | 43,2c8cbd8a10010e735e17c3c1,121.33792910173216,30.725865589696383 45 | 44,2c8cbd8a10010e735e17c3c1,121.3379859817284,30.725826508179743 46 | 45,2c8cbd8a10010e735e17c3c1,121.3380608254286,30.725766405266786 47 | 46,2c8cbd8a10010e735e17c3c1,121.33807978596553,30.72574638158463 48 | 47,2c8cbd8a10010e735e17c3c1,121.3380897812259,30.725556456344535 49 | 48,2c8cbd8a10010e735e17c3c1,121.33806385223859,30.725390582780918 50 | 49,2c8cbd8a10010e735e17c3c1,121.33772863311387,30.724760481735277 51 | 50,2c8cbd8a10010e735e17c3c1,121.33769371157948,30.724727559627098 52 | 51,2c8cbd8a10010e735e17c3c1,121.33764082858897,30.724702665412284 53 | 52,2c8cbd8a10010e735e17c3c1,121.33757397458683,30.724686791691905 54 | 53,2c8cbd8a10010e735e17c3c1,121.33592255394944,30.724885649676665 55 | 54,2c8cbd8a10010e735e17c3c1,121.33587465612939,30.724908724792193 56 | 55,2c8cbd8a10010e735e17c3c1,121.3358527016589,30.72494074886025 57 | 56,2c8cbd8a10010e735e17c3c1,121.33584471361897,30.724998735035133 58 | 57,2c8cbd8a10010e735e17c3c1,121.33595144156823,30.72544532504792 59 | 58,bee6a5d41f859f9bd72ce2ec,121.15267608659207,30.78945842748988 60 | 59,bee6a5d41f859f9bd72ce2ec,121.15554516166289,30.789348762516067 61 | 60,bee6a5d41f859f9bd72ce2ec,121.15555096893429,30.78916585693283 62 | 61,bee6a5d41f859f9bd72ce2ec,121.15550526781857,30.788686674245408 63 | 62,bee6a5d41f859f9bd72ce2ec,121.15563022310867,30.786703389631814 64 | 63,bee6a5d41f859f9bd72ce2ec,121.15577852639753,30.785980366199777 65 | 64,bee6a5d41f859f9bd72ce2ec,121.15590469436125,30.78536969259544 66 | 65,bee6a5d41f859f9bd72ce2ec,121.15590456944295,30.785233772623645 67 | 66,bee6a5d41f859f9bd72ce2ec,121.15464155449675,30.78484194042879 68 | 67,bee6a5d41f859f9bd72ce2ec,121.15424499216877,30.78463777034476 69 | 68,bee6a5d41f859f9bd72ce2ec,121.15275372573966,30.784076097445386 70 | 69,bee6a5d41f859f9bd72ce2ec,121.15267608659207,30.78945842748988 71 | -------------------------------------------------------------------------------- /baidu/app.py: -------------------------------------------------------------------------------- 1 | #coding: utf-8 2 | import requests 3 | import json 4 | import time 5 | import os 6 | import pandas as pd 7 | from transCoordinateSystem import bd09_to_wgs84 8 | 9 | # TODO 1 查询关键字,只支持单个 10 | KeyWord = "餐饮" 11 | 12 | # TODO 2 POI关键词,只支持单个 13 | baiduAk = '百度地图申请的密钥' 14 | 15 | # TODO 3 爬取区域的左下角和右上角百度地图坐标(经纬度) 16 | BigRect = { 17 | 'left': { 18 | 'x': 120.86099303837032, 19 | 'y': 30.6607006997429 20 | }, 21 | 'right': { 22 | 'x': 122.12725435186897, 23 | 'y': 31.89735902287794 24 | } 25 | } 26 | 27 | # TODO 4 划分细分窗口的数量,横向X * 纵向Y 28 | WindowSize = { 29 | 'xNum': 5.0, 30 | 'yNum': 5.0 31 | } 32 | 33 | 34 | 35 | 36 | def getSmallRect(bigRect, windowSize, windowIndex): 37 | """ 38 | 获取小矩形的左上角和右下角坐标字符串(百度坐标系) 39 | :param bigRect: 关注区域坐标信息 40 | :param windowSize: 细分窗口数量信息 41 | :param windowIndex: Z型扫描的小矩形索引号 42 | :return: lat,lng,lat,lng 43 | """ 44 | offset_x = (bigRect['right']['x'] - bigRect['left']['x'])/windowSize['xNum'] 45 | offset_y = (bigRect['right']['y'] - bigRect['left']['y'])/windowSize['yNum'] 46 | left_x = bigRect['left']['x'] + offset_x * (windowIndex % windowSize['xNum']) 47 | left_y = bigRect['left']['y'] + offset_y * (windowIndex // windowSize['yNum']) 48 | right_x = (left_x + offset_x) 49 | right_y = (left_y + offset_y) 50 | return str(left_y) + ',' + str(left_x) + ',' + str(right_y) + ',' + str(right_x) 51 | 52 | 53 | def requestBaiduApi(keyWords, smallRect, baiduAk): 54 | pageNum = 0 55 | file = open(os.getcwd() + os.sep + "data/result.txt", 'a+', encoding='utf-8') 56 | pois = [] 57 | while True: 58 | try: 59 | URL = "http://api.map.baidu.com/place/v2/search?query=" + keyWords + \ 60 | "&bounds=" + smallRect + \ 61 | "&output=json" + \ 62 | "&ak=" + baiduAk + \ 63 | "&scope=2" + \ 64 | "&page_size=20" + \ 65 | "&page_num=" + str(pageNum) 66 | print(URL) 67 | resp = requests.get(URL) 68 | res = json.loads(resp.text) 69 | if len(res['results']) == 0: 70 | print('返回结果为0') 71 | break 72 | else: 73 | for r in res['results']: 74 | pois.append(r) 75 | file.writelines(str(r).strip() + '\n') 76 | pageNum += 1 77 | time.sleep(1) 78 | except Exception as e: 79 | print("爬取失败,请查看输出的错误信息:", resp.text.strip()) 80 | break 81 | return pois 82 | 83 | def check_params(): 84 | ''' 85 | 判断输入的经纬度范围是否正确 86 | :return: 87 | ''' 88 | 89 | min_lng = BigRect['left']['x'] 90 | max_lng = BigRect['right']['x'] 91 | 92 | min_lat = BigRect['left']['y'] 93 | max_lat = BigRect['right']['y'] 94 | 95 | if int(min_lng) > int(max_lng): 96 | print('输入经度有误!,右上角的经度应该大于左下角的经度值') 97 | exit(0) 98 | if int(min_lat) > int(max_lat): 99 | print('输入经度有误!,右上角的纬度应该大于左下角的纬度值') 100 | exit(0) 101 | 102 | def main(): 103 | #检查输入参数是否正确 104 | check_params() 105 | 106 | all_pois = [] 107 | for index in range(int(WindowSize['xNum'] * WindowSize['yNum'])): 108 | smallRect = getSmallRect(BigRect, WindowSize, index) 109 | 110 | print(smallRect) 111 | pois = requestBaiduApi(keyWords=KeyWord, smallRect=smallRect, baiduAk=baiduAk) 112 | all_pois.extend(pois) 113 | time.sleep(1) 114 | 115 | data_csv = {} 116 | uids, names, provinces, citys, areas, addresses, lngs, lats = [], [], [], [], [], [], [], [] 117 | for poi in all_pois: 118 | if poi == None: 119 | continue 120 | uids.append(poi.get('uid')) 121 | names.append(poi.get('name')) 122 | provinces.append(poi.get('province')) 123 | citys.append(poi.get('city')) 124 | areas.append(poi.get('area')) 125 | addresses.append(poi.get('address')) 126 | location = poi['location'] 127 | lng = location['lng'] 128 | lat = location['lat'] 129 | 130 | result = bd09_to_wgs84(float(lng), float(lat)) 131 | lng = result[0] 132 | lat = result[1] 133 | 134 | lngs.append(lng) 135 | lats.append(lat) 136 | data_csv['uid'] = uids 137 | data_csv['name'] = names 138 | data_csv['province'] = provinces 139 | data_csv['city'] = citys 140 | data_csv['area'] = areas 141 | data_csv['address'] = addresses 142 | data_csv['lng'] = lngs 143 | data_csv['lat'] = lats 144 | 145 | df = pd.DataFrame(data_csv) 146 | data_path = os.getcwd() + os.sep + "data" + os.sep 147 | if not os.path.exists(data_path): 148 | os.mkdir(data_path) 149 | df.to_csv(data_path + "bmap-poi-" + KeyWord + '.csv', index=False, encoding='utf_8_sig') 150 | 151 | 152 | if __name__ == '__main__': 153 | main() 154 | -------------------------------------------------------------------------------- /baidu/boundary/app.py: -------------------------------------------------------------------------------- 1 | 2 | import pandas as pd 3 | import os 4 | import uuid 5 | from transCoordinateSystem import bd09_to_wgs84 6 | import requests,json,math 7 | from requests.adapters import HTTPAdapter 8 | 9 | 10 | #TODO 1.带有UID字段的CSV格式的百度POI数据文件地址,最终爬取的边界数据位于data目录下,文件命名:result-xxx.csv,坐标经纬度为WGS84 11 | file_path = 'data/bmap-poi--park-shanghai.csv' 12 | 13 | 14 | #TODO 2.百度地图服务端密钥 15 | bmap_key = '百度密钥' 16 | 17 | 18 | 19 | def get_boundary_by_uid(uid): 20 | bmap_boundary_url = 'https://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=ext&uid=' + uid + '&c=340&ext_ver=new&tn=B_NORMAL_MAP&nn=0&auth=fw9wVDQUyKS7%3DQ5eWeb5A21KZOG0NadNuxHNBxBBLBHtxjhNwzWWvy1uVt1GgvPUDZYOYIZuEt2gz4yYxGccZcuVtPWv3GuxNt%3DkVJ0IUvhgMZSguxzBEHLNRTVtlEeLZNz1%40Db17dDFC8zv7u%40ZPuxtfvSulnDjnCENTHEHH%40NXBvzXX3M%40J2mmiJ4Y&ie=utf-8&l=19&b=(12679382.095,2565580.38;12679884.095,2565907.38)&t=1573133634785' 21 | 22 | 23 | s = requests.Session() 24 | s.mount('http://', HTTPAdapter(max_retries=3)) 25 | s.mount('https://', HTTPAdapter(max_retries=3)) 26 | 27 | data = s.get(url=bmap_boundary_url, timeout=5, headers={"Connection": "close"}) 28 | data = data.text 29 | data = json.loads(data) 30 | content = data['content'] 31 | if not 'geo' in content: 32 | return None 33 | geo = content['geo'] 34 | i = 0 35 | strsss = '' 36 | for jj in str(geo).split('|')[2].split('-')[1].split(','): 37 | jj = str(jj).strip(';') 38 | if i % 2 == 0: 39 | strsss = strsss + str(jj) + ',' 40 | else: 41 | strsss = strsss + str(jj) + ';' 42 | i = i + 1 43 | return strsss.strip(";") 44 | 45 | def transform_coordinate_batch(coordinates): 46 | cooed_count = math.ceil(len(coordinates) / 100) 47 | 48 | coords = '' 49 | 50 | 51 | for i in range(cooed_count): 52 | one_coords = coordinates.split(";")[i * 100: i * 100 + 100] 53 | one_coords_str = '' 54 | for point in one_coords: 55 | one_coords_str = one_coords_str + point + ";" 56 | 57 | one_coords_str = one_coords_str.strip(";") 58 | print(one_coords_str.strip(";")) 59 | 60 | 61 | req_url = 'http://api.map.baidu.com/geoconv/v1/?coords='+one_coords_str+'&from=6&to=5&ak=' + bmap_key 62 | 63 | s = requests.Session() 64 | s.mount('http://', HTTPAdapter(max_retries=3)) 65 | s.mount('https://', HTTPAdapter(max_retries=3)) 66 | print(req_url) 67 | 68 | data = s.get(req_url, timeout=5, headers={"Connection": "close"}) # , proxies=proxies 69 | data = data.text 70 | try: 71 | data = json.loads(data) 72 | except Exception as e: 73 | print('发送异常,当前坐标:', coordinates) 74 | return ' ' 75 | 76 | if data['status'] == 0: 77 | result = data['result'] 78 | if len(result) > 0: 79 | for res in result: 80 | lng = res['x'] 81 | lat = res['y'] 82 | coords = coords + ";" + str(lng) + "," + str(lat) 83 | print(coords.strip(";")) 84 | return coords.strip(";") 85 | 86 | csv_file = pd.read_csv(file_path, encoding='utf-8') 87 | a_col = [] 88 | data_csv = {} 89 | 90 | uids, boundarys = [], [] 91 | for i in range(len(csv_file)): 92 | uid = csv_file['uid'][i] 93 | uids.append(uid) 94 | 95 | coordinates = get_boundary_by_uid(uid) 96 | if coordinates is not None: 97 | coords = transform_coordinate_batch(coordinates) 98 | print('成功返回边界:', uid + ',' + coords) 99 | boundarys.append(coords) 100 | else: 101 | boundarys.append(' ') 102 | 103 | data_csv['uid'] = uids 104 | 105 | data_csv['boundary'] = boundarys 106 | df = pd.DataFrame(data_csv) 107 | 108 | boundary_result_file_name = 'data' + os.sep + 'temp-' + str(uuid.uuid4()).replace("-", "") + '.csv' 109 | 110 | df.to_csv(boundary_result_file_name, index=False, encoding='gbk') 111 | 112 | 113 | # 将数据处理为ARCGIS能展示多边形的数据格式 114 | csv_file = pd.read_csv(boundary_result_file_name, encoding='gbk') 115 | 116 | a_col = [] 117 | data_csv = {} 118 | numbers, xs, ys, uids = [], [], [], [] 119 | index = 1 120 | for i in range(len(csv_file)): 121 | boundary = str(csv_file['boundary'][i]) 122 | 123 | uid = str(csv_file['uid'][i]) 124 | 125 | if boundary != ' ' and boundary != 'nan' and boundary != None: 126 | for point in boundary.split(";"): 127 | print(boundary) 128 | lng = point.split(",")[0] 129 | lat = point.split(",")[1] 130 | 131 | 132 | #转换为WGS84坐标系 133 | coord_wgs84 = bd09_to_wgs84(float(lng), float(lat)) 134 | lng = coord_wgs84[0] 135 | lat = coord_wgs84[1] 136 | 137 | xs.append(lng) 138 | ys.append(lat) 139 | numbers.append(index) 140 | uids.append(uid) 141 | 142 | index = index + 1 143 | data_csv['number'] = numbers 144 | data_csv['x'] = xs 145 | data_csv['y'] = ys 146 | data_csv['uid'] = uids 147 | 148 | df = pd.DataFrame(data_csv) 149 | 150 | boundary_result_file_name = 'data' + os.sep + 'result-' + str(uuid.uuid4()).replace("-", "") + '.csv' 151 | df.to_csv(boundary_result_file_name, index=False, encoding='gbk') -------------------------------------------------------------------------------- /gaode/poi-province/shp.py: -------------------------------------------------------------------------------- 1 | #-*-coding:utf-8-*- 2 | import csv 3 | import codecs 4 | import os 5 | 6 | import osgeo.ogr as ogr 7 | import osgeo.osr as osr 8 | import osgeo.gdal as gdal 9 | 10 | ''' 11 | shp.py要能正常运行的话需要做如下处理: 12 | 1. 下载gata-data.rar文件夹,地址:https://github.com/wudawxb1995/ForLearn,当前文件夹下也有,并解压到随意一个目录下(没有中文的目录) 13 | 2. 配置环境变量:GDAL_DATA 值为第一步解压后的文件路径 14 | 3.为了解决读取CSV中存在中文的问题,需要设置环境变量:SHAPE_ENCODING UTF-8 15 | 设置完成后重启pycharm工具方可生效 16 | 17 | 18 | 19 | 参考文章:https://blog.csdn.net/zsc201825/article/details/90112302 20 | ''' 21 | 22 | def trans_point_to_shp(folder, fn, idlng, idlat, delimiter=','): 23 | data = [] 24 | with codecs.open(folder + fn, 'rb', 'gbk') as csvfile: 25 | reader = csv.reader(csvfile, delimiter=delimiter) 26 | # skip the header 27 | next(reader, None) 28 | # loop through each of the rows and assign the attributes to variables 29 | for row in reader: 30 | name = row[2] 31 | address = row[3] 32 | pname = row[4] 33 | business_area = row[5] 34 | cityname = row[6] 35 | adname = row[7] 36 | type = row[8] 37 | typecode = row[9] 38 | 39 | type1 = row[10] 40 | type2 = row[11] 41 | type3 = row[12] 42 | type4 = row[13] 43 | id = row[14] 44 | try: 45 | lng = float(row[0]) 46 | lat = float(row[1]) 47 | except Exception: 48 | continue 49 | 50 | data.append([lng, lat, name, address, pname, business_area, cityname, adname, type, typecode, type1, type2, type3, type4]) 51 | 52 | # set up the shapefile driver 53 | 54 | gdal.SetConfigOption('GDAL_FILENAME_IS_UTF8', 'NO') # 解决中文路径 55 | gdal.SetConfigOption('SHAPE_ENCODING', 'utf-8') # 解决SHAPE文件的属性值 56 | 57 | driver = ogr.GetDriverByName("ESRI Shapefile") 58 | 59 | # create the data source 60 | #data_source = driver.CreateDataSource(folder +"sss.shp") 61 | data_source = driver.CreateDataSource(folder + fn.split(".")[0] + ".shp") 62 | # create the spatial reference, WGS84 63 | srs = osr.SpatialReference() 64 | srs.ImportFromEPSG(4326) 65 | 66 | # create the layer 67 | layer = data_source.CreateLayer("volcanoes", srs, ogr.wkbPoint) 68 | 69 | # Add the fields we're interested in 70 | layer.CreateField(ogr.FieldDefn("lng", ogr.OFTReal)) 71 | layer.CreateField(ogr.FieldDefn("lat", ogr.OFTReal)) 72 | 73 | field_name = ogr.FieldDefn("name", ogr.OFTString) 74 | field_name.SetWidth(24) 75 | layer.CreateField(field_name) 76 | layer.CreateField(ogr.FieldDefn("adress", ogr.OFTString)) 77 | layer.CreateField(ogr.FieldDefn("pname", ogr.OFTString)) 78 | layer.CreateField(ogr.FieldDefn("cityname", ogr.OFTString)) 79 | layer.CreateField(ogr.FieldDefn("adname", ogr.OFTString)) 80 | 81 | layer.CreateField(ogr.FieldDefn("type", ogr.OFTString)) 82 | layer.CreateField(ogr.FieldDefn("typecode", ogr.OFTString)) 83 | layer.CreateField(ogr.FieldDefn("type1", ogr.OFTString)) 84 | layer.CreateField(ogr.FieldDefn("type2", ogr.OFTString)) 85 | layer.CreateField(ogr.FieldDefn("type3", ogr.OFTString)) 86 | layer.CreateField(ogr.FieldDefn("type4", ogr.OFTString)) 87 | layer.CreateField(ogr.FieldDefn("id", ogr.OFTString)) 88 | 89 | 90 | # Process the text file and add the attributes and features to the shapefile 91 | 92 | 93 | 94 | for row in data: 95 | # create the feature 96 | feature = ogr.Feature(layer.GetLayerDefn()) 97 | # Set the attributes using the values from the delimited text file 98 | feature.SetField("lng", row[0]) 99 | feature.SetField("lat", row[1]) 100 | feature.SetField("name", row[2]) 101 | feature.SetField("adress", row[3]) 102 | feature.SetField("pname", row[4]) 103 | 104 | feature.SetField("cityname", row[5]) 105 | feature.SetField("adname", row[6]) 106 | feature.SetField("type", row[7]) 107 | feature.SetField("typecode", row[8]) 108 | feature.SetField("type1", row[9]) 109 | feature.SetField("type2", row[10]) 110 | feature.SetField("type3", row[11]) 111 | feature.SetField("type4", row[12]) 112 | feature.SetField("id", row[13]) 113 | 114 | 115 | # create the WKT for the feature using Python string formatting 116 | wkt = "POINT(%f %f)" % (float(row[0]), float(row[1])) 117 | 118 | # Create the point from the Well Known Txt 119 | point = ogr.CreateGeometryFromWkt(wkt) 120 | 121 | # Set the feature geometry using the point 122 | feature.SetGeometry(point) 123 | # Create the feature in the layer (shapefile) 124 | layer.CreateFeature(feature) 125 | # Dereference the feature 126 | feature = None 127 | 128 | # Save and close the data source 129 | data_source = None 130 | 131 | 132 | 133 | if __name__ == '__main__': 134 | folder = 'C:\\study\\python\\studyws\\code_20191103\\data\\si-chuan-sheng\\010103' + os.sep 135 | 136 | #folder = 'C:\\study\\python\\studyws\\poi-根据分类编码爬取-导出可选CSV并生成shp\\data\\四川省\\010000' + os.sep 137 | fn = 'poi-si-chuan-sheng-010103.csv' 138 | #fn = 'poi-四川省-010000.csv' 139 | idlng = 0 140 | idlat = 1 141 | trans_point_to_shp(folder, fn, idlng, idlat) 142 | 143 | -------------------------------------------------------------------------------- /gaode/poi-pology/shp.py: -------------------------------------------------------------------------------- 1 | #-*-coding:utf-8-*- 2 | import csv 3 | import codecs 4 | import os 5 | 6 | import osgeo.ogr as ogr 7 | import osgeo.osr as osr 8 | import osgeo.gdal as gdal 9 | 10 | 11 | ''' 12 | shp.py要能正常运行的话需要做如下处理: 13 | 1. 下载gata-data.rar文件夹,地址:https://github.com/wudawxb1995/ForLearn,当前文件夹下也有,并解压到随意一个目录下(没有中文的目录) 14 | 2. 配置环境变量:GDAL_DATA 值为第一步解压后的文件路径 15 | 3.为了解决读取CSV中存在中文的问题,需要设置环境变量:SHAPE_ENCODING UTF-8 16 | 设置完成后重启pycharm工具方可生效 17 | 18 | 参考文章:https://blog.csdn.net/zsc201825/article/details/90112302 19 | ''' 20 | 21 | def trans_point_to_shp(folder, fn, idlng, idlat, pology_split_distance, delimiter=','): 22 | data = [] 23 | with codecs.open(folder + fn, 'rb', 'utf_8_sig') as csvfile: 24 | reader = csv.reader(csvfile, delimiter=delimiter) 25 | # skip the header 26 | next(reader, None) 27 | # loop through each of the rows and assign the attributes to variables 28 | ''' 29 | data_csv['lon'], data_csv['lat'], data_csv['name'], data_csv['address'], data_csv['pname'], \ 30 | data_csv['cityname'], data_csv['business_area'], data_csv['type'], data_csv['typecode'], data_csv['id'], data_csv[ 31 | 'type1'], data_csv['type2'], data_csv['type3'], data_csv['type4'] 32 | ''' 33 | for row in reader: 34 | name = row[2] 35 | address = row[3] 36 | pname = row[4] 37 | cityname = row[5] 38 | business_area = row[6] 39 | type = row[7] 40 | typecode = row[8] 41 | type1 = row[10] 42 | type2 = row[11] 43 | type3 = row[12] 44 | type4 = row[13] 45 | id = row[9] 46 | try: 47 | lng = float(row[0]) 48 | lat = float(row[1]) 49 | except Exception: 50 | continue 51 | 52 | data.append([lng, lat, name, address, pname, business_area, cityname, type, typecode, type1, type2, type3, type4, id]) 53 | 54 | # set up the shapefile driver 55 | 56 | gdal.SetConfigOption('GDAL_FILENAME_IS_UTF8', 'NO') # 解决中文路径 57 | gdal.SetConfigOption('SHAPE_ENCODING', 'gbk') # 解决SHAPE文件的属性值 58 | 59 | driver = ogr.GetDriverByName("ESRI Shapefile") 60 | 61 | # create the data source 62 | #data_source = driver.CreateDataSource(folder +"sss.shp") 63 | data_source = driver.CreateDataSource(folder + fn.split(".")[0] + "-" + str(pology_split_distance) + ".shp") 64 | # create the spatial reference, WGS84 65 | srs = osr.SpatialReference() 66 | srs.ImportFromEPSG(4326) 67 | 68 | # create the layer 69 | layer = data_source.CreateLayer("volcanoes", srs, ogr.wkbPoint) 70 | 71 | # Add the fields we're interested in 72 | layer.CreateField(ogr.FieldDefn("lng", ogr.OFTReal)) 73 | layer.CreateField(ogr.FieldDefn("lat", ogr.OFTReal)) 74 | 75 | field_name = ogr.FieldDefn("name", ogr.OFTString) 76 | field_name.SetWidth(24) 77 | layer.CreateField(field_name) 78 | layer.CreateField(ogr.FieldDefn("adress", ogr.OFTString)) 79 | layer.CreateField(ogr.FieldDefn("pname", ogr.OFTString)) 80 | layer.CreateField(ogr.FieldDefn("cityname", ogr.OFTString)) 81 | 82 | layer.CreateField(ogr.FieldDefn("type", ogr.OFTString)) 83 | layer.CreateField(ogr.FieldDefn("typecode", ogr.OFTString)) 84 | layer.CreateField(ogr.FieldDefn("type1", ogr.OFTString)) 85 | layer.CreateField(ogr.FieldDefn("type2", ogr.OFTString)) 86 | layer.CreateField(ogr.FieldDefn("type3", ogr.OFTString)) 87 | layer.CreateField(ogr.FieldDefn("type4", ogr.OFTString)) 88 | layer.CreateField(ogr.FieldDefn("id", ogr.OFTString)) 89 | 90 | 91 | # Process the text file and add the attributes and features to the shapefile 92 | 93 | 94 | 95 | for row in data: 96 | # create the feature 97 | feature = ogr.Feature(layer.GetLayerDefn()) 98 | # Set the attributes using the values from the delimited text file 99 | #[lng, lat, name, address, pname, business_area, cityname, type, typecode, type1, type2, type3, type4, id] 100 | feature.SetField("lng", row[0]) 101 | feature.SetField("lat", row[1]) 102 | feature.SetField("name", row[2]) 103 | feature.SetField("adress", row[3]) 104 | feature.SetField("pname", row[4]) 105 | 106 | feature.SetField("business_area", row[5]) 107 | feature.SetField("cityname", row[6]) 108 | feature.SetField("type", row[7]) 109 | feature.SetField("typecode", row[8]) 110 | feature.SetField("type1", row[9]) 111 | feature.SetField("type2", row[10]) 112 | feature.SetField("type3", row[11]) 113 | feature.SetField("type4", row[12]) 114 | feature.SetField("id", row[13]) 115 | 116 | 117 | # create the WKT for the feature using Python string formatting 118 | wkt = "POINT(%f %f)" % (float(row[0]), float(row[1])) 119 | 120 | # Create the point from the Well Known Txt 121 | point = ogr.CreateGeometryFromWkt(wkt) 122 | 123 | # Set the feature geometry using the point 124 | feature.SetGeometry(point) 125 | # Create the feature in the layer (shapefile) 126 | layer.CreateFeature(feature) 127 | # Dereference the feature 128 | feature = None 129 | 130 | # Save and close the data source 131 | data_source = None 132 | 133 | 134 | 135 | if __name__ == '__main__': 136 | folder = 'C:\\Users\\hgvgh\\Desktop\\poi_150100_050000' + os.sep 137 | 138 | #folder = 'C:\\study\\python\\studyws\\poi-根据分类编码爬取-导出可选CSV并生成shp\\data\\四川省\\010000' + os.sep 139 | fn = 'poi_150100_050000.csv' 140 | #fn = 'poi-四川省-010000.csv' 141 | idlng = 0 142 | idlat = 1 143 | trans_point_to_shp(folder, fn, idlng, idlat) 144 | 145 | -------------------------------------------------------------------------------- /gaode/poi-city/app.py: -------------------------------------------------------------------------------- 1 | from urllib.parse import quote 2 | from urllib import request 3 | import json 4 | import os 5 | import xlwt 6 | import pandas as pd 7 | from transCoordinateSystem import gcj02_to_wgs84, gcj02_to_bd09 8 | #from shp import trans_point_to_shp 9 | 10 | ''' 11 | 版本更新说明: 12 | 13 | 2019.10.05: 14 | 1. 数据导出格式支持CSV格式以及XLS两种格式; 15 | 2. 支持同时采集多个城市的POI数据; 16 | 3. 支持同时采集多个POI分类数据 17 | 18 | 2019.10.10: 19 | 1. 数据导出支持CSV以及XLS两种格式; 20 | 2. CSV格式数据会生成.shp文件,可以直接在ARCGIS中使用 21 | 22 | 2020.06.19: 23 | 1.清除了poi数据写入shp文件相关操作 24 | 2.修改为根据POI分类关键字来爬取,而不是分类编码 25 | ''' 26 | 27 | #################################################需要修改########################################################### 28 | 29 | # TODO 1.替换为从高德开放平台上申请申请的密钥 30 | amap_web_key = '申请的高德web秘钥' 31 | 32 | # TODO 2.分类关键字,最好对照<<高德地图POI分类关键字以及编码.xlsx>>来填写对应分类关键字(不是编码),多个用逗号隔开 33 | keyword = ['大学'] 34 | 35 | # TODO 3.城市,多个用逗号隔开 36 | city = ['北京'] 37 | 38 | # TODO 4.输出数据坐标系,1为高德GCJ20坐标系,2WGS84坐标系,3百度BD09坐标系 39 | coord = 2 40 | 41 | # TODO 5. 输出数据文件格式,1为默认xls格式,2为csv格式 42 | data_file_format = 2 43 | 44 | ############################################以下不需要动####################################################################### 45 | 46 | 47 | poi_search_url = "http://restapi.amap.com/v3/place/text" 48 | poi_boundary_url = "https://ditu.amap.com/detail/get/detail" 49 | 50 | 51 | # 根据城市名称和分类关键字获取poi数据 52 | def getpois(cityname, keywords): 53 | i = 1 54 | poilist = [] 55 | while True: # 使用while循环不断分页获取数据 56 | result = getpoi_page(cityname, keywords, i) 57 | print(result) 58 | result = json.loads(result) # 将字符串转换为json 59 | if result['count'] == '0': 60 | break 61 | 62 | hand(poilist, result) 63 | i = i + 1 64 | return poilist 65 | 66 | 67 | # 数据写入excel 68 | def write_to_excel(poilist, cityname, classfield): 69 | # 一个Workbook对象,这就相当于创建了一个Excel文件 70 | book = xlwt.Workbook(encoding='utf-8', style_compression=0) 71 | sheet = book.add_sheet(classfield, cell_overwrite_ok=True) 72 | 73 | # 第一行(列标题) 74 | sheet.write(0, 0, 'lon') 75 | sheet.write(0, 1, 'lat') 76 | sheet.write(0, 2, 'name') 77 | sheet.write(0, 3, 'address') 78 | sheet.write(0, 4, 'pname') 79 | sheet.write(0, 5, 'cityname') 80 | sheet.write(0, 6, 'business_area') 81 | sheet.write(0, 7, 'type') 82 | 83 | for i in range(len(poilist)): 84 | location = poilist[i].get('location') 85 | name = poilist[i].get('name') 86 | address = poilist[i].get('address') 87 | pname = poilist[i].get('pname') 88 | cityname = poilist[i].get('cityname') 89 | business_area = poilist[i].get('business_area') 90 | type = poilist[i].get('type') 91 | lng = str(location).split(",")[0] 92 | lat = str(location).split(",")[1] 93 | 94 | if (coord == 2): 95 | result = gcj02_to_wgs84(float(lng), float(lat)) 96 | lng = result[0] 97 | lat = result[1] 98 | if (coord == 3): 99 | result = gcj02_to_bd09(float(lng), float(lat)) 100 | lng = result[0] 101 | lat = result[1] 102 | 103 | # 每一行写入 104 | sheet.write(i + 1, 0, lng) 105 | sheet.write(i + 1, 1, lat) 106 | sheet.write(i + 1, 2, name) 107 | sheet.write(i + 1, 3, address) 108 | sheet.write(i + 1, 4, pname) 109 | sheet.write(i + 1, 5, cityname) 110 | sheet.write(i + 1, 6, business_area) 111 | sheet.write(i + 1, 7, type) 112 | 113 | # 最后,将以上操作保存到指定的Excel文件中 114 | book.save(r'data' + os.sep + 'poi-' + cityname + "-" + classfield + ".xls") 115 | 116 | 117 | # 数据写入csv文件中 118 | def write_to_csv(poilist, cityname, classfield): 119 | data_csv = {} 120 | lons, lats, names, addresss, pnames, citynames, business_areas, types = [], [], [], [], [], [], [], [] 121 | 122 | for i in range(len(poilist)): 123 | print('===================') 124 | print(poilist[i]) 125 | location = poilist[i].get('location') 126 | name = poilist[i].get('name') 127 | address = poilist[i].get('address') 128 | pname = poilist[i].get('pname') 129 | cityname = poilist[i].get('cityname') 130 | business_area = poilist[i].get('business_area') 131 | type = poilist[i].get('type') 132 | lng = str(location).split(",")[0] 133 | lat = str(location).split(",")[1] 134 | 135 | if (coord == 2): 136 | result = gcj02_to_wgs84(float(lng), float(lat)) 137 | lng = result[0] 138 | lat = result[1] 139 | if (coord == 3): 140 | result = gcj02_to_bd09(float(lng), float(lat)) 141 | lng = result[0] 142 | lat = result[1] 143 | lons.append(lng) 144 | lats.append(lat) 145 | names.append(name) 146 | addresss.append(address) 147 | pnames.append(pname) 148 | citynames.append(cityname) 149 | if business_area == []: 150 | business_area = '' 151 | business_areas.append(business_area) 152 | types.append(type) 153 | data_csv['lon'], data_csv['lat'], data_csv['name'], data_csv['address'], data_csv['pname'], \ 154 | data_csv['cityname'], data_csv['business_area'], data_csv['type'] = \ 155 | lons, lats, names, addresss, pnames, citynames, business_areas, types 156 | 157 | df = pd.DataFrame(data_csv) 158 | 159 | folder_name = 'poi-' + cityname + "-" + classfield 160 | folder_name_full = 'data' + os.sep + folder_name + os.sep 161 | if os.path.exists(folder_name_full) is False: 162 | os.makedirs(folder_name_full) 163 | 164 | file_name = 'poi-' + cityname + "-" + classfield + ".csv" 165 | file_path = folder_name_full + file_name 166 | 167 | df.to_csv(file_path, index=False, encoding='utf_8_sig') 168 | return folder_name_full, file_name 169 | 170 | 171 | # 将返回的poi数据装入集合返回 172 | def hand(poilist, result): 173 | # result = json.loads(result) # 将字符串转换为json 174 | pois = result['pois'] 175 | for i in range(len(pois)): 176 | poilist.append(pois[i]) 177 | 178 | 179 | # 单页获取pois 180 | def getpoi_page(cityname, keywords, page): 181 | req_url = poi_search_url + "?key=" + amap_web_key + '&extensions=all&keywords=' + quote( 182 | keywords) + '&city=' + quote(cityname) + '&citylimit=true' + '&offset=25' + '&page=' + str( 183 | page) + '&output=json' 184 | data = '' 185 | print('============请求url:' + req_url) 186 | with request.urlopen(req_url) as f: 187 | data = f.read() 188 | data = data.decode('utf-8') 189 | return data 190 | 191 | 192 | def get_areas(code): 193 | ''' 194 | 获取城市的所有区域 195 | :param code: 196 | :return: 197 | ''' 198 | 199 | print('获取城市的所有区域:code: ' + str(code).strip()) 200 | data = get_distrinctNoCache(code) 201 | 202 | print('get_distrinct result:' + data) 203 | 204 | data = json.loads(data) 205 | 206 | districts = data['districts'][0]['districts'] 207 | # 判断是否是直辖市 208 | # 北京市、上海市、天津市、重庆市。 209 | if (code.startswith('重庆') or code.startswith('上海') or code.startswith('北京') or code.startswith('天津')): 210 | districts = data['districts'][0]['districts'][0]['districts'] 211 | 212 | i = 0 213 | area = "" 214 | for district in districts: 215 | name = district['name'] 216 | adcode = district['adcode'] 217 | i = i + 1 218 | area = area + "," + adcode 219 | 220 | print(area) 221 | print(str(area).strip(',')) 222 | return str(area).strip(',') 223 | 224 | 225 | def get_data(city, keyword): 226 | ''' 227 | 根据城市名以及POI类型爬取数据 228 | :param city: 229 | :param keyword: 230 | :return: 231 | ''' 232 | isNeedAreas = True 233 | if isNeedAreas: 234 | area = get_areas(city) 235 | all_pois = [] 236 | if area != None and area != "": 237 | area_list = str(area).split(",") 238 | if area_list == 0: 239 | area_list = str(area).split(",") 240 | 241 | for area in area_list: 242 | pois_area = getpois(area, keyword) 243 | print('当前城区:' + str(area) + ', 分类:' + str(keyword) + ", 总的有" + str(len(pois_area)) + "条数据") 244 | all_pois.extend(pois_area) 245 | print("所有城区的数据汇总,总数为:" + str(len(all_pois))) 246 | if data_file_format == 2: 247 | # 写入CSV 248 | file_folder, file_name = write_to_csv(all_pois, city, keyword) 249 | # 写入SHP 250 | #trans_point_to_shp(file_folder, file_name, 0, 1) 251 | return 252 | return write_to_excel(all_pois, city, keyword) 253 | else: 254 | pois_area = getpois(city, keyword) 255 | if data_file_format == 2: 256 | # 写入CSV 257 | file_folder, file_name = write_to_csv(all_pois, city, keyword) 258 | # 写入SHP 259 | #trans_point_to_shp(file_folder, file_name, 0, 1) 260 | return 261 | return write_to_excel(pois_area, city, keyword) 262 | 263 | return None 264 | 265 | 266 | def get_distrinctNoCache(code): 267 | ''' 268 | 获取中国城市行政区划 269 | :return: 270 | ''' 271 | 272 | url = "https://restapi.amap.com/v3/config/district?subdistrict=2&extensions=all&key=" + amap_web_key 273 | 274 | req_url = url + "&keywords=" + quote(code) 275 | 276 | print(req_url) 277 | 278 | with request.urlopen(req_url) as f: 279 | data = f.read() 280 | data = data.decode('utf-8') 281 | print(code, data) 282 | return data 283 | 284 | 285 | if __name__ == '__main__': 286 | 287 | for ct in city: 288 | for type in keyword: 289 | get_data(ct, type) 290 | print('总的', len(city), '个城市, ', len(keyword), '个分类数据全部爬取完成!') 291 | 292 | -------------------------------------------------------------------------------- /gaode/poi-pology/app.py: -------------------------------------------------------------------------------- 1 | #! /usr/local/bin/python3 2 | # coding: utf-8 3 | # __author__ = "Liu jiao" 4 | # __date__ = 2019/10/16 16:11 5 | 6 | 7 | from urllib.parse import quote 8 | import json 9 | import os 10 | from transCoordinateSystem import gcj02_to_wgs84, gcj02_to_bd09 11 | import area_boundary as area_boundary 12 | import city_grid as city_grid 13 | import time 14 | import collections 15 | import pandas as pd 16 | from requests.adapters import HTTPAdapter 17 | import requests 18 | 19 | #from shp import trans_point_to_shp 20 | 21 | 22 | ''' 23 | 版本更新说明: 24 | 2020.06.19: 25 | 1.清除了poi数据写入shp文件相关操作 26 | 27 | ''' 28 | 29 | #################################################需要修改########################################################### 30 | 31 | ## TODO 1.划分的网格距离,0.02-0.05最佳,建议如果是数量比较多的用0.01或0.02,如餐厅,企业。数据量少的用0.05或者更大,如大学 32 | pology_split_distance = 0.5 33 | 34 | ## TODO 2. 城市编码,参见高德城市编码表,注意需要用adcode列的编码 35 | city_code = '150100' 36 | 37 | ## TODO 3. POI类型编码,类型名或者编码都行,具体参见《高德地图POI分类编码表.xlsx》 38 | typs = ['加油站'] # ['企业', '公园', '广场', '风景名胜', '小学'] 39 | 40 | ## TODO 4. 高德开放平台密钥 41 | gaode_key = ['高德秘钥1', '高德秘钥2'] 42 | 43 | # TODO 5.输出数据坐标系,1为高德GCJ20坐标系,2WGS84坐标系,3百度BD09坐标系 44 | coord = 2 45 | 46 | ############################################以下不需要动####################################################################### 47 | 48 | 49 | poi_pology_search_url = 'https://restapi.amap.com/v3/place/polygon' 50 | 51 | buffer_keys = collections.deque(maxlen=len(gaode_key)) 52 | 53 | 54 | def init_queen(): 55 | for i in range(len(gaode_key)): 56 | buffer_keys.append(gaode_key[i]) 57 | print('当前可供使用的高德密钥:', buffer_keys) 58 | 59 | 60 | # 根据城市名称和分类关键字获取poi数据 61 | def getpois(grids, keywords): 62 | if buffer_keys.maxlen == 0: 63 | print('密钥已经用尽,程序退出!!!!!!!!!!!!!!!') 64 | exit(0) 65 | amap_key = buffer_keys[0] # 总是获取队列中的第一个密钥 66 | 67 | i = 1 68 | poilist = [] 69 | while True: # 使用while循环不断分页获取数据 70 | result = getpoi_page(grids, keywords, i, amap_key) 71 | print("当前爬取结果:", result) 72 | if result != None: 73 | result = json.loads(result) # 将字符串转换为json 74 | try: 75 | if result['count'] == '0': 76 | break 77 | except Exception as e: 78 | print('出现异常:', e) 79 | 80 | if result['infocode'] == '10001' or result['infocode'] == '10003': 81 | print(result) 82 | print('无效的密钥!!!!!!!!!!!!!,重新切换密钥进行爬取') 83 | buffer_keys.remove(buffer_keys[0]) 84 | try: 85 | amap_key = buffer_keys[0] # 总是获取队列中的第一个密钥 86 | except Exception as e: 87 | print('密钥已经用尽,程序退出...') 88 | exit(0) 89 | result = getpoi_page(grids, keywords, i, amap_key) 90 | result = json.loads(result) 91 | hand(poilist, result) 92 | i = i + 1 93 | return poilist 94 | 95 | 96 | # 数据写入csv文件中 97 | def write_to_csv(poilist, citycode, classfield, coord): 98 | data_csv = {} 99 | lons, lats, names, addresss, pnames, citynames, business_areas, types, typecodes, ids, type_1s, type_2s, type_3s, type_4s = [], [], [], [], [], [], [], [], [], [], [], [], [], [] 100 | 101 | if len(poilist) == 0: 102 | print("处理完成,当前citycode:" + str(citycode), ", classfield为:", str(classfield) + ",数据为空,,,结束.......") 103 | return None, None 104 | 105 | for i in range(len(poilist)): 106 | location = poilist[i].get('location') 107 | name = poilist[i].get('name') 108 | address = poilist[i].get('address') 109 | pname = poilist[i].get('pname') 110 | cityname = poilist[i].get('cityname') 111 | business_area = poilist[i].get('business_area') 112 | type = poilist[i].get('type') 113 | typecode = poilist[i].get('typecode') 114 | lng = str(location).split(",")[0] 115 | lat = str(location).split(",")[1] 116 | id = poilist[i].get('id') 117 | 118 | if (coord == 2): 119 | result = gcj02_to_wgs84(float(lng), float(lat)) 120 | lng = result[0] 121 | lat = result[1] 122 | if (coord == 3): 123 | result = gcj02_to_bd09(float(lng), float(lat)) 124 | lng = result[0] 125 | lat = result[1] 126 | type_1, type_2, type_3, type_4 = '','','','' 127 | if str(type) != None and str(type) != '': 128 | type_strs = type.split(';') 129 | for i in range(len(type_strs)): 130 | ty = type_strs[i] 131 | if i == 0: 132 | type_1 = ty 133 | elif i == 1: 134 | type_2 = ty 135 | elif i == 2: 136 | type_3 = ty 137 | elif i == 3: 138 | type_4 = ty 139 | 140 | lons.append(lng) 141 | lats.append(lat) 142 | names.append(name) 143 | addresss.append(address) 144 | pnames.append(pname) 145 | citynames.append(cityname) 146 | if business_area == []: 147 | business_area = '' 148 | business_areas.append(business_area) 149 | types.append(type) 150 | typecodes.append(typecode) 151 | ids.append(id) 152 | type_1s.append(type_1) 153 | type_2s.append(type_2) 154 | type_3s.append(type_3) 155 | type_4s.append(type_4) 156 | data_csv['lon'], data_csv['lat'], data_csv['name'], data_csv['address'], data_csv['pname'], \ 157 | data_csv['cityname'], data_csv['business_area'], data_csv['type'], data_csv['typecode'], data_csv['id'], data_csv[ 158 | 'type1'], data_csv['type2'], data_csv['type3'], data_csv['type4'] = \ 159 | lons, lats, names, addresss, pnames, citynames, business_areas, types, typecodes, ids, type_1s, type_2s, type_3s, type_4s 160 | 161 | df = pd.DataFrame(data_csv) 162 | 163 | folder_name = 'poi-' + citycode + "-" + classfield 164 | folder_name_full = 'data' + os.sep + folder_name + os.sep 165 | if os.path.exists(folder_name_full) is False: 166 | os.makedirs(folder_name_full) 167 | file_name = 'poi-' + citycode + "-" + classfield + ".csv" 168 | file_path = folder_name_full + file_name 169 | df.to_csv(file_path, index=False, encoding='utf_8_sig') 170 | print('写入成功') 171 | return folder_name_full, file_name 172 | 173 | 174 | # 将返回的poi数据装入集合返回 175 | def hand(poilist, result): 176 | # result = json.loads(result) # 将字符串转换为json 177 | pois = result['pois'] 178 | for i in range(len(pois)): 179 | poilist.append(pois[i]) 180 | 181 | 182 | # 单页获取pois 183 | def getpoi_page(grids, types, page, key): 184 | polygon = str(grids[0]) + "," + str(grids[1]) + "|" + str(grids[2]) + "," + str(grids[3]) 185 | req_url = poi_pology_search_url + "?key=" + key + '&extensions=all&types=' + quote( 186 | types) + '&polygon=' + polygon + '&offset=25' + '&page=' + str( 187 | page) + '&output=json' 188 | print('请求url:', req_url) 189 | 190 | s = requests.Session() 191 | s.mount('http://', HTTPAdapter(max_retries=5)) 192 | s.mount('https://', HTTPAdapter(max_retries=5)) 193 | try: 194 | data = s.get(req_url, timeout=5) 195 | return data.text 196 | except requests.exceptions.RequestException as e: 197 | data = s.get(req_url, timeout=5) 198 | return data.text 199 | return None 200 | 201 | 202 | def get_drids(min_lng, max_lat, max_lng, min_lat, keyword, key, pology_split_distance, all_grids): 203 | grids_lib = city_grid.generate_grids(min_lng, max_lat, max_lng, min_lat, pology_split_distance) 204 | 205 | print('划分后的网格数:', len(grids_lib)) 206 | print(grids_lib) 207 | 208 | # 3. 根据生成的网格爬取数据,验证网格大小是否合适,如果不合适的话,需要继续切分网格 209 | for grid in grids_lib: 210 | one_pology_data = getpoi_page(grid, keyword, 1, key) 211 | data = json.loads(one_pology_data) 212 | print(data) 213 | 214 | while int(data['count']) > 890: 215 | get_drids(grid[0], grid[1], grid[2], grid[3], keyword, key, pology_split_distance / 2, all_grids) 216 | 217 | 218 | all_grids.append(grid) 219 | return all_grids 220 | 221 | 222 | def get_data(city, keyword, coord): 223 | # 1. 获取城市边界的最大、最小经纬度 224 | amap_key = buffer_keys[0] # 总是获取队列中的第一个密钥 225 | max_lng, min_lng, max_lat, min_lat = area_boundary.getlnglat(city, amap_key) 226 | 227 | print('当前城市:', city, "max_lng, min_lng, max_lat, min_lat:", max_lng, min_lng, max_lat, min_lat) 228 | 229 | # 2. 生成网格切片格式: 230 | 231 | grids_lib = city_grid.generate_grids(min_lng, max_lat, max_lng, min_lat, pology_split_distance) 232 | 233 | print('划分后的网格数:', len(grids_lib)) 234 | print(grids_lib) 235 | 236 | all_data = [] 237 | begin_time = time.time() 238 | 239 | print('==========================正式开始爬取啦!!!!!!!!!!!================================') 240 | 241 | for grid in grids_lib: 242 | # grid格式:[112.23, 23.23, 112.24, 23.22] 243 | one_pology_data = getpois(grid, keyword) 244 | 245 | print('===================================当前矩形范围:', grid, '总共:', 246 | str(len(one_pology_data)) + "条数据.............................") 247 | 248 | all_data.extend(one_pology_data) 249 | 250 | end_time = time.time() 251 | print('全部:', str(len(grids_lib)) + '个矩形范围', '总的', str(len(all_data)), '条数据, 耗时:', str(end_time - begin_time), 252 | '正在写入CSV文件中') 253 | file_folder, file_name = write_to_csv(all_data, city, keyword, coord) 254 | # 写入shp 255 | #if file_folder is not None: 256 | #trans_point_to_shp(file_folder, file_name, 0, 1, pology_split_distance, keyword) 257 | 258 | 259 | if __name__ == '__main__': 260 | # 初始化密钥队列 261 | init_queen() 262 | 263 | for type in typs: 264 | get_data(city_code, type, coord) 265 | -------------------------------------------------------------------------------- /gaode/poi-province/app.py: -------------------------------------------------------------------------------- 1 | from urllib.parse import quote 2 | from urllib import request 3 | import json 4 | import os 5 | import collections 6 | import pandas as pd 7 | from xpinyin import Pinyin 8 | from transCoordinateSystem import gcj02_to_wgs84, gcj02_to_bd09 9 | import random 10 | #from shp import trans_point_to_shp 11 | 12 | ''' 13 | 版本更新说明: 14 | 2019.10.05: 15 | 1. 数据导出格式支持CSV、shp格式以及XLS格式; 16 | 2. 支持同时采集多个城市的POI数据; 17 | 3. 支持同时采集多个POI分类数据 18 | 19 | 2020.06.19: 20 | 1.清除了poi数据写入shp文件相关操作 21 | ''' 22 | 23 | #################################################需要修改########################################################### 24 | 25 | # TODO 1.替换为上面申请的密钥,支持多个,如果单个失效了,会自动切换密钥 26 | amap_web_key = ['高德秘钥1', '高德秘钥2'] 27 | 28 | # TODO 2.分类关键字,最好对照<<高德地图POI分类关键字以及编码.xlsx>>来填写对应编码,多个用逗号隔开 29 | keyword = ['010600', '010700'] 30 | 31 | 32 | # TODO 3.省名,最好单个爬,比较耗时 33 | province = ['云南'] 34 | 35 | # TODO 4.输出数据坐标系,1为高德GCJ20坐标系,2WGS84坐标系,3百度BD09坐标系 36 | coord = 2 37 | 38 | # TODO 5. 输出数据文件格式,1为默认xls格式,2为csv+shp格式 39 | data_file_format = 2 40 | 41 | 42 | ############################################以下不需要动####################################################################### 43 | 44 | 45 | print('总的有', len(keyword), '个待爬POI') 46 | 47 | poi_search_url = "http://restapi.amap.com/v3/place/text" 48 | poi_boundary_url = "https://ditu.amap.com/detail/get/detail" 49 | 50 | 51 | buffer_keys = collections.deque(maxlen=len(amap_web_key)) 52 | def init_queen(): 53 | for i in range(len(amap_web_key)): 54 | buffer_keys.append(amap_web_key[i]) 55 | print('当前可供使用的高德密钥:', buffer_keys) 56 | 57 | def get_districthtml(province):#province的html 58 | 59 | if buffer_keys.maxlen == 0: 60 | print('密钥已经用尽,程序退出!!!!!!!!!!!!!!!') 61 | exit(0) 62 | amap_key = buffer_keys[0] #总是获取队列中的第一个密钥 63 | print('获取到的队列中的密钥:', amap_key) 64 | url = "https://restapi.amap.com/v3/config/district?subdistrict=1&extensions=all&key=" + amap_key 65 | req_url = url + "&keywords=" + quote(str(province)) 66 | print(req_url) 67 | 68 | with request.urlopen(req_url) as f: 69 | HTML = f.read() 70 | HTML = HTML.decode('utf-8') 71 | print(province, HTML) 72 | HTML = json.loads(HTML) 73 | 74 | districts = HTML['districts'][0]['districts'] 75 | city_codes = [] 76 | city_names = [] 77 | for district in districts: 78 | name = district['name'] 79 | adcode = district['adcode'] 80 | city_codes.append(adcode) 81 | city_names.append(name) 82 | return city_codes, city_names 83 | 84 | 85 | def get_random_key(): 86 | return amap_web_key[random.randint(0, len(amap_web_key) - 1)] 87 | 88 | # 根据城市名称/area名称和分类关键字获取poi数据 89 | def getpois(area, keywords, poilist, city, area_name): #输入city或者area均可 本文是area 90 | i = 1 91 | while True: # 使用while循环不断分页获取数据 92 | result = getpoi_page(area, keywords, i) 93 | print(result) 94 | 95 | if result['count'] == '0': 96 | break 97 | hand(poilist, result, city, area_name) 98 | i = i + 1 99 | return poilist 100 | 101 | 102 | # 将返回的poi数据装入集合返回 103 | def hand(poilist, result, city, area_name): 104 | 105 | print('result:', result) 106 | # result = json.loads(result) # 将字符串转换为json 107 | pois = result['pois'] 108 | for i in range(len(pois)): 109 | pois 110 | poilist.append(pois[i]) 111 | # 单页获取pois 112 | def getpoi_page(cityname, keywords, page): 113 | if buffer_keys.maxlen == 0: 114 | print('密钥已经用尽,程序退出!!!!!!!!!!!!!!!') 115 | exit(0) 116 | amap_key = buffer_keys[0] #总是获取队列中的第一个密钥 117 | print('获取到的队列中的密钥:', amap_key) 118 | 119 | req_url = poi_search_url + "?key=" + amap_key + '&extensions=all&types=' + quote( 120 | keywords) + '&city=' + quote(cityname) + '&citylimit=true' + '&offset=25' + '&page=' + str( 121 | page) + '&output=json' 122 | ''' 123 | http: // restapi.amap.com / v3 / place / text?keywords = 北京大学 & city = beijing & output = xml 124 | & offset = 20 & page = 1 & key = < 用户的key > & extensions = all 125 | ''' 126 | try: 127 | with request.urlopen(req_url, timeout=3, ) as f: 128 | data = f.read() 129 | data = data.decode('utf-8') 130 | except Exception as e: 131 | print('请求异常') 132 | return getpoi_page(cityname, keywords, page) 133 | 134 | data = json.loads(data) 135 | 136 | print('当前密钥:', amap_key, '请求url :', req_url, '返回结果:', data) 137 | print('返回结果:', data) 138 | if data['status'] == '0': # 请求成功,但是返回数据失败 139 | if data['infocode'] == '10001': 140 | print('无效的密钥!!!!!!!!!!!!!,重新切换密钥进行爬取') 141 | buffer_keys.remove(buffer_keys[0]) 142 | return getpoi_page(cityname, keywords, page) 143 | if data['infocode'] == '10003': 144 | print('当前key访问已超出日访问量!!!!!!!!!!!!!') 145 | buffer_keys.remove(buffer_keys[0]) 146 | return getpoi_page(cityname, keywords, page) 147 | print('其他错误:', data['info']) 148 | 149 | return data 150 | 151 | 152 | 153 | 154 | def get_distrinctNoCache(city):#city的html 155 | if buffer_keys.maxlen == 0: 156 | print('密钥已经用尽,程序退出!!!!!!!!!!!!!!!') 157 | exit(0) 158 | amap_key = buffer_keys[0] #总是获取队列中的第一个密钥 159 | print('获取到的队列中的密钥:', amap_key) 160 | url = "https://restapi.amap.com/v3/config/district?subdistrict=2&extensions=all&key=" + amap_key 161 | req_url = url + "&keywords=" + quote(city) 162 | print(req_url) 163 | with request.urlopen(req_url) as f: 164 | data = f.read() 165 | data = data.decode('utf-8') 166 | print(city, data) 167 | return data 168 | 169 | 170 | def get_areas(city): #根据city以及获取到的html,处理得到area---后的POI键值对 171 | print('获取城市: ' + str(city).strip()) 172 | data = get_distrinctNoCache(city) 173 | print('城市的HTML:' + data) 174 | data = json.loads(data) 175 | print(data) 176 | 177 | if len(data['districts']) == 0: 178 | return city 179 | 180 | districts = data['districts'][0]['districts'] #根据POI键值对获取?? 181 | # 判断是否是直辖市 182 | # 北京市、上海市、天津市、重庆市。 183 | if (str(city).startswith('重庆') or str(city).startswith('上海') or str(city).startswith('北京') or str(city).startswith('天津')): 184 | districts =data ['districts'][0]['districts'][0]['districts'] 185 | i = 0 186 | areas = [] 187 | names = [] 188 | for district in districts: 189 | name = district['name'] 190 | adcode = district['adcode'] 191 | i = i + 1 192 | areas.append(adcode) 193 | names.append(name) 194 | return areas, names 195 | 196 | 197 | def get_data(province, classfield): 198 | poi_list = [] 199 | 200 | #获取省下面的所有城市 201 | city_codes, city_names = get_districthtml(province) 202 | 203 | print(city_codes) 204 | print(city_names) 205 | 206 | 207 | for i in range(len(city_codes)): 208 | city = city_codes[i] 209 | name = city_names[i] 210 | print(city, name) 211 | areas, area_names = get_areas(city) 212 | for i in range(len(areas)): 213 | area = areas[i] 214 | area_name = area_names[i] 215 | poi_list = getpois(area, classfield, poi_list, city, area_name) 216 | 217 | return poi_list 218 | 219 | 220 | 221 | # 数据写入csv文件中 222 | def write_to_csv(poilist, provincename, classfield): 223 | data_csv = {} 224 | lons, lats, names, addresss, pnames, business_areas,citynames, adnames, types, typecodes\ 225 | , type_1s, type_2s, type_3s, type_4s, ids = [], [], [], [], [], [], [], [], [], [], [], [], [], [], [] 226 | 227 | for i in range(len(poilist)): 228 | location = poilist[i].get('location') 229 | name = poilist[i].get('name') 230 | address = poilist[i].get('address') 231 | pname = poilist[i].get('pname') 232 | #provincename = poilist[i]['provincename'] 233 | business_area = poilist[i].get('business_area') 234 | cityname = poilist[i].get('cityname') 235 | adname = poilist[i].get('adname') 236 | type = poilist[i].get('type') 237 | typecode = poilist[i].get('typecode') 238 | lng = str(location).split(",")[0] 239 | lat = str(location).split(",")[1] 240 | id = poilist[i].get('id') 241 | type = str(type) 242 | type_1 = '' 243 | type_2 = '' 244 | type_3 = '' 245 | type_4 = '' 246 | if str(type) != None and str(type) != '': 247 | type_strs = type.split(';') 248 | for i in range(len(type_strs)): 249 | ty = type_strs[i] 250 | if i == 0: 251 | type_1 = ty 252 | elif i == 1: 253 | type_2 = ty 254 | elif i == 2: 255 | type_3 = ty 256 | elif i == 3: 257 | type_4 = ty 258 | 259 | if (coord == 2): 260 | result = gcj02_to_wgs84(float(lng), float(lat)) 261 | lng = result[0] 262 | lat = result[1] 263 | if (coord == 3): 264 | result = gcj02_to_bd09(float(lng), float(lat)) 265 | lng = result[0] 266 | lat = result[1] 267 | lons.append(lng) 268 | lats.append(lat) 269 | names.append(name) 270 | addresss.append(address) 271 | citynames.append(cityname) 272 | adnames.append(adname) 273 | pnames.append(pname) 274 | #provincenames.append(provincename) 275 | if business_area == []: 276 | business_area = '' 277 | business_areas.append(business_area) 278 | types.append(type) 279 | typecodes.append(typecode) 280 | type_1s.append(type_1) 281 | type_2s.append(type_2) 282 | type_3s.append(type_3) 283 | type_4s.append(type_4) 284 | ids.append(id) 285 | data_csv['lon'], data_csv['lat'], data_csv['name'], data_csv['address'], data_csv['pname'], \ 286 | data_csv['business_area'], data_csv['cityname'], data_csv['adname'], data_csv['type'], data_csv['typecode'], \ 287 | data_csv['type1'], data_csv['type2'], data_csv['type3'], data_csv['type4'], data_csv['id'] = \ 288 | lons, lats, names, addresss, pnames, business_areas, citynames, adnames, types, typecodes, type_1s, type_2s, type_3s, type_4s, ids 289 | 290 | pin = Pinyin() 291 | provincename_pinyin = pin.get_pinyin(provincename) # 默认分割符为- 292 | 293 | df = pd.DataFrame(data_csv) 294 | folder_name_full = 'data' + os.sep + provincename_pinyin + os.sep #+ classfield + os.sep 295 | if os.path.exists(folder_name_full) is False: 296 | os.makedirs(folder_name_full) 297 | 298 | 299 | file_name = 'poi-' + provincename_pinyin + "-" + classfield + ".csv" 300 | 301 | 302 | file_path = folder_name_full + file_name 303 | df.to_csv(file_path, index=False, encoding='utf_8_sig') 304 | 305 | print('写入地址:', folder_name_full, file_name) 306 | return folder_name_full, file_name 307 | 308 | 309 | if __name__ == '__main__': # 函数运行的入口,直接print('hello, world')也可以运行。 310 | 311 | 312 | #初始化密钥队列 313 | init_queen() 314 | 315 | one_pro_type_poi_list = [] 316 | for pro in province: # 循环获取每个省份的POI 317 | print('=====================当前省:', pro, '爬取开始...............') 318 | for type in keyword: # 循环获取每个编码的POI 319 | print('=====================当前POI类型:', type, '爬取开始...............') 320 | #一个省一个类型的数据总和 321 | #try: 322 | one_pro_type_poi_list = get_data(pro, type) # 最先要读,和最先调用的函数 323 | 324 | print('当前省:', pro, '分类:', type, '爬取完成,总共', len(one_pro_type_poi_list), '条数据') 325 | 326 | # 写入文件中 327 | file_folder, file_name = write_to_csv(one_pro_type_poi_list, pro, type) 328 | 329 | # 写入shp 330 | #trans_point_to_shp(file_folder, file_name, 0, 1) 331 | 332 | #except Exception as e: 333 | #print('===================================爬取失败,当前省:', pro, '分类:', type, '...........................') 334 | #print(e) 335 | 336 | print('总的', len(province), '个省份, ', len(keyword), '个分类数据全部爬取完成!') # 最后打印 337 | 338 | -------------------------------------------------------------------------------- /baidu/data/result.txt: -------------------------------------------------------------------------------- 1 | {'name': '维多利购物中心', 'location': {'lat': 40.822646, 'lng': 111.67575}, 'address': '呼和浩特市回民区中山西路1号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '844a750e0f107ea062685846', 'telephone': '(0471)2650100', 'detail': 1, 'uid': '844a750e0f107ea062685846', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67578483522, 'lat': 40.823715333487}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=844a750e0f107ea062685846&output=html&source=placeapi_v2', 'overall_rating': '4.7', 'comment_num': '8', 'children': []}} 2 | {'name': '海亮广场', 'location': {'lat': 40.820154, 'lng': 111.674919}, 'address': '内蒙古自治区呼和浩特市回民区中山西路和锡林郭勒南路交汇处', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '373cf757b73e6f774354d728', 'detail': 1, 'uid': '373cf757b73e6f774354d728', 'detail_info': {'tag': '房地产;其他', 'navi_location': {'lng': 111.67518762735, 'lat': 40.820709949067}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=373cf757b73e6f774354d728&output=html&source=placeapi_v2', 'overall_rating': '3.0', 'children': []}} 3 | {'name': '凯德MALL(鄂尔多斯大街店)', 'location': {'lat': 40.803207, 'lng': 111.68811}, 'address': '呼和浩特市赛罕区鄂尔多斯大街26号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': '23e8cf0c4a8775221c38946e', 'telephone': '(0471)5961222', 'detail': 1, 'uid': '23e8cf0c4a8775221c38946e', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68699306404, 'lat': 40.803093159686}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=23e8cf0c4a8775221c38946e&output=html&source=placeapi_v2', 'price': '278.0', 'overall_rating': '4.4', 'comment_num': '34', 'children': []}} 4 | {'name': '七彩城购物中心', 'location': {'lat': 40.809081, 'lng': 111.66989}, 'address': '内蒙古自治区呼和浩特市回民区石羊桥路与大学西街交汇处西北角', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': 'e9d6cea37cd8face51e5c572', 'telephone': '(0471)5315767', 'detail': 1, 'uid': 'e9d6cea37cd8face51e5c572', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67059119029, 'lat': 40.80949746931}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=e9d6cea37cd8face51e5c572&output=html&source=placeapi_v2', 'overall_rating': '4.5', 'comment_num': '16', 'children': []}} 5 | {'name': '劝业场(昭乌达路店)', 'location': {'lat': 40.829113, 'lng': 111.696908}, 'address': '内蒙古自治区呼和浩特市新城区昭乌达路66号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '0f956ce0c2462541a80dd852', 'telephone': '(0471)6201051', 'detail': 1, 'uid': '0f956ce0c2462541a80dd852', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.69650508454, 'lat': 40.828913656293}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=0f956ce0c2462541a80dd852&output=html&source=placeapi_v2', 'price': '0.0', 'overall_rating': '4.7', 'comment_num': '8', 'children': []}} 6 | {'name': '王府井奥莱(中山西路店)', 'location': {'lat': 40.818481, 'lng': 111.673232}, 'address': '呼和浩特市回民区中山西路86号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '91ea5d4dceaf0377c7f50d29', 'telephone': '(0471)3356888', 'detail': 1, 'uid': '91ea5d4dceaf0377c7f50d29', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67237841222, 'lat': 40.818244246475}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=91ea5d4dceaf0377c7f50d29&output=html&source=placeapi_v2', 'price': '0.0', 'overall_rating': '4.5', 'comment_num': '23', 'children': []}} 7 | {'name': '内蒙古民族商场', 'location': {'lat': 40.819914, 'lng': 111.672844}, 'address': '呼和浩特市回民区中山西路7号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '504d6113fd846aaa465726c5', 'telephone': '(0471)6601511', 'detail': 1, 'uid': '504d6113fd846aaa465726c5', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67434349415, 'lat': 40.820173679697}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=504d6113fd846aaa465726c5&output=html&source=placeapi_v2', 'price': '300.0', 'overall_rating': '4.5', 'comment_num': '25', 'children': []}} 8 | {'name': '嘉茂购物中心', 'location': {'lat': 40.803264, 'lng': 111.687971}, 'address': '内蒙古自治区呼和浩特市赛罕区鄂尔多斯大街26号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'detail': 1, 'uid': '1142e79a820969ad3b221c0f', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68742187646, 'lat': 40.804226649368}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=1142e79a820969ad3b221c0f&output=html&source=placeapi_v2', 'overall_rating': '5.0', 'comment_num': '3', 'children': []}} 9 | {'name': 'GOMEET', 'location': {'lat': 40.811912, 'lng': 111.682695}, 'address': '大学西街与锡林郭勒南路交叉口东南角', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'detail': 1, 'uid': 'c3e8661a1d096f00d23ce3d2', 'detail_info': {'tag': '购物;购物中心', 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=c3e8661a1d096f00d23ce3d2&output=html&source=placeapi_v2', 'overall_rating': '4.2', 'comment_num': '5', 'children': []}} 10 | {'name': '维多利商厦', 'location': {'lat': 40.821502, 'lng': 111.67461}, 'address': '呼和浩特市回民区中山西路39号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '971f6d42a338c5bced74f895', 'detail': 1, 'uid': '971f6d42a338c5bced74f895', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67582392409, 'lat': 40.821482164622}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=971f6d42a338c5bced74f895&output=html&source=placeapi_v2', 'overall_rating': '3.8', 'comment_num': '50', 'children': []}} 11 | {'name': '宝马商城', 'location': {'lat': 40.820997, 'lng': 111.671871}, 'address': '呼和浩特市回民区贝尔路西巷27号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': 'fa01e937d57ecf4a774ff118', 'detail': 1, 'uid': 'fa01e937d57ecf4a774ff118', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67228930481, 'lat': 40.820561403712}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=fa01e937d57ecf4a774ff118&output=html&source=placeapi_v2', 'overall_rating': '3.0', 'comment_num': '3', 'children': []}} 12 | {'name': '时代城', 'location': {'lat': 40.820582, 'lng': 111.676537}, 'address': '内蒙古自治区呼和浩特市回民区中山西路1号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': 'b9e5d0b828634dc181a12e43', 'detail': 1, 'uid': 'b9e5d0b828634dc181a12e43', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.67767660195, 'lat': 40.820499394369}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=b9e5d0b828634dc181a12e43&output=html&source=placeapi_v2', 'overall_rating': '4.4', 'comment_num': '30', 'children': []}} 13 | {'name': '凯德新世纪', 'location': {'lat': 40.829077, 'lng': 111.686572}, 'address': '呼和浩特市新城区新城西街48号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': 'd991e11667dc36551f389418', 'detail': 1, 'uid': 'd991e11667dc36551f389418', 'detail_info': {'tag': '购物;其他', 'navi_location': {'lng': 111.68608861502, 'lat': 40.829495089369}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=d991e11667dc36551f389418&output=html&source=placeapi_v2', 'overall_rating': '0.0', 'comment_num': '2', 'children': []}} 14 | {'name': '五四商城', 'location': {'lat': 40.817791, 'lng': 111.678644}, 'address': '内蒙古自治区呼和浩特市回民区锡林郭勒南路73号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '34e48508c16913e2d8d89118', 'detail': 1, 'uid': '34e48508c16913e2d8d89118', 'detail_info': {'tag': '购物;商铺', 'navi_location': {'lng': 111.67901263377, 'lat': 40.817843236216}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=34e48508c16913e2d8d89118&output=html&source=placeapi_v2', 'overall_rating': '3.3', 'comment_num': '10', 'children': []}} 15 | {'name': '星悦荟商厦', 'location': {'lat': 40.818874, 'lng': 111.672248}, 'address': '内蒙古自治区呼和浩特市回民区中山西路9号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'detail': 1, 'uid': 'ea637d93d06a512826e0a09c', 'detail_info': {'tag': '购物;购物中心', 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=ea637d93d06a512826e0a09c&output=html&source=placeapi_v2', 'overall_rating': '4.3', 'comment_num': '18', 'children': []}} 16 | {'name': '凯元广场', 'location': {'lat': 40.788494, 'lng': 111.713386}, 'address': '内蒙古自治区呼和浩特市赛罕区昭乌达路与包头大街交汇处西南角', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': 'c8b6e1e65771a70cea56fa79', 'detail': 1, 'uid': 'c8b6e1e65771a70cea56fa79', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.71398566241, 'lat': 40.788783460032}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=c8b6e1e65771a70cea56fa79&output=html&source=placeapi_v2', 'overall_rating': '3.9', 'comment_num': '18', 'children': []}} 17 | {'name': '邻里荟购物中心', 'location': {'lat': 40.814213, 'lng': 111.745268}, 'address': '鄂尔多斯东街21号附近', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': 'ff98c5c0d8cbca1188b98871', 'detail': 1, 'uid': '8ae8346f9f632ed1c61b75fb', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.74537498117, 'lat': 40.813792283557}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=8ae8346f9f632ed1c61b75fb&output=html&source=placeapi_v2', 'overall_rating': '5.0', 'comment_num': '4', 'children': []}} 18 | {'name': '万达广场(呼市回民区店)', 'location': {'lat': 40.838009, 'lng': 111.614933}, 'address': '呼和浩特市回民区阿拉善北路与成吉思汗西街交汇处', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '回民区', 'street_id': '7f8e917cde2024abfb2d61e5', 'detail': 1, 'uid': '7f8e917cde2024abfb2d61e5', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.61606137158, 'lat': 40.839218941313}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=7f8e917cde2024abfb2d61e5&output=html&source=placeapi_v2', 'overall_rating': '4.5', 'comment_num': '41', 'children': []}} 19 | {'name': '滨海商业广场', 'location': {'lat': 40.862884, 'lng': 111.684928}, 'address': '呼和浩特市新城区成吉思汗大街16号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '45306fb10a9f09807c29bde6', 'detail': 1, 'uid': '45306fb10a9f09807c29bde6', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68551142768, 'lat': 40.863413509589}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=45306fb10a9f09807c29bde6&output=html&source=placeapi_v2', 'price': '9800.0', 'overall_rating': '4.3', 'comment_num': '21', 'children': []}} 20 | {'name': '滨海玖禾奥莱', 'location': {'lat': 40.862926, 'lng': 111.683932}, 'address': '呼和浩特市新城区成吉思汗大街16号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '5584d2a191d8650c9e82eaac', 'telephone': '(0471)2860657', 'detail': 1, 'uid': '5584d2a191d8650c9e82eaac', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.6837201454, 'lat': 40.861994403297}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=5584d2a191d8650c9e82eaac&output=html&source=placeapi_v2', 'overall_rating': '5.0', 'comment_num': '2', 'children': []}} 21 | {'name': '滨海商业广场C区(滨海商业广场店)', 'location': {'lat': 40.862774, 'lng': 111.684131}, 'address': '成吉思汗大街16号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '3ad5683414920762c056acb9', 'detail': 1, 'uid': '3ad5683414920762c056acb9', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68551142768, 'lat': 40.863413509589}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=3ad5683414920762c056acb9&output=html&source=placeapi_v2', 'children': []}} 22 | {'name': '滨海商业广场E区(滨海商业广场店)', 'location': {'lat': 40.862917, 'lng': 111.685074}, 'address': '哲里木路与成吉思汗大街交叉口东南100米', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': 'cd68e0a735e592ffeee4a55d', 'detail': 1, 'uid': 'cd68e0a735e592ffeee4a55d', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68551142768, 'lat': 40.863413509589}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=cd68e0a735e592ffeee4a55d&output=html&source=placeapi_v2', 'children': []}} 23 | {'name': '滨海商业广场-A区', 'location': {'lat': 40.860428, 'lng': 111.684763}, 'address': '内蒙古自治区呼和浩特市新城区滨海商业广场A区(成吉思汗广场东)', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '7ba687b62a64cfbfe5e96511', 'detail': 1, 'uid': '7ba687b62a64cfbfe5e96511', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.68405311941, 'lat': 40.860268633556}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=7ba687b62a64cfbfe5e96511&output=html&source=placeapi_v2', 'children': []}} 24 | {'name': '苏宁易购广场(呼和浩特店)', 'location': {'lat': 40.841978, 'lng': 111.740388}, 'address': '呼和浩特市赛罕区新华东街26号呼和浩特万达广场1层', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': 'fd111d59132c112d8f772787', 'detail': 1, 'uid': 'db871c1572190943b8bd63c1', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.74040651897, 'lat': 40.84261607343}, 'indoor_floor': 'F5', 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=db871c1572190943b8bd63c1&output=html&source=placeapi_v2', 'overall_rating': '4.4', 'comment_num': '43', 'children': []}} 25 | {'name': '维多利·摩尔城', 'location': {'lat': 40.835704, 'lng': 111.716699}, 'address': '呼和浩特市赛罕区新华东街62号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': '8d4bf05d412778579e95de36', 'detail': 1, 'uid': '8d4bf05d412778579e95de36', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.71714542689, 'lat': 40.836142307543}, 'type': 'house', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=8d4bf05d412778579e95de36&output=html&source=placeapi_v2', 'overall_rating': '4.5', 'children': []}} 26 | {'name': '长乐宫购物中心', 'location': {'lat': 40.835929, 'lng': 111.715002}, 'address': '呼和浩特市赛罕区新华东街66号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': '3d03000841cc7fb2fe0eb0c5', 'telephone': '(0471)6632885', 'detail': 1, 'uid': '3810c8794c89128b9c09f718', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.71429913959, 'lat': 40.83673270811}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=3810c8794c89128b9c09f718&output=html&source=placeapi_v2', 'overall_rating': '3.2', 'comment_num': '21', 'children': []}} 27 | {'name': '维多利喜悦汇', 'location': {'lat': 40.8709, 'lng': 111.698301}, 'address': '呼和浩特市新城区兴安北路', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '6dce5c43745aa14d95f08c86', 'telephone': '(0471)3827777', 'detail': 1, 'uid': '6dce5c43745aa14d95f08c86', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.69979142476, 'lat': 40.870562270221}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=6dce5c43745aa14d95f08c86&output=html&source=placeapi_v2', 'overall_rating': '4.3', 'comment_num': '7', 'children': []}} 28 | {'name': '万达广场(呼和浩特店)', 'location': {'lat': 40.8422, 'lng': 111.741097}, 'address': '呼和浩特市赛罕区新华东街26号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': 'cfe44457f72b3ca2ce04efae', 'telephone': '(0471)3259999', 'detail': 1, 'uid': 'cfe44457f72b3ca2ce04efae', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.74091981343, 'lat': 40.842713708769}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=cfe44457f72b3ca2ce04efae&output=html&source=placeapi_v2', 'overall_rating': '4.4', 'comment_num': '28', 'children': []}} 29 | {'name': '天宇百货商城', 'location': {'lat': 40.844735, 'lng': 111.700432}, 'address': '兴安北路169号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '4de06d866af2026388b9880c', 'detail': 1, 'uid': '4de06d866af2026388b9880c', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.70063044929, 'lat': 40.844798479747}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=4de06d866af2026388b9880c&output=html&source=placeapi_v2', 'overall_rating': '0.0', 'comment_num': '1', 'children': []}} 30 | {'name': '维多利国际广场', 'location': {'lat': 40.833857, 'lng': 111.704683}, 'address': '内蒙古自治区呼和浩特市新城区新华东街8号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '6deee30870104f1729fc4847', 'telephone': '(0471)2236611', 'detail': 1, 'uid': '6deee30870104f1729fc4847', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.70305814958, 'lat': 40.833893301616}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=6deee30870104f1729fc4847&output=html&source=placeapi_v2', 'price': '480.0', 'overall_rating': '4.0', 'comment_num': '29', 'children': []}} 31 | {'name': '融城百汇购物中心', 'location': {'lat': 40.864263, 'lng': 111.733428}, 'address': '成吉思汗东街附近', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': 'c81b4720e13578cff7eafcb7', 'detail': 1, 'uid': 'c81b4720e13578cff7eafcb7', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.73454346755, 'lat': 40.863200197233}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=c81b4720e13578cff7eafcb7&output=html&source=placeapi_v2', 'overall_rating': '1.0', 'comment_num': '1', 'children': []}} 32 | {'name': '瑞富祥商场(新华东街店)', 'location': {'lat': 40.840854, 'lng': 111.728829}, 'address': '内蒙古自治区呼和浩特市新城区新华东街587号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '43b7e88958c87a6a58f6be14', 'detail': 1, 'uid': '43b7e88958c87a6a58f6be14', 'detail_info': {'tag': '购物;超市', 'navi_location': {'lng': 111.72898683712, 'lat': 40.840614061481}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=43b7e88958c87a6a58f6be14&output=html&source=placeapi_v2', 'overall_rating': '0.0', 'comment_num': '3', 'children': []}} 33 | {'name': '维多利国际广场-三期', 'location': {'lat': 40.834259, 'lng': 111.701815}, 'address': '新华大街11号附近', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': 'e03361f7bc9ad8d36fc02cae', 'detail': 1, 'uid': 'e03361f7bc9ad8d36fc02cae', 'detail_info': {'tag': '购物;购物中心', 'navi_location': {'lng': 111.70249479255, 'lat': 40.834162607613}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=e03361f7bc9ad8d36fc02cae&output=html&source=placeapi_v2', 'overall_rating': '0.0', 'comment_num': '1', 'children': []}} 34 | {'name': '金叶商厦', 'location': {'lat': 40.837826, 'lng': 111.716263}, 'address': '新华大街东风路祥泰小区1号楼', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '新城区', 'street_id': '0fedf77dc09768bc1811d58f', 'detail': 1, 'uid': '0fedf77dc09768bc1811d58f', 'detail_info': {'tag': '购物;购物中心', 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=0fedf77dc09768bc1811d58f&output=html&source=placeapi_v2', 'overall_rating': '0.0', 'children': []}} 35 | {'name': '天美商场', 'location': {'lat': 40.833479, 'lng': 111.715999}, 'address': '呼和浩特市赛罕区东影南街74号', 'province': '内蒙古自治区', 'city': '呼和浩特市', 'area': '赛罕区', 'street_id': '886c7b9794a1d9d39fe321a6', 'detail': 1, 'uid': 'cac5fc7695bb80ea2cb96d18', 'detail_info': {'tag': '购物;百货商场', 'navi_location': {'lng': 111.71651015511, 'lat': 40.833476878298}, 'type': 'shopping', 'detail_url': 'http://api.map.baidu.com/place/detail?uid=cac5fc7695bb80ea2cb96d18&output=html&source=placeapi_v2', 'overall_rating': '3.5', 'comment_num': '4', 'children': []}} 36 | --------------------------------------------------------------------------------