使用python下载地图边界坐标(省市县级)

简介: 使用python下载地图边界坐标(省市县级)

使用python下载地图边界坐标
省市县级

#! /usr/bin/env python
# encoding: utf-8

import os
import requests
import json


def downloadOne(imgurl,path):
    try:
        r = requests.get(imgurl,timeout=30,verify=True)
        r.raise_for_status()
        #使用with语句可以不用自己手动关闭已经打开的文件流
        with open(path,"wb") as f: #开始写文件,wb代表写二进制文件
            f.write(r.content)
            print('下载'+path+'完成')
    except Exception:
        print('')

def mkPath(path,name):
    floder = os.path.join(path,name)
    if not os.path.exists(floder):
        os.mkdir(floder)
    return floder

def digui(path,full_url):
    print(path,full_url)
    r = requests.get(full_url)
    ret = json.loads(r.text)
    p_list = ret['features']
    size = len(p_list)
    print(size)
    for dic in p_list:
        p_adcode = dic['properties']['adcode']
        p_name = dic['properties']['name']
        print(p_adcode,p_name)
        url = "https://***/areas_v3/bound/{}.json".format(str(p_adcode))
        p_path = mkPath(path,p_name)
        file_p = os.path.join(p_path,p_name+'.json')
        downloadOne(url,file_p)
        try:
            url = "https://***/areas_v3/bound/{}_full.json".format(str(p_adcode))
            file_full_p = os.path.join(path,p_name+'_full.json')
            downloadOne(url,file_full_p)
            digui(p_path,url)
        except:
            print(p_name,'是个直辖市')

def downloadGeos():
    url = 'https://***/areas_v3/bound/100000.json'
    name = '中国'
    path = mkPath(r'D:\\bigemap',name)
    file_p = os.path.join(path,name+'.json')
    downloadOne(url,file_p)
    full_url = 'https://***/areas_v3/bound/100000_full.json'
    file_full_p = os.path.join(path,name+'_full.json')
    downloadOne(full_url,file_full_p)
    digui(path,full_url)

downloadGeos()
相关文章
|
2天前
|
Python
下载python所有的包 国内地址
下载python所有的包 国内地址
|
18天前
|
存储 缓存 安全
Python案例分享:如何实现文件的上传下载
Python案例分享:如何实现文件的上传下载
89 6
|
1月前
|
JSON JavaScript API
用Python编写小工具下载OSM路网数据
用Python编写小工具下载OSM路网数据
|
1月前
|
前端开发 数据库 Python
用Python轻松开发数据库取数下载工具
用Python轻松开发数据库取数下载工具
|
1月前
|
数据可视化 数据挖掘 定位技术
Python+Kepler.gl轻松制作时间轮播地图
Python+Kepler.gl轻松制作时间轮播地图
|
1月前
|
Python
Python 下载 html 中的 图片
Python 下载 html 中的 图片
24 2
|
1月前
|
数据可视化 Python
Python 绘制误码率对比折线图,纵坐标是10次幂,即求对数
本文介绍了如何在Python中绘制误码率(BER)的对比折线图,特别指出纵坐标使用10次幂即对数形式来表示误码率,横坐标为信噪比(SNR),并提供了相应的绘图函数和使用示例。
25 2
|
1月前
|
数据可视化 定位技术 开发工具
用Python快速制作海报级地图
用Python快速制作海报级地图
|
1月前
|
API 网络安全 开发工具
【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
|
1月前
|
数据处理 Python
解锁Python多线程编程魔法,告别漫长等待!让数据下载如飞,感受科技带来的速度与激情!
【8月更文挑战第22天】Python以简洁的语法和强大的库支持在多个领域大放异彩。尽管存在全局解释器锁(GIL),Python仍提供多线程支持,尤其适用于I/O密集型任务。通过一个多线程下载数据的例子,展示了如何使用`threading`模块创建多线程程序,并与单线程版本进行了性能对比。实验表明,多线程能显著减少总等待时间,但在CPU密集型任务上GIL可能会限制其性能提升。此案例帮助理解Python多线程的优势及其适用场景。
27 0