Skip to content

Gridliner inline label projection hard-coded for WGS84 #1902

@Bob131

Description

@Bob131

Description

Calling cartopy.crs.Projection.gridlines() with a CRS using a non-WGS84 Globe and with x_inline=True raises an exception during drawing, apparently due to gridliner.py:800: when either axis is specified as inline, the transform used comes from a newly-instantiated PlateCarree projection with a default Globe (i.e., a WGS84 globe).

The raised exception message is ProjError: Error creating Transformer from CRS.: (Internal Proj Error: proj_create_operations: Source and target ellipsoid do not belong to the same celestial body).

Code to reproduce

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

globe = ccrs.Globe(semimajor_axis=1, semiminor_axis=1, ellipse=None)
projection = data_ccrs = ccrs.PlateCarree(globe=globe)

plt.figure()
ax = plt.subplot(111, projection=projection)
ax.set_global()
ax.gridlines(crs=data_ccrs, draw_labels=['x'], x_inline=True)
plt.show()

Traceback

Traceback (most recent call last):
  File "/usr/lib64/python3.10/site-packages/matplotlib/backends/backend_gtk3cairo.py", line 31, in on_draw_event
    self.figure.draw(self._renderer)
  File "/usr/lib64/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/usr/lib64/python3.10/site-packages/matplotlib/artist.py", line 49, in draw_wrapper
    return draw(artist, renderer)
  File "/usr/lib64/python3.10/site-packages/matplotlib/figure.py", line 2799, in draw
    mimage._draw_list_compositing_images(
  File "/usr/lib64/python3.10/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/lib64/python3.10/site-packages/matplotlib/artist.py", line 49, in draw_wrapper
    return draw(artist, renderer)
  File "/usr/lib64/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 543, in draw
    self._draw_preprocess(renderer)
  File "/usr/lib64/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 517, in _draw_preprocess
    gl._draw_gridliner(renderer=renderer)
  File "/usr/lib64/python3.10/site-packages/cartopy/mpl/gridliner.py", line 948, in _draw_gridliner
    this_path = update_artist(artist, renderer)
  File "/usr/lib64/python3.10/site-packages/cartopy/mpl/gridliner.py", line 775, in update_artist
    artist.update_bbox_position_size(renderer)
  File "/usr/lib64/python3.10/site-packages/matplotlib/text.py", line 506, in update_bbox_position_size
    posx, posy = self.get_transform().transform((posx, posy))
  File "/usr/lib64/python3.10/site-packages/matplotlib/transforms.py", line 1463, in transform
    res = self.transform_affine(self.transform_non_affine(values))
  File "/usr/lib64/python3.10/site-packages/matplotlib/transforms.py", line 2386, in transform_non_affine
    return self._a.transform_non_affine(points)
  File "/usr/lib64/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 134, in transform_non_affine
    return prj.transform_points(self.source_projection,
  File "/usr/lib64/python3.10/site-packages/cartopy/crs.py", line 401, in transform_points
    _safe_pj_transform(src_crs, self, x, y, z, trap=trap)
  File "/usr/lib64/python3.10/site-packages/cartopy/crs.py", line 43, in _safe_pj_transform
    transformer = Transformer.from_crs(src_crs, tgt_crs, always_xy=True)
  File "/usr/lib64/python3.10/site-packages/pyproj/transformer.py", line 534, in from_crs
    return Transformer(
  File "/usr/lib64/python3.10/site-packages/pyproj/transformer.py", line 310, in __init__
    self._local.transformer = transformer_maker()
  File "/usr/lib64/python3.10/site-packages/pyproj/transformer.py", line 97, in __call__
    return _Transformer.from_crs(
  File "pyproj/_transformer.pyx", line 643, in pyproj._transformer._Transformer.from_crs
pyproj.exceptions.ProjError: Error creating Transformer from CRS.: (Internal Proj Error: proj_create_operations: Source and target ellipsoid do not belong to the same celestial body)
Full environment definition

Operating system

Fedora 35

Cartopy version

v0.20.0, but appears to be an issue on master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions