尝试绘制河流时出现 Cartopy 错误

Cartopy error when attempting to plot rivers

尝试使用 Cartopy 绘制河流时,出现 URL 错误。我什至不确定河流功能是否会绘制我想要的内容...我正在尝试让加尔维斯顿航道显示在我的地图上。

这是我得到的错误:

C:\ProgramData\Anaconda3\lib\site-packages\cartopy\io\__init__.py:260: DownloadWarning: Downloading: https://naciscdn.org/naturalearth/10m/physical/ne_10m_rivers_lake_centerlines.zip
  warnings.warn('Downloading: {}'.format(url), DownloadWarning)
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1010, in _send_output
    self.send(msg)
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 950, in send
    self.connect()
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1417, in connect
    super().connect()
  File "C:\ProgramData\Anaconda3\lib\http\client.py", line 921, in connect
    self.sock = self._create_connection(
  File "C:\ProgramData\Anaconda3\lib\socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\ProgramData\Anaconda3\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

这是代码:

import matplotlib.pyplot as plt
import datetime as dt
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.feature as cfeature
from metpy.plots import USCOUNTIES


ship_lon, ship_lat = -94.80234, 29.31221


ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-95.5, -94.1, 28.8, 29.8])
ax.add_feature(USCOUNTIES.with_scale('500k'),facecolor='none', edgecolor='gray',linewidth=0.5)

ax.add_feature(cfeature.NaturalEarthFeature('physical', 'land', '10m', edgecolor='black', facecolor='#d4d4d4'))
ax.add_feature(cfeature.NaturalEarthFeature('physical', 'ocean', '10m', facecolor='lightblue'))
ax.add_feature(cfeature.NaturalEarthFeature('physical', 'rivers_lake_centerlines', '10m', facecolor='lightblue'))

ax.set_title('Hunter-T Approximate Location at Time of Incident',loc='left',fontsize=10,fontweight='bold')
plt.scatter(ship_lon, ship_lat, marker='*', color='black',s=12, zorder=10)
plt.text(ship_lon, ship_lat+.03, 'Vessel Location', fontsize=5, fontweight='bold',horizontalalignment='center')

plt.savefig(fname='vessel_location.png',bbox_inches='tight', dpi=600)
plt.close()

如果我将河流线排除在外,这就是我的输出。带有船只位置的标记实际上是一条船只通道。我正试图让那片水域展示出来。我尝试搜索一个 shapefile,但我不确定哪个 shapefile 可能绘制​​该特征。或者有没有更好的方法来绘制该区域的高分辨率地图?

您可以尝试在浏览器的警告中打印 url,这将表明它在该位置根本不可用。就是当你把https改成http的时候。您可以尝试手动下载解压到cartopy.config['data_dir'].

所示位置

但最好只更新您的 cartopy 版本,因为它应该从 AWS 下载 Natural Earth 数据,例如来自:
https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_rivers_lake_centerlines.zip

当使用 cartopy 版本 0.19 时,它对我来说工作正常。然而,您可能想要将面色更改为“none”并且只为河流设置边缘颜色。因为它会以其他方式绘制这条线,就好像它是 polygon/patch.

ax.add_feature(
    cfeature.NaturalEarthFeature(
        'physical', 'rivers_lake_centerlines', '10m', linewidth=2, 
        edgecolor='lightblue', facecolor='none',
    ),
)

缩小一点以便更清楚地显示河流,对我来说它看起来像: