Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ class LambertConformal(Projection):
def __init__(self, central_longitude=-96.0, central_latitude=39.0,
false_easting=0.0, false_northing=0.0,
standard_parallels=(33, 45),
globe=None, cutoff=-30):
globe=None, cutoff=-30, longitude_extent=180):
"""
Parameters
----------
Expand All @@ -1770,6 +1770,10 @@ def __init__(self, central_longitude=-96.0, central_latitude=39.0,
The map extends to infinity opposite the central pole
so we must cut off the map drawing before then.
A value of 0 will draw half the globe. Defaults to -30.
longitude_extent: optional
Maximal longitude extent of the map.
Limits the axes boundary from central longitude minus and plus
the longitude extent.

"""
proj4_params = [('proj', 'lcc'),
Expand Down Expand Up @@ -1812,11 +1816,17 @@ def __init__(self, central_longitude=-96.0, central_latitude=39.0,
lats[0] = lats[-1] = plat
if plat == 90:
# Ensure clockwise
lons[1:-1] = np.linspace(central_longitude + 180 - 0.001,
central_longitude - 180 + 0.001, n)
lons[1:-1] = np.linspace(
central_longitude + longitude_extent - 0.001,
central_longitude - longitude_extent + 0.001,
n
)
else:
lons[1:-1] = np.linspace(central_longitude - 180 + 0.001,
central_longitude + 180 - 0.001, n)
lons[1:-1] = np.linspace(
central_longitude - longitude_extent + 0.001,
central_longitude + longitude_extent - 0.001,
n
)

points = self.transform_points(self.as_geodetic(), lons, lats)

Expand Down
18 changes: 18 additions & 0 deletions lib/cartopy/tests/crs/test_lambert_conformal.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ def test_single_npole(self):
decimal=0)


def test_longitude_extent():
"""Test that longitude_extent parameter controls map boundary extent."""
# Default behavior (180 degrees)
crs_default = ccrs.LambertConformal()

# Reduced extent (90 degrees)
crs_narrow = ccrs.LambertConformal(longitude_extent=90)

# The narrow projection should have smaller x_limits
default_x_range = crs_default.x_limits[1] - crs_default.x_limits[0]
narrow_x_range = crs_narrow.x_limits[1] - crs_narrow.x_limits[0]

# With longitude_extent=90 vs 180, the range should be noticeably smaller
assert narrow_x_range < default_x_range
# Verify it's meaningfully narrower (not just a rounding difference)
assert narrow_x_range < default_x_range * 0.9


class TestLambertZoneII:
def setup_class(self):
self.point_a = (1.4868268900254693, 48.13277955695077)
Expand Down
Loading