一个网站大概多少页面,如何做旅游休闲网站,百度直播平台,网站制作公司 信科网络原文作者#xff1a;我辈李想 版权声明#xff1a;文章原创#xff0c;转载时请务必加上原文超链接、作者信息和本声明。 Cartopy基础入门
【Cartopy】库的安装和天地图瓦片加载 【Cartopy】【Cartopy】如何更好的确定边界显示 【Cartopy】【Cartopy】如何丝滑的加载Geojso… 原文作者我辈李想 版权声明文章原创转载时请务必加上原文超链接、作者信息和本声明。 Cartopy基础入门
【Cartopy】库的安装和天地图瓦片加载 【Cartopy】【Cartopy】如何更好的确定边界显示 【Cartopy】【Cartopy】如何丝滑的加载Geojson数据 文章目录 Cartopy基础入门前言一、python版本二、环境依赖三、库依赖四、下载Cartopy的whl文件五、天地图瓦片加载六、保存io图片七、保存多图效率问题 前言
Cartopy的官方文档还是太难读了来来回回找了很多资料还是有很多东西无法使用网络上教程大多比较官方。作为程序员很多时候还是根据源码来使用各种库来的实在。官网链接可参考https://scitools.org.uk/cartopy/docs/latest/installing.html#required-dependencies。 现在是2023年8月11日,在python3.8环境下安装Cartopy0.20.2 一、python版本 二、环境依赖
在windows系统可通过安装OSGeo4W完成gdal、geos、proj的安装。 在linux可以参考链接https://blog.csdn.net/qq_15028721/article/details/129244588 下载GDAL文件,地址 百度的网盘链接: https://pan.baidu.com/s/1mvls3DA9-_41j52CkuT0wQ?pwdvied 提取码: vied
安装命令如下
pip install .\GDAL-3.4.3-cp38-cp38-win_amd64.whl三、库依赖
官网一直在更新版本我们这里是以python3.8来安装需要的库依赖包括Matplotlib 、Shapely 、pyshp 、pyproj 。安装命令如下
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyproj3.3.1 pyshp2.3.1 Shapely1.8.2 matplotlib3.
5.2四、下载Cartopy的whl文件
百度网盘链接: https://pan.baidu.com/s/1cJyRL6KzoyPLWyITLNtZIA?pwd7i86 提取码: 7i86 pip install .\Cartopy-0.20.2-cp38-cp38-win_amd64.whl五、天地图瓦片加载
import datetime
import random
import os
import json
import zipfile
import shutil
from xml.etree import ElementTree
from pathlib import Pathfrom docxtpl import DocxTemplate, InlineImage
from docx.shared import Mmimport cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.io.img_tiles as cimgt# 高德地图底图
class GaodeMap(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl http://webrd02.is.autonavi.com/appmaptile?langzh_cnsize1scale1style8x%sy%sz%s % (x, y, z)return url# 天地图底图
class TDT(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl http://t%s.tianditu.gov.cn/DataServer?Tvec_wx%sy%sl%stkdbf3e0f3ac8d0162ae0a4bbd0fcbd09b% (random.randint(1, 7),x, y, z)return url
class TDT_ter(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl http://t3.tianditu.gov.cn/DataServer?Tter_wx%sy%sl%stkdbf3e0f3ac8d0162ae0a4bbd0fcbd09b% (x, y, z)return url
class TDT_img(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl http://t3.tianditu.gov.cn/DataServer?Timg_wx%sy%sl%stkdbf3e0f3ac8d0162ae0a4bbd0fcbd09b% (x, y, z)return url
# 谷歌底图
class GuGeMap(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl fhttp://mt2.google.com/vt/lyrsmscale2hlzh-CNglcnx{x}y{y}z{z}return url# openstreetmap底图
class OpenStreetMap(cimgt.GoogleWTS):def _image_url(self, tile):x, y, z tileurl fhttps://tile.openstreetmap.org/{z}/{x}/{y}.pngreturn url# 地图
proj ccrs.PlateCarree()
plt.figure(figsize[10, 10], dpi300, edgecolorcoral)
geo_axes plt.axes(projectionproj)
# 网格线
geo_axes.gridlines(draw_labelsTrue, x_inlineFalse, y_inlineFalse)# 底图天地图
geo_axes.add_image(TDT(), 8)# 正方形图片
plt.axis(square)plt.savefig(plt_img, dpi300)六、保存io图片
img_buf io.BytesIO()
plt.savefig(img_buf, dpi300)
img_buf.seek(0)七、保存多图效率问题
plt.savefig(plt_img, dpi300)
plt.clf()