在底图的正交投影上打印形状文件的问题

2024-10-04 05:23:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在试图绘制专属经济区(EEZ)形状文件的正交投影从底图包。但是,shapefile文件有来自世界各地的eez,所以当我尝试绘制shapefile时,总是有一些在特定角度的投影中不可见的。这导致形状被抹去,这不是我想要的效果。最终,我只希望绘制选定的shapefile,但是同样的问题很可能会出现,所以现在我很乐意解决这个更基本的情况,我尝试绘制所有的shapefile。你知道吗

在代码中,我尝试了一个简单的例子,在这个例子中,我使用basemap中的readshapefile命令来绘制shapefile。我也尝试过将各种形状绘制为多边形(我认为这样可以更灵活地更改各个形状文件的外观),但是我无法将多边形显示在地图上的正确位置,我会看到类似的涂抹行为(因此问题可能有相同或类似的根本原因)。你知道吗

我附上了下面这个简单案例的代码。如果我运行这个,我得到的投影显示为一个我想要的,但与形状文件涂抹。shapefile可以在http://www.marineregions.org/downloads.php#unioneezcountry找到,我使用了海洋和陆地区域的第2版:世界国家边界和专属经济区的联合

#Here is the figure
fig=plt.figure(figsize=(20,12))
ax=fig.add_subplot(111)

#create the map projection
Map=Basemap(projection='ortho',lon_0=0,lat_0=0,resolution='l')
Map.drawcoastlines(zorder=10)
Map.drawcountries(zorder=10)
Map.drawmapboundary()
#Reading in the shapefile and plotting it
Map.readshapefile('~/EEZ_Boundaries/EEZ_land_v2_201410','countries')

Here is a link to the image I get when I run the code


Tags: 文件the代码maphereis绘制多边形
1条回答
网友
1楼 · 发布于 2024-10-04 05:23:13

好吧,在花了更多的时间尝试让它工作之后,我几乎放弃了Basemap,转而使用cartopy。在这种情况下,Cartopy已经解决了这个问题,因此创建我试图获得的图形的代码是:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cpf
from cartopy.io.shapereader import Reader

#Set the projection
projection=ccrs.Orthographic(central_longitude=0,central_latitude=0)

fig=plt.figure(figsize=(20,12))
axMap=fig.add_subplot(1,1,1,projection=projection)

#resolution of the coastlines
resolution='10m'
axMap.coastlines(resolution=resolution,edgecolor='black',zorder=10)

#Add the shapefiles
shape_feature = cpf.ShapelyFeature(Reader(direc_shp+file_shp).geometries(),
                               ccrs.PlateCarree(), edgecolor='black')
axMap.add_feature(shape_feature,zorder=1)

相关问题 更多 >