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

fiona seems to be necessary when plotting coastlines #2355

Closed
WayneCrawford opened this issue Mar 18, 2024 · 2 comments
Closed

fiona seems to be necessary when plotting coastlines #2355

WayneCrawford opened this issue Mar 18, 2024 · 2 comments

Comments

@WayneCrawford
Copy link

Description

The cartopy installation documentation lists required and optional libraries. But when I install only the required libraries and run the "Features" Gallery example, I get a ShapefileException.

Installing the "optional" fiona library fixes the problem.

I think the problem should be resolved when using only the required libraries, or fiona should be added to the "required" list

Code to reproduce

import matplotlib.pyplot as plt

import cartopy.crs as ccrs
import cartopy.feature as cfeature


def main():
    fig = [plt.figure](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure)()
    ax = fig.add_subplot(1, 1, 1, projection=[ccrs.PlateCarree](https://scitools.org.uk/cartopy/docs/latest/reference/projections.html#cartopy.crs.PlateCarree)())
    ax.set_extent([-20, 60, -40, 45], crs=[ccrs.PlateCarree](https://scitools.org.uk/cartopy/docs/latest/reference/projections.html#cartopy.crs.PlateCarree)())

    ax.add_feature([cfeature.LAND](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature))
    ax.add_feature([cfeature.OCEAN](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature))
    ax.add_feature([cfeature.COASTLINE](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature))
    ax.add_feature([cfeature.BORDERS](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature), linestyle=':')
    ax.add_feature([cfeature.LAKES](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature), alpha=0.5)
    ax.add_feature([cfeature.RIVERS](https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.feature.NaturalEarthFeature.html#cartopy.feature.NaturalEarthFeature))

    [plt.show](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show)()


if __name__ == '__main__':
    main()

Traceback

Traceback (most recent call last):
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 1233, in _on_timer
    ret = func(*args, **kwargs)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/backends/backend_macosx.py", line 71, in callback_func
    callback()
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/backends/backend_macosx.py", line 94, in _draw_idle
    self.draw()
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/backends/backend_macosx.py", line 53, in draw
    super().draw()
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/figure.py", line 3154, in draw
    mimage._draw_list_compositing_images(
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 535, in draw
    return super().draw(renderer=renderer, **kwargs)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 3070, in draw
    mimage._draw_list_compositing_images(
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/mpl/feature_artist.py", line 152, in draw
    geoms = self._feature.intersecting_geometries(extent)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/feature/__init__.py", line 305, in intersecting_geometries
    return super().intersecting_geometries(extent)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/feature/__init__.py", line 108, in intersecting_geometries
    return (geom for geom in self.geometries() if
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/feature/__init__.py", line 290, in geometries
    geometries = tuple(shapereader.Reader(path).geometries())
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/cartopy/io/shapereader.py", line 136, in __init__
    self._reader = reader = shapefile.Reader(filename)
  File "/Users/crawford/opt/anaconda3/envs/seaplan/lib/python3.9/site-packages/shapefile.py", line 825, in __init__
    raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
shapefile.ShapefileException: Shapefile Reader requires a shapefile or file-like object.

Full environment definition

Operating system

macos 14.2.1

Cartopy version

0.22

conda list

# packages in environment at /Users/crawford/opt/anaconda3/envs/seaplan:
#
# Name                    Version                   Build  Channel
attrs                     20.3.0                   pypi_0    pypi
c-ares                    1.17.1               hc929b4f_0    conda-forge
ca-certificates           2020.12.5            h033912b_0    conda-forge
cartopy                   0.22.0                   pypi_0    pypi
certifi                   2020.12.5        py39h6e9494a_0    conda-forge
click                     8.1.7                    pypi_0    pypi
click-plugins             1.1.1                    pypi_0    pypi
cligj                     0.7.2                    pypi_0    pypi
contourpy                 1.2.0                    pypi_0    pypi
cycler                    0.10.0                     py_2    conda-forge
docutils                  0.20.1                   pypi_0    pypi
fonttools                 4.50.0                   pypi_0    pypi
freetype                  2.10.4               h3f75d11_0    conda-forge
geos                      3.8.1                h4a8c4bd_0    conda-forge
importlib-metadata        7.0.2                    pypi_0    pypi
importlib-resources       6.3.1                    pypi_0    pypi
jpeg                      9d                   hbcb3906_0    conda-forge
jsonref                   1.1.0                    pypi_0    pypi
jsonschema                3.2.0                    pypi_0    pypi
kiwisolver                1.3.1            py39heea7e63_0    conda-forge
krb5                      1.17.2               h60d9502_0    conda-forge
lcms2                     2.11                 h11f7e16_1    conda-forge
libblas                   3.9.0                3_openblas    conda-forge
libcblas                  3.9.0                3_openblas    conda-forge
libcurl                   7.71.1               h9bf37e3_8    conda-forge
libcxx                    11.0.0               h4c3b8ed_1    conda-forge
libedit                   3.1.20191231         h0678c8f_2    conda-forge
libev                     4.33                 haf1e3a3_1    conda-forge
libffi                    3.3                  h046ec9c_2    conda-forge
libgfortran               5.0.0               h7cc5361_13    conda-forge
libgfortran5              9.3.0               h7cc5361_13    conda-forge
liblapack                 3.9.0                3_openblas    conda-forge
libnghttp2                1.41.0               h7580e61_2    conda-forge
libopenblas               0.3.12          openmp_h54245bb_1    conda-forge
libpng                    1.6.37               h7cec526_2    conda-forge
libssh2                   1.9.0                h8a08a2b_5    conda-forge
libtiff                   4.1.0                hca7d577_6    conda-forge
libwebp-base              1.1.0                hbcb3906_3    conda-forge
llvm-openmp               11.0.0               h73239a0_1    conda-forge
lz4-c                     1.9.2                hb1e8313_3    conda-forge
matplotlib                3.8.3                    pypi_0    pypi
ncurses                   6.2                  h2e338ed_4    conda-forge
numpy                     1.26.4                   pypi_0    pypi
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openssl                   1.1.1i               h35c211d_0    conda-forge
packaging                 24.0                     pypi_0    pypi
pandas                    2.2.1                    pypi_0    pypi
pillow                    8.0.1            py39h38d7768_0    conda-forge
pip                       20.3.2             pyhd8ed1ab_0    conda-forge
proj                      7.1.1                h45baca5_3    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyproj                    3.6.1                    pypi_0    pypi
pyrsistent                0.17.3                   pypi_0    pypi
pyshp                     2.1.2              pyh9f0ad1d_0    conda-forge
python                    3.9.1           h1d169a7_1_cpython    conda-forge
python-dateutil           2.9.0.post0              pypi_0    pypi
python_abi                3.9                      1_cp39    conda-forge
pytz                      2020.4                   pypi_0    pypi
pyyaml                    5.3.1                    pypi_0    pypi
readline                  8.0                  h0678c8f_2    conda-forge
scipy                     1.12.0                   pypi_0    pypi
seaplan                   0.5.0                     dev_0    <develop>
setuptools                49.6.0           py39h2c36a5b_2    conda-forge
shapely                   1.7.1            py39h7edaf14_1    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
sqlite                    3.34.0               h17101e1_0    conda-forge
tk                        8.6.10               h0419947_1    conda-forge
tornado                   6.1              py39h5a22ff9_0    conda-forge
tzdata                    2024.1                   pypi_0    pypi
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
xarray                    2024.2.0                 pypi_0    pypi
xz                        5.2.5                haf1e3a3_1    conda-forge
zipp                      3.18.1                   pypi_0    pypi
zlib                      1.2.11            h7795811_1010    conda-forge
zstd                      1.4.5                h289c70a_2    conda-forge

pip list

Package             Version             Location
------------------- ------------------- -----------------------------------------
attrs               20.3.0
Cartopy             0.22.0
certifi             2020.12.5
click               8.1.7
click-plugins       1.1.1
cligj               0.7.2
contourpy           1.2.0
cycler              0.10.0
docutils            0.20.1
fonttools           4.50.0
importlib-metadata  7.0.2
importlib-resources 6.3.1
jsonref             1.1.0
jsonschema          3.2.0
kiwisolver          1.3.1
matplotlib          3.8.3
numpy               1.26.4
obsinfo             0.110.18
olefile             0.46
packaging           24.0
pandas              2.2.1
Pillow              8.0.1
pip                 20.3.2
pyparsing           2.4.7
pyproj              3.6.1
pyrsistent          0.17.3
pyshp               2.1.2
python-dateutil     2.9.0.post0
pytz                2020.4
PyYAML              5.3.1
scipy               1.12.0
seaplan             0.5.0               /Users/crawford/_Work/Programming/seaplan
setuptools          49.6.0.post20201009
Shapely             1.7.1
six                 1.15.0
tornado             6.1
tzdata              2024.1
wheel               0.36.2
xarray              2024.2.0
zipp                3.18.1
@rcomer
Copy link
Member

rcomer commented Mar 18, 2024

Hi @WayneCrawford, I think you are seeing this error because you are have an older version of pyshp. Could you upgrade that to v2.3 and try again? I think fiona gets used in place of pyshp if installed, but should not be necessary.

Note we have increased the minimum required pyshp for the next release (which should be fairly soon) #2290.

@WayneCrawford
Copy link
Author

Yep, that works!

Regards,
Wayne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants