From 80fcffdce7c71c5550b75ddacde12ed23acd57dc Mon Sep 17 00:00:00 2001 From: Vanhci Date: Fri, 22 May 2026 10:06:52 +0800 Subject: [PATCH] Fix issue #2277: apply same EPSG-range fix to test fixture The _geotags.py writer was fixed in PR #2280 to use pyproj (or a vetted fallback allowlist) instead of the broken EPSG range heuristic (4000-4999) when deciding whether to write GeographicTypeGeoKey vs ProjectedCSTypeGeoKey. The same broken heuristic was present in make_minimal_tiff() in the test conftest, which corrupts test GeoTIFFs with projected CRS codes that fall in the 4000-4999 window (e.g. 4087, 4088, 4499). This commit mirrors the fix from _geotags.py into the test fixture: - Adds the same _KNOWN_GEOGRAPHIC_EPSG_FALLBACK frozenset - Adds _is_geographic() helper that uses pyproj when available, falls back to the allowlist - Replaces the check in make_minimal_tiff() with _is_geographic(epsg) --- xrspatial/geotiff/tests/conftest.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/xrspatial/geotiff/tests/conftest.py b/xrspatial/geotiff/tests/conftest.py index 86cf2a267..bb2c69b36 100644 --- a/xrspatial/geotiff/tests/conftest.py +++ b/xrspatial/geotiff/tests/conftest.py @@ -10,6 +10,32 @@ import numpy as np import pytest +#: Vetted allowlist of EPSG codes known to be geographic (for test fixtures). +#: Mirrors the fallback set in _geotags.py. Kept intentionally small. +_KNOWN_GEOGRAPHIC_EPSG_FALLBACK = frozenset({ + 4326, # WGS 84 + 4269, # NAD83 + 4267, # NAD27 + 4258, # ETRS89 + 4283, # GDA94 + 4322, # WGS 72 + 4230, # ED50 + 4019, # Unknown datum based on GRS 1980 ellipsoid + 4047, # Unspecified datum based on GRS 1980 Authalic Sphere +}) + + +def _is_geographic(epsg: int) -> bool: + """Return True if the EPSG code refers to a geographic CRS. + + Uses pyproj when available; falls back to the vetted allowlist. + """ + try: + from pyproj import CRS + return CRS.from_epsg(epsg).is_geographic + except Exception: + return epsg in _KNOWN_GEOGRAPHIC_EPSG_FALLBACK + def gpu_available() -> bool: """True iff cupy imports AND a CUDA device is actually usable. @@ -223,7 +249,7 @@ def add_doubles(tag, vals): add_doubles(33922, [0.0, 0.0, 0.0, ox, oy, 0.0]) # ModelTiepoint if epsg is not None: - if epsg == 4326 or (4000 <= epsg < 5000): + if _is_geographic(epsg): model_type, key_id = 2, 2048 else: model_type, key_id = 1, 3072