使用Basemap的readshapefile进行打印时,如果定义的地图的中心位置不是shapefile的纵向中心,则只打印它的一部分。下面是一个使用Natural Earth's海岸线的示例:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
shpf = './NaturalEarth/ne_50m_land/ne_50m_land'
fig, ax = plt.subplots(nrows=1, ncols=1, dpi=100)
m = Basemap(
ax = ax,
projection = 'cyl',
llcrnrlon = 0, llcrnrlat = -90,
urcrnrlon = 360, urcrnrlat = 90
)
m.readshapefile(shpf,'ne_50m_land')
m.drawmeridians(np.arange(0,360,45),labels=[True,False,False,True])
产生:
使用Basemap或Python有解决方法吗?我知道有些人在QGIS或类似的工具中重新定位shapefile,但每次创建新地图时都这样做似乎不实际,而且我的QGIS技能非常基本。在
一种方法是告诉
readshapefile
不要直接绘制海岸线,然后在自己绘制之前操纵线段。下面是一个基于您的用例的示例:在上面的例子中,我按照Basemap documentation中解释的方式遍历形状文件的线段。首先,我认为只要在经度小于0的点上加360度就足够了,但是当海岸线穿过0度线时,就会得到水平线。因此,每当出现这样的交叉时,就必须将这些线切割成更小的线段。这很容易用
numpy
完成。然后我使用plot
命令绘制海岸线。如果您想做更复杂的事情,请看一下Basemap documentation。最终结果如下:
希望这有帮助。
相关问题 更多 >
编程相关推荐