Skip to content

Conversation

@leonard-seydoux
Copy link

@leonard-seydoux leonard-seydoux commented Nov 5, 2025

Rationale

This PR adds a longitude_extent parameter to the LambertConformal projection to allow control over the map's longitudinal coverage.

Previously, the longitudinal extent was hardcoded at 180° on each side of the central meridian, which meant the projection always covered a full hemisphere. While set_extent() can be used to crop the view, it doesn't change the underlying projection boundary, often resulting in suboptimal axis limits for regional maps.

With this parameter, users can create more appropriate projection boundaries for regional applications where a full hemisphere coverage is unnecessary.

This is an updated version of #1665, rebased on the current main branch.

Implications

  • Adds a new optional keyword argument longitude_extent (default: 180) to LambertConformal.__init__
  • Backward compatible: default behavior remains unchanged
  • The projection boundary is now computed using longitude_extent instead of the hardcoded 180° value
  • Users can create more focused regional projections without distorted axis boundaries

Checklist

  • ✅ New feature: Added longitude_extent parameter with default value of 180 to maintain backward compatibility
  • ✅ Test suite: Added test_longitude_extent() in lib/cartopy/tests/crs/test_lambert_conformal.py to verify the parameter controls boundary extent
  • ✅ Documentation: Updated docstring to document the new parameter
  • ✅ All existing LambertConformal tests pass (13/13)
  • ✅ CLA: Previously signed

Example use

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

fig = plt.figure(figsize=(14, 6))

# Example 1: Default extent (180 degrees on each side)
ax1 = fig.add_subplot(
    1,
    2,
    1,
    projection=ccrs.LambertConformal(
        central_longitude=-100, central_latitude=35, cutoff=0.0
    ),
)
ax1.add_feature(cfeature.LAND, facecolor="lightgray")
ax1.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)
ax1.set_title("Default longitude extent", fontsize=12)

# Example 2: Reduced extent (90 degrees on each side)
ax2 = fig.add_subplot(
    1,
    2,
    2,
    projection=ccrs.LambertConformal(
        central_longitude=-100,
        central_latitude=45,
        longitude_extent=80,
        cutoff=0.0,
    ),
)
ax2.add_feature(cfeature.LAND, facecolor="lightgray")
ax2.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)
ax2.set_title("Reduced longitude extent (90°)", fontsize=12)

plt.tight_layout()
plt.show()
lambert_conformal_extent

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2025

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

2 participants