https://github.com/cnmetlab/cnmaps
这是一个可以让中国地图画起来更丝滑的python扩展包
https://github.com/cnmetlab/cnmaps
cartopy china gis map matplotlib python
Last synced: 3 months ago
JSON representation
这是一个可以让中国地图画起来更丝滑的python扩展包
- Host: GitHub
- URL: https://github.com/cnmetlab/cnmaps
- Owner: cnmetlab
- License: bsd-3-clause
- Created: 2021-07-22T16:18:08.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T18:39:35.000Z (almost 2 years ago)
- Last Synced: 2025-10-11T15:56:54.267Z (9 months ago)
- Topics: cartopy, china, gis, map, matplotlib, python
- Language: Python
- Homepage: https://cnmaps.rtfd.io
- Size: 66.1 MB
- Stars: 140
- Watchers: 3
- Forks: 25
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cnmaps 是一个以中国领土主张为标准开发的地图类 Python 扩展包
## 安装
安装 cnmaps 需要满足 Python 的解释器在 3.9 版本及以上。
### 使用 pip 安装
cnmaps 最简单也最快的安装方法是使用 pip:
```bash
pip install -U cnmaps
```
从 `2.0.0` 开始,官方边界与样例数据已经拆分到独立包 [cnmaps-data](https://pypi.org/project/cnmaps-data/);安装 `cnmaps` 时会默认一并安装该数据包,无需再手动准备内置数据目录。
### 使用 conda 安装
你也可以使用 conda-forge:
```bash
conda install -c conda-forge cnmaps
```
补充说明:conda-forge 当前只维护到 `1.1.7` 版本;`2.x` 及后续版本仅发布到 PyPI,conda 发行将停止后续维护。
### 从源码安装(参与开发)
若需修改源码或运行测试,可在克隆 [主仓库](https://github.com/cnmetlab/cnmaps) 后使用 [Poetry](https://python-poetry.org/) 安装依赖:
```bash
poetry install
```
## 快速开始
### 绘制国界
用最简单直接的方式,来绘制你的第一张中国地图。
```python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(country='中国', level='国'))
plt.show()
```

### 绘制省界
cnmaps还可以绘制各省(特区/直辖市)的地图
```python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='省'), linewidth=0.8, color='r')
plt.show()
```

### 绘制市界
cnmaps可以绘制市级的行政区地图。
```python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='市'), linewidth=0.5, color='g')
plt.show()
```

### 绘制区县界
cnmaps可以绘制区县级的行政区地图。
```python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
draw_maps(get_adm_maps(level='区县'), linewidth=0.8, color='r')
plt.show()
```

### 绘制全球国家边界
如果你想快速验证 `cnmaps` 现在的全球国家级边界能力,可以直接执行下面这段最小示例代码。
```python
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cnmaps import get_adm_maps, draw_maps
fig = plt.figure(figsize=(14, 7))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree(central_longitude=105))
draw_maps(get_adm_maps(level='国', source='世界银行'), linewidth=0.4, color='#666666')
draw_maps(get_adm_maps(country='中国', level='国'), linewidth=1.0, color='crimson')
plt.show()
```

## 使用指南
针对本项目更多的使用方法,我们还有一份更详细的文档:[cnmaps使用指南](https://cnmaps.readthedocs.io/zh_CN/latest/index.html)
## 引用
本项目适用的地图边界的数据源包括:
1. GaryBikini/ChinaAdminDivisonSHP: v2.0, 2021, DOI: 10.5281/zenodo.4167299
海拔高度地形数据来自ASTER数字高程模型,并对原始数据进行了稀释。