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

Shapefile gives warning with GSHHS feature #1659

Closed
MHBalsmeier opened this issue Sep 16, 2020 · 4 comments
Closed

Shapefile gives warning with GSHHS feature #1659

MHBalsmeier opened this issue Sep 16, 2020 · 4 comments
Milestone

Comments

@MHBalsmeier
Copy link
Contributor

MHBalsmeier commented Sep 16, 2020

Hi,
shapefile gives me a warning when I save a figure which has GSHHS features in it. Thought I'd ask it here:

MWE:

import matplotlib.pyplot as plt;
import cartopy.crs as ccrs;
import cartopy;
fig = plt.figure();
proj = ccrs.Mercator(central_longitude = 0);
ax = plt.axes(projection = proj);
ax.add_feature(cartopy.feature.GSHHSFeature(levels = (1, 2), linewidth = 2.0));
print("before");
fig.savefig("test.png");
print("after");

output:

before

/home/max/.local/lib/python3.8/site-packages/shapefile.py:385: UserWarning: Shapefile shape has invalid polygon: no exterior rings found (must have clockwise orientation); interpreting holes as exteriors.
  warnings.warn('Shapefile shape has invalid polygon: no exterior rings found (must have clockwise orientation); interpreting holes as exteriors.')

after

What is the cause of this and how can it be resolved?

OS: Ubuntu 20.04
Cartopy: 0.18.0
pyshp: 2.1.2

Thanks in advance.

@dopplershift
Copy link
Contributor

Since the warning is coming from /home/max/.local/lib/python3.8/site-packages/shapefile.py:385, I think this is an issue between the GSHHS data and pyshp. It may be worth asking on the pyshp issue tracker. Having said that, it looks like we are currently using an old copy of the GSHHS data (2.2.0 while 2.3.7 is the latest), so it's possible using a newer copy of the data would fix it--which is covered in #1353. Closing since the only thing CartoPy could do is update, and that's already covered in another issue.

@MHBalsmeier
Copy link
Contributor Author

thanks, updating the coastline data solved it

@karimbahgat
Copy link
Contributor

karimbahgat commented Aug 31, 2021

The warnings are just a notification caused when trying to produce the GeoJSON representation of two weird slivers in the GSHHS_c_L1.shp shapefile (downloaded from the most recent cartopy GitHub repo), at shapefile index 95 and 471. They are both single-part polygons but have the ring orientation of an interior hole (i.e. holes without an exterior polygon). PyShp assumes they were meant to be exterior polygons and includes them in the GeoJSON, notifying the user. The cartopy visualizations should be the same as before. A quick fix to supress the warnings for cartopy users would be to remove shapes 95 and 471 from cartopy's version of GSHHS_c_L1.shp.

I just made some commits that improved the somewhat cryptic warning messages, reports which shapes were affected, and allows disabling the warning messages. Should be available in the next version.

@MHBalsmeier
Copy link
Contributor Author

Thanks, I updated the GSHHS version that cartopy uses, since then the warnings do no longer occur.

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

4 participants