Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When attempting to use Cartopy to plot rivers, I'm getting a URL error. I'm not even sure the rivers feature will plot what I want...I'm attempting to get the Galveston Ship Channel to show on my map.

Here's the error I get:

C:ProgramDataAnaconda3libsite-packagescartopyio\__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:ProgramDataAnaconda3liburllib
equest.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:ProgramDataAnaconda3libhttpclient.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:ProgramDataAnaconda3libhttpclient.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:ProgramDataAnaconda3libhttpclient.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:ProgramDataAnaconda3libhttpclient.py", line 1010, in _send_output
    self.send(msg)
  File "C:ProgramDataAnaconda3libhttpclient.py", line 950, in send
    self.connect()
  File "C:ProgramDataAnaconda3libhttpclient.py", line 1417, in connect
    super().connect()
  File "C:ProgramDataAnaconda3libhttpclient.py", line 921, in connect
    self.sock = self._create_connection(
  File "C:ProgramDataAnaconda3libsocket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:ProgramDataAnaconda3libsocket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

And here's the code:

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()

If I leave the rivers line out, this is my output. The marker with the vessel location is actually a ship channel. I'm trying to get that body of water to display. I tried searching for a shapefile, but I'm unsure of what shapefile might plot that feature. Or is there a better way to go about plotting a high-res map of this area?

Output Image

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
122 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try the url it prints in the warning in a browser, and that'll show that it's simply not available at that location. It is when you change https to http. You could try to download and extract it manually to the location as shown in cartopy.config['data_dir'].

But it's probably best to simply update your cartopy version, since it should be downloading the Natural Earth data from AWS, for example from:
https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_rivers_lake_centerlines.zip

When using cartopy version 0.19 it works fine for me. You do however probably want to change the facecolor to be "none" and only set the edgecolor for the rivers. Since it will otherwise plot the line as if it's a polygon/patch.

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

Zooming out a little to show the rivers more clearly, for me it looks like:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...