Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coastlines update #1823

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cartopy/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class GSHHSFeature(Feature):
The dataset scale. One of 'auto', 'coarse', 'low', 'intermediate',
'high, or 'full' (default is 'auto').
levels
A list of integers 1-4 corresponding to the desired GSHHS feature
A list of integers 1-6 corresponding to the desired GSHHS feature
levels to draw (default is [1] which corresponds to coastlines).

Other Parameters
Expand Down
42 changes: 37 additions & 5 deletions lib/cartopy/io/shapereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io
import itertools
import os
from urllib.error import HTTPError

import shapely.geometry as sgeom
import shapefile
Expand Down Expand Up @@ -408,9 +409,12 @@ class GSHHSShpDownloader(Downloader):
"""
FORMAT_KEYS = ('config', 'scale', 'level')

_GSHHS_URL_TEMPLATE = ('https://www.ngdc.noaa.gov/mgg/shorelines/data/'
'gshhs/oldversions/version2.2.0/'
'GSHHS_shp_2.2.0.zip')
gshhs_version = '2.3.7'

_GSHHS_URL_TEMPLATE = (
'https://www.ngdc.noaa.gov/mgg/shorelines/data/'
'gshhs/latest/gshhg-shp-' + gshhs_version + '.zip'
)

def __init__(self,
url_template=_GSHHS_URL_TEMPLATE,
Expand All @@ -435,15 +439,43 @@ def acquire_all_resources(self, format_dict):

# Download archive.
url = self.url(format_dict)
shapefile_online = self._urlopen(url)
try:
shapefile_online = self._urlopen(url)
# error handling:
except HTTPError:
try:
"""
case if GSHHS has had an update
without changing the naming convention
"""
url = (
'https://www.ngdc.noaa.gov/mgg/shorelines/data/'
'gshhs/oldversions/version' + self.gshhs_version + '/'
'gshhg-shp-' + self.gshhs_version + '.zip'
)
shapefile_online = self._urlopen(url)
except HTTPError:
"""
case if GSHHS has had an update
with changing the naming convention
"""
url = (
'https://www.ngdc.noaa.gov/mgg/shorelines/data/'
'gshhs/oldversions/version2.3.6/'
'gshhg-shp-2.3.6.zip'
)
shapefile_online = self._urlopen(url)
zfh = ZipFile(io.BytesIO(shapefile_online.read()), 'r')
shapefile_online.close()

# Iterate through all scales and levels and extract relevant files.
modified_format_dict = dict(format_dict)
scales = ('c', 'l', 'i', 'h', 'f')
levels = (1, 2, 3, 4)
levels = (1, 2, 3, 4, 5, 6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the documentation to indicate it goes up to 6 now?

A list of integers 1-4 corresponding to the desired GSHHS feature
levels to draw (default is [1] which corresponds to coastlines).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did that, will squash once more

for scale, level in itertools.product(scales, levels):
# the combination c4 does not occur for some reason
if scale == "c" and level == 4:
continue
modified_format_dict.update({'scale': scale, 'level': level})
target_path = self.target_path(modified_format_dict)
target_dir = os.path.dirname(target_path)
Expand Down