Projection on a perfect sphere

I’m trying to use geoviews to display astronomical data, where a distorted sphere doesn’t apply. I think I’ve figured out how create the right crs instances, and transform them using geopandas, but I can’t get them to work with geoviews: I get a long stack trace ending in:

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

Here is a stripped down example with dummy data:

import numpy as np
import pandas as pd
import geoviews
import geopandas
import shapely
import cartopy
from cartopy import crs
from numpy.random import default_rng

geoviews.extension("bokeh")

# Spherical globe, units of degrees
# I'm really interested in Celestial coordinates, so distortion and physical distances like meters do not apply
spherical_globe = crs.Globe(
    ellipse="sphere", semimajor_axis=180 / np.pi, semiminor_axis=180 / np.pi
)

# Set the CRS I will supply data in
data_crs = crs.PlateCarree(globe=spherical_globe)

# Set the CRS I want them displayed in
display_crs = crs.LambertAzimuthalEqualArea(
    central_latitude=90, central_longitude=0, globe=spherical_globe
)

# Make same random triangles
rng = default_rng()
n = 5
triangles = [
    shapely.geometry.Polygon([(rng.random() * 90, rng.random() * 90) for i in range(3)])
    for j in range(n)
]

geodf = geopandas.GeoDataFrame(
    {
        "a": rng.random(n),
        "geometry": geopandas.GeoSeries(triangles, crs=data_crs),
    },
    crs=data_crs,
)

geodf.to_crs(display_crs)
# Result runs without complaint, and gives plausible values.

chart = geoviews.Polygons(geodf).opts(projection=display_crs)
chart
# Fails with long stack trace ending in
#  ProjError: Error creating Transformer from CRS.: (Internal Proj Error: proj_create_operations: Source and target ellipsoid do not belong to the same celestial body)

Coming back to this a long time later, I realize that geoviews.Polygons doesn’t seem to pay attention to the crs in the geodf it is given. If I explicitly set the crs in the instantiation of Polygons:

chart = geoviews.Polygons(geodf, crs=data_crs).opts(projection=display_crs)

it works.

1 Like