gma 地理空间绘图:(1)绘制简单的世界地图-1.地图绘制与细节调整

了解 gma

gma 是什么?

gma 是一个基于 Python 的地理、气象数据快速处理和数据分析函数包(Geographic and Meteorological Analysis,gma)。gma 网站:地理与气象分析库。

gma 的主要功能有哪些?

气候气象(例如 SPEI、SPI、ET0 等)。
遥感指数(例如 NDVI、EVI、TVDI 等)。
数学运算(例如 数据平滑、评估、滤波、拉伸、增强变换等)。
系统交互(例如 获取路径、重命名、压缩等操作)。
空间杂项(例如 计算空间距离、面积计算,坐标转换、空间插值等操作)。
栅格处理(例如 栅格镶嵌、裁剪、重采样、重投影、格式转换、数据融合等)。
栅格分析(例如 DEM 坡度、坡向、阴影、等值线等计算)。
矢量处理(例如 矢量裁剪、擦除、交集、融合、重投影等)。
地图工具(例如 栅格、矢量数据绘图,指北针、比例尺等生成,坐标系定义等)

gma 的安装要求?

系统 (X64): Window 10+,Linux
Python 版本: 3.8.8 ~ 3.10,建议使用 3.9

gma 哪个版本开始支持空间绘图?

gma 1.1.2 及之后的版本
点击查看:gma 1.1.2 版本的新增内容

基于 gma 绘制简单的世界地图

本文基于 gma 1.1.2 (Python 3.9) ,为大家展示绘制世界地图(gma 内置的世界国家和地区),如果有自有的高精度世界地图,也可按照此方法绘制。

1. 绘制世界地图

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = None)# 2.将内置的世界矢量图层添加到地图框 
MapL1 = MapF.AddLayer(WorldLayer)

请添加图片描述

2. 其他参数说明

自 gma 1.1.0 起,gma 不在内置中文帮助。

2.1 MapFrame 帮助

'''
Initialize a map frame for plotting a map!**Optional
----------
Axes = None or matplotlib.~.AxesSubplot. Default None.A matplotlib subplot. If None, a default Axes will be created. BaseMapProj = str, int or SpatRef. Default 'WGS84'.Base map coordinate system. All data that added to this frame will be reprojectedto this coordinate system. Can be EPSG, WKT, Proj4, and other types of coordinatecharacters or SpatRef(gma spatial reference) class.Extent = list or None. Default None.Plot [left, bottom, right, top] extent(In WGS84). All data that added to this mapframe will be clipped to this extent. Default(None) is the maximum extent supportedby the base map coordinate system.
'''

在这里插入图片描述

2.2 AddLayer 帮助

'''
Add a layer to the map frame.Parameters
----------
GMALayer: gma.algorithm.core.dataio.Layer.A vector layer opened by gma.Open(.GetLayer).**Optional
----------
FID = list or None. Default None.The feature ID of the vector to plot. Default(None) all feature.For more, see gma.~.Layer.FaceColor = str, tuplt, list or None. Default '#BED2FF'.The polygon fill color. Only for 'Polygon' layers. If None, a random color willbe generated. If it is a list, assign a different color to each feature. For more,see matplotlib.EdgeColor = str, tuplt, list or None. Default '#B2B2B2'.The polygon edge color. Only for 'Polygon' layers. If None, a random color willbe generated. If it is a list, assign a different color to each feature.For more, see matplotlib.Hatch = str, list or None. Default None.Filling style. May be {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} or acombination thereof. Only for 'Polygon' layers. Default(None) no filling style.If it is a list, assign a different hatch to each feature. For more, see matplotlib.LineStyle = str, list, tuple, or None. Default None.Line style. May be {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}.If it is a list,assign a different line style to each feature. Default(None) no line style.For more, see matplotlib.LineWidth = float or list. Default 0.5.Line width. In font-size units. If it is a list, assign a differentline width to each feature. LineColor = str, tuplt, list or None. Default '#B2B2B2'.The line color. Only for 'Line' layers. If None, a random color will be generated.Ifit is a list, assign a different color to each feature. For more, see matplotlib.PointColor = str, tuplt, list or None. Default '#BED2FF'.The point color. Only for 'Point' layers. If None, a random color will be generated.If it is a list, assign a different color to each feature. For more, see matplotlib.PointSize = float, list or None. Default None.The point size. Only for 'Point' layers. If it is a list, assign a different size to each feature.Default(None) depends on the matplotlib setting.PointMarker = str, list or None. Default None.The point marker. Only for 'Point' layers. Default(None) depends on the matplotlib setting.If it is a list, assign a different marker to each feature.Labels = str or None. Default None.Manually set the feature labels. The number should be the same as the number of layer features.Otherwise, the shortfall will be assigned as null. Default(None) no labels.FieldName = list, str or None. Default None.Layer field used to configure the label. If 'FieldName' is configured, 'Label' will be disabled.Default(None) no labels.Connector = str. Default ''.If 'FieldName' configures more than one field, the fields are connected with this symbol.Zorder = int or None. Default None.The layer order. Used to control the order of the layers. Default(None) depends on thematplotlib setting.Returns
----------
gma.~.PlotLPolygon/PlotLLine/PlotLPoint.'''

简单的世界地图细节调整

本例仅针对多边形的边界线、填充内容进行示例。其他参数参考2.2 进行调整和测试。

1. 调整边界线

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = None)# 2.添加图层,并调整 边界线的颜色和线的宽度
MapL1 = MapF.AddLayer(WorldLayer, EdgeColor = 'gray', LineWidth = 0.2)

请添加图片描述

2. 调整填充色

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = None)# 2.添加图层,并调整 填充颜色
MapL1 = MapF.AddLayer(WorldLayer, FaceColor = 'gray')

请添加图片描述

3. 调整填充样式

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = None)# 2.添加图层,并调整 填充样式
MapL1 = MapF.AddLayer(WorldLayer, Hatch = '*/')

请添加图片描述

4. 为每个国家或地区分配随机颜色

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = None)# 2.添加图层,并为每个国家或地区分配随机颜色
### FaceColor = None 相当于生成了一个颜色列表,列表中的每个颜色都是随机的。
### 列表颜色数量与国家或地区数量相同(所有类似的参数均可按照此说明配置)。
MapL1 = MapF.AddLayer(WorldLayer, FaceColor = None)

请添加图片描述

地图框控制

1. 调整底图坐标系

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,调整底图坐标系为 WGS 84 / Pseudo-Mercator(EPSG: 3857)
### 又名 web墨卡托投影,Spherical Mercator, Google Maps, OpenStreetMap, Bing, ArcGIS, ESRI等均使用此投影!
MapF = plot.MapFrame(Axes = None, BaseMapProj = 3857, Extent = None)# 2.添加图层
MapL1 = MapF.AddLayer(WorldLayer)

请添加图片描述

2. 控制显示范围

from gma.map import plot# 0. 打开 gma 内置的世界矢量
WorldDS = plot.GetWorldDataSource()
WorldLayer = WorldDS.GetLayer(0)# 1.初始化一个地图框,用于绘图
MapF = plot.MapFrame(Axes = None, BaseMapProj = 'WGS84', Extent = (-10, 30, 30, 60))# 2.添加图层
MapL1 = MapF.AddLayer(WorldLayer)

请添加图片描述

Published by

风君子

独自遨游何稽首 揭天掀地慰生平