cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Introduce `path_to_shapely` and `shapely_to_path`

Open rcomer opened this issue 1 year ago • 3 comments

Rationale

Closes #2447. Introduce shapely_to_path which maps a single Shapely geometry or collection to a single Matplotlib path, and path_to_shapely, which does the opposite. To take full advantage of this in our transforms code, also modify project_geometry so that it returns a GeometryCollection from either a GeometryCollection or a LinearRing. Previously GeometryCollection was not supported and LinearRing was mapped to a tuple.

Note the first commit just duplicates the existing path_to_geos and geos_to_path and all the material changes are in the second commit. I rearranged the logic in path_to_shapely because it seemed simpler to separate the geometry types into different lists up front.

I also went ahead and started a whatsnew for the next release. I think that was suggested a couple of releases ago and it does seem simpler to me to add the entries as we go.

Implications

The new behaviour of project_geometry from a LinearRing could be a breaking change but, since the docstring of project_geometry states that it returns a Shapely geometry, I claim this one as a bug fix.

rcomer avatar Oct 15 '24 16:10 rcomer

I also tested this with my user code that generates many contour plots. I got identical results with my branch and with main.

rcomer avatar Oct 15 '24 16:10 rcomer

Broke the minimum versions tests 😢

rcomer avatar Oct 15 '24 16:10 rcomer

Most of the tests were fixed by bumping minimum Shapely to v2.0. I think that’s reasonable to do since v2 will be 2 years old in December. However, I think the remaining test failure might need a workaround for lack of https://github.com/matplotlib/matplotlib/pull/25252. It’s too soon to drop support for MPL 3.7.

rcomer avatar Oct 15 '24 18:10 rcomer