geojson全国各省市区地图json数据(目前仅到全国、省、市、区级别,无法到乡、镇、社区),现在尚未验证是高德or百度坐标系,预计阿里系应该是gcj-02坐标,有验证的小伙伴可回复下,嘿嘿
json数据获取地址:
http://datav.aliyun.com/tools/atlas/#&lat=31.769817845138945&lng=104.29901249999999&zoom=4
测试json数据地址,并且可以转化为shape格式文件:
https://mapshaper.org/
直接将json数据拖入即可,并可导出shape图层
全国的json数据,写了一个python程序获取下来了,有需要的可以下载来用:
python代码如下:
# 请求库
import requests
# 解析库
# from bs4 import BeautifulSoup
# 用于解决爬取的数据格式化
import io
import sys
import json
# 创建文件
# file_path:文件路径
# msg:即要写入的内容
def create_file(file_path, msg):
with open(file_path, "wt", encoding="utf-8") as out_file:
out_file.write(msg)
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
req = requests.get('https://geo.datav.aliyun.com/areas_v2/bound/100000_full.json')
req.encoding = 'utf-8'
result = json.loads(req.text)
# 写入文件
# with open('../geo_json/100000_全国_full.json', 'w') as file_obj:
# json.dump(result, file_obj)
dict_area = dict()
dict_area['100000'] = '全国'
# 可写入带格式化后的json对象
create_file('../geo_json/100000_full.json', req.text)
# 读取并加载json文件 json.loads(操作的是字符串),json.load()操作的是文件流
with open('../geo_json/100000_full.json', 'r', encoding="utf-8") as file_obj:
geo_json = json.load(file_obj)
print('read result is :')
print(geo_json)
features = geo_json["features"]
i = 0
for province_feature in features: # 循环各省
adcode = str(province_feature["properties"]["adcode"])
name = province_feature["properties"]["name"]
dict_area[adcode] = name
print('name{0} is {1}, adcode is {2}'.format(i, name, adcode))
i = i + 1
if adcode[4:] != '00': # 直辖市的下一级别直接是区,没有市级别
continue
# 省份的url_json获取,获取省,及省内城市json
province_full_url = 'https://geo.datav.aliyun.com/areas_v2/bound/{0}_full.json'.format(adcode)
province_full_json = json.loads(requests.get(province_full_url).text)
city_features = province_full_json["features"]
j = 0
for city_feature in city_features: # 循环各市
city_adcode = str(city_feature["properties"]["adcode"])
city_name = city_feature["properties"]["name"]
dict_area[city_adcode] = city_name
print('name{0}-{1} is {2}, adcode is {3}'.format(i, j, city_name, city_adcode))
j = j + 1
# 遍历字典
for area in dict_area.keys():
print('{}:{}', area, dict_area[area])
area_url = 'https://geo.datav.aliyun.com/areas_v2/bound/{0}.json'.format(area)
req = requests.get(area_url)
create_file('../geo_json/{0}_{1}.json'.format(area, dict_area[area]), req.text)
area_full_url = 'https://geo.datav.aliyun.com/areas_v2/bound/{0}_full.json'.format(area)
print(area_full_url)
req = requests.get(area_full_url)
if req.text.find("NoSuchKey") == -1:
create_file('../geo_json/{0}_{1}_full.json'.format(area, dict_area[area]), req.text)
# json文件说明
# 中国json https://geo.datav.aliyun.com/areas_v2/bound/100000.json
# 中国+各省市json https://geo.datav.aliyun.com/areas_v2/bound/100000_full.json
# 山东省边界json https://geo.datav.aliyun.com/areas_v2/bound/370000.json
# 山东省+省内地级市json https://geo.datav.aliyun.com/areas_v2/bound/370000_full.json
# 德州市边界json https://geo.datav.aliyun.com/areas_v2/bound/371400.json
# 德州市+内部辖区json https://geo.datav.aliyun.com/areas_v2/bound/371400_full.json
# create_file('../geo_json/full.json', result)
# 读取并加载json文件