cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Contouf bug (shapely misreading interior polygons)

Open stephenworsley opened this issue 5 years ago • 1 comments

This bug is similar to the one described in #1326, except I believe it has a slightly different cause. Contourf will occasionally fill in too much of a layer, obscuring parts of the layers behind it. cotourf_bug

I believe this is due to the code used to determine which polygons to remove from a larger polygon. Specifically, the problem seems to be occurring at this line: https://github.com/SciTools/cartopy/blob/master/lib/cartopy/mpl/patch.py#L192

A polygon which ought to be recognised as a hole of the larger polygon is not being recognised as such. The polygons in question look like this problem_polys and appear to be, in some sense, pathological (the outer polygon is not valid according to the shapely method is_valid). These polygons seem to be generated by code in matplotlib, however, since matplotlib treats them differently, they don't appear to cause problems in matplotlib.

I tried removing the line in question and this seemed to solve the problem without causing any other errors in the plot. With that said, doing so may well cause problems wherever else path_to_geos is used. It may be worth considering if the paths passed into path_to_geos are sufficiently well structured, at least in the case of contourf, that this line is unnecessary: https://github.com/SciTools/cartopy/blob/master/lib/cartopy/mpl/patch.py#L192

stephenworsley avatar Jan 20 '20 15:01 stephenworsley

Hi @stephenworsley, do you still have the code to reproduce this one?

rcomer avatar Nov 02 '24 15:11 rcomer

Closing for lack of reproducing code.

rcomer avatar Jul 21 '25 13:07 rcomer