好的,我认为我有一个部分解决方案。
基本的想法是使用 drawcoastlines() 函数中的路径按大小/面积排序。这意味着前 N 条路径(对于大多数应用程序)是主要陆地和湖泊,后面的路径是较小的岛屿和河流。
问题在于,你想要的前 N 条路径将取决于投影方式(例如全球、极地、区域)、是否应用面积阈值以及是否需要湖泊或小岛等。换句话说,你需要根据每个应用程序进行微调。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
mp = 'cyl'
m = Basemap(resolution='c',projection=mp,lon_0=0,area_thresh=200000)
fill_color = '0.9'
m.fillcontinents(color=fill_color,lake_color='white')
coasts = m.drawcoastlines(zorder=100,color=fill_color,linewidth=0.5)
coasts_paths = coasts.get_paths()
for ipoly in xrange(len(coasts_paths)):
print ipoly
r = coasts_paths[ipoly]
polygon_vertices = [(vertex[0],vertex[1]) for (vertex,code) in
r.iter_segments(simplify=False)]
px = [polygon_vertices[i][0] for i in xrange(len(polygon_vertices))]
py = [polygon_vertices[i][1] for i in xrange(len(polygon_vertices))]
m.plot(px,py,'k-',linewidth=1)
plt.show()
一旦您知道停止绘制的相关ipoly(poly_stop),那么您可以像这样做...
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
mproj = ['nplaea','cyl']
mp = mproj[0]
if mp == 'nplaea':
m = Basemap(resolution='c',projection=mp,lon_0=0,boundinglat=30,area_thresh=200000,round=1)
poly_stop = 10
else:
m = Basemap(resolution='c',projection=mp,lon_0=0,area_thresh=200000)
poly_stop = 18
fill_color = '0.9'
m.fillcontinents(color=fill_color,lake_color='white')
coasts = m.drawcoastlines(zorder=100,color=fill_color,linewidth=0.5)
coasts_paths = coasts.get_paths()
for ipoly in xrange(len(coasts_paths)):
if ipoly > poly_stop: continue
r = coasts_paths[ipoly]
polygon_vertices = [(vertex[0],vertex[1]) for (vertex,code) in
r.iter_segments(simplify=False)]
px = [polygon_vertices[i][0] for i in xrange(len(polygon_vertices))]
py = [polygon_vertices[i][1] for i in xrange(len(polygon_vertices))]
m.plot(px,py,'k-',linewidth=1)
plt.show()
![enter image description here](https://istack.dev59.com/xa59B.webp)