Skip to content

Commit b1719cb

Browse files
committed
Address review: test preserve on global templates, exact merc latitude (#3549)
1 parent 174b134 commit b1719cb

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

xrspatial/_template_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
lonlat=(-180.0, -85.0, 180.0, 85.0), area_epsg=8857,
5454
shape_epsg=3395),
5555
# Global Web Mercator (EPSG:3857). Native bounds are the canonical square
56-
# extent +/-20037508 m, which is +/-180 lon and +/-85.051129 lat (the
56+
# extent +/-20037508 m, which is +/-180 lon and +/-85.0511287798 lat (the
5757
# latitude where the Mercator y matches the x half-extent). lonlat stops at
58-
# +/-85.051129 because Mercator y diverges to infinity at the poles.
58+
# that latitude because Mercator y diverges to infinity at the poles.
5959
'web_mercator': dict(
6060
bounds=(-20037508, -20037508, 20037508, 20037508), crs=3857,
6161
default_resolution=50000, label='World (Web Mercator)',
62-
lonlat=(-180.0, -85.051129, 180.0, 85.051129),
62+
lonlat=(-180.0, -85.0511287798, 180.0, 85.0511287798),
6363
area_epsg=8857, shape_epsg=3395),
6464
# Global equal-area grid (EPSG:8857, Equal Earth). Native bounds are the
6565
# +/-90 world projected into Equal Earth.

xrspatial/tests/test_templates.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ def test_cf_grid_mapping_preserve_path():
578578
assert "Conus Albers" in agg.attrs["crs_wkt"]
579579

580580

581+
@pytest.mark.parametrize("name", ["web_mercator", "equal_earth"])
582+
def test_global_preserve_picks_world_projection(name):
583+
# the global templates carry the same area/shape EPSG hints as 'world', so
584+
# preserve='shape' lands on World Mercator (EPSG:3395) instead of a stray
585+
# UTM zone for the (0, 0) centroid, and preserve='area' lands on Equal Earth
586+
agg_shape = from_template(name, preserve="shape")
587+
assert agg_shape.attrs["crs"] == 3395
588+
assert _proj(3395) == "merc"
589+
assert from_template(name, preserve="area").attrs["crs"] == 8857
590+
591+
581592
def test_grid_mapping_omitted_for_equal_earth():
582593
# Equal Earth (the preserve='area' fallback for the world bbox) has no
583594
# CF grid mapping, so grid_mapping_name is left off and crs_wkt stands

0 commit comments

Comments
 (0)